Files
simplex-chat/apps/ios/Shared/Views/Helpers/StickyScrollView.swift
Arturs Krumins bdb6bd6e20 ios: hide user picker sheet instantly, when opening another sheet (#4927)
* ios: hide user picker sheet instantly, when opening another sheet

* tweak appearance

* distance based animation duration

* cleanup; dismiss

* implement UIViewPropertyAnimator

* resolve warning

* user picker bottom padding

* reset user scroll position on dismiss; cleanup

* reduce dif

* delay user picker closing

* touchable list row; prevent tap gesture passtrough

* fix dark mode tap target; retain highlight; highlight in user scroller

* fix layout loop; add upper animation speed constraint

* refactor separators

* instantanious longPress; tweak animations

* cubic animation curve; dynamic backdrop opacity

* remove touchdown animation

* ios: user picker sheet concurent animation (#4955)

* ios: user picker sheet concurent animation

* bind showSettings; cleanup

* async qr code generation

* fix iOS15 sheet animation when presenting sheet multiple times

* async camera authorization in 'Use from desktop' sheet

* load sheet navigation titles before presenting (#4963)

* load sheet navigation titles before presenting

* list background during loading

* improve handling of repeated sheet presentation state changes

* fix keyboard related glitches

* ios: remove `showSettings` and `withNavigation` (#4980)

* remove showSettings

* pass dismiss action trough navigation links

* move auth to all sheets

---------

Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com>
2024-10-07 18:30:17 +01:00

62 lines
1.8 KiB
Swift

//
// StickyScrollView.swift
// SimpleX (iOS)
//
// Created by user on 20/09/2024.
// Copyright © 2024 SimpleX Chat. All rights reserved.
//
import SwiftUI
struct StickyScrollView<Content: View>: UIViewRepresentable {
@Binding var resetScroll: ResetScrollAction
@ViewBuilder let content: () -> Content
func makeUIView(context: Context) -> UIScrollView {
let hc = context.coordinator.hostingController
hc.view.backgroundColor = .clear
let sv = UIScrollView()
sv.showsHorizontalScrollIndicator = false
sv.addSubview(hc.view)
sv.delegate = context.coordinator
DispatchQueue.main.async {
resetScroll = ResetScrollAction { sv.setContentOffset(.zero, animated: false) }
}
return sv
}
func updateUIView(_ scrollView: UIScrollView, context: Context) {
let hc = context.coordinator.hostingController
hc.rootView = content()
hc.view.frame.size = hc.view.intrinsicContentSize
scrollView.contentSize = hc.view.intrinsicContentSize
}
func makeCoordinator() -> Coordinator {
Coordinator(content: content())
}
class Coordinator: NSObject, UIScrollViewDelegate {
let hostingController: UIHostingController<Content>
init(content: Content) {
self.hostingController = UIHostingController(rootView: content)
}
func scrollViewWillEndDragging(
_ scrollView: UIScrollView,
withVelocity velocity: CGPoint,
targetContentOffset: UnsafeMutablePointer<CGPoint>
) {
if targetContentOffset.pointee.x < 32 {
targetContentOffset.pointee.x = 0
}
}
}
}
struct ResetScrollAction {
var action = { }
func callAsFunction() { action() }
}