[ADD] News, Browse and Settings views ported to SwiftUI

This commit contains WIP SwiftUI versions of most of the views in SideStore.
This commit is contained in:
Fabian Thies
2022-11-23 22:34:02 +01:00
parent ed2270ff46
commit 16a8bce102
30 changed files with 2047 additions and 2 deletions

View File

@@ -0,0 +1,47 @@
//
// ObservableScrollView.swift
// SideStore
//
// Created by Fabian Thies on 20.11.22.
// Copyright © 2022 Fabian Thies. All rights reserved.
//
import SwiftUI
struct ObservableScrollView<Content: View>: View {
@Namespace var scrollViewNamespace
@Binding var scrollOffset: CGFloat
let content: (ScrollViewProxy) -> Content
init(scrollOffset: Binding<CGFloat>, @ViewBuilder content: @escaping (ScrollViewProxy) -> Content) {
self._scrollOffset = scrollOffset
self.content = content
}
var body: some View {
ScrollView {
ScrollViewReader { proxy in
content(proxy)
.background(GeometryReader { geoReader in
let offset = -geoReader.frame(in: .named(scrollViewNamespace)).minY
Color.clear
.preference(key: ScrollViewOffsetPreferenceKey.self, value: offset)
})
}
}
.coordinateSpace(name: scrollViewNamespace)
.onPreferenceChange(ScrollViewOffsetPreferenceKey.self) { value in
scrollOffset = value
}
}
}
struct ScrollViewOffsetPreferenceKey: PreferenceKey {
static var defaultValue = CGFloat.zero
static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
value += nextValue()
}
}