Post

Replies

Boosts

Views

Activity

Reply to Button Touch Not Canceled in ScrollView on Modal in SwiftUI for iOS 18
Good day everyone! On Xcode 26 apple make worse Gesture's now! So now my hack doesn't work. But, for iOS 26 I found a new hack, so I updated my prevous solution: public extension View { func resetTappedButtonWhenScrolled() -> some View { modifier(ResetTappedButtonWhenScrolled()) } } private struct ResetTappedButtonWhenScrolled: ViewModifier { @State private var isScrolling = false @ViewBuilder func body(content: Content) -> some View { if #available(iOS 18, *) { content .disabled(isScrolling) .background(ScrollGestureObserver(isScrolling: $isScrolling)) } else { content } } } private struct ScrollGestureObserver: UIViewRepresentable { @Binding var isScrolling: Bool func makeCoordinator() -> Coordinator { Coordinator(isScrolling: $isScrolling) } func makeUIView(context: Context) -> UIView { let view = UIView() DispatchQueue.main.async { if let scrollView = view.enclosingScrollView() { scrollView.panGestureRecognizer.addTarget( context.coordinator, action: #selector(Coordinator.handlePan(_:)), ) } } return view } func updateUIView(_ uiView: UIView, context: Context) {} } private extension ScrollGestureObserver { final class Coordinator: NSObject { @Binding var isScrolling: Bool init(isScrolling: Binding<Bool>) { _isScrolling = isScrolling } @objc func handlePan(_ gesture: UIPanGestureRecognizer) { switch gesture.state { case .began, .changed: if !isScrolling { isScrolling = true } case .ended, .cancelled, .failed: if isScrolling { isScrolling = false } default: break } } } } private extension UIView { func enclosingScrollView() -> UIScrollView? { sequence(first: superview, next: { $0?.superview }) .compactMap { $0 as? UIScrollView } .first } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’25
Reply to Button Touch Not Canceled in ScrollView on Modal in SwiftUI for iOS 18
The same bug on iOS 18.3 and Xcode 16.2. I made "hack" for ScrollView to solve that problem. But it can conflict with your views if you used @Environment(\.isEnabled) var isEnabled public struct FixScrollViewWithTappedButton: ViewModifier { @State private var isScrolling = false @ViewBuilder public func body(content: Content) -> some View { if #available(iOS 18, *) { content .disabled(isScrolling) .simultaneousGesture( DragGesture() .onChanged { _ in isScrolling = true } .onEnded { _ in isScrolling = false } ) } } } But my solution will reset your tap on button and you don't need to patch every button in your application. Example: .sheet(isPresented: $isPresented) { ScrollView(showsIndicators: false) { VStack(alignment: .leading, spacing: 0) { ForEach((0...31).map(String.init), id: \.self) { text in Button(action: { print("Tapped \(text)") }) { Text(text) .padding() .foregroundColor(.white) .background(Color.blue) .cornerRadius(8) } } } .modifier(FixScrollViewWithTappedButton()) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’25
Reply to iOS 16 Crash that happens when changing navigation state
same issue on ios 16.1, app builded on xcode 13.3.1 Crashed: com.apple.main-thread 0 SwiftUI 0x895d90 OUTLINED_FUNCTION_2 + 836 1 SwiftUI 0x895da8 OUTLINED_FUNCTION_2 + 860 2 SwiftUI 0x1329880 OUTLINED_FUNCTION_2 + 424 3 SwiftUI 0x6806c OUTLINED_FUNCTION_441 + 584 4 SwiftUI 0x481b0 OUTLINED_FUNCTION_194 + 544 5 UIKitCore 0x1b7194 -[UIViewController removeChildViewController:notifyDidMove:] + 128 6 UIKitCore 0x77d6e8 -[UINavigationController removeChildViewController:notifyDidMove:] + 80 7 UIKitCore 0x205224 -[UIViewController dealloc] + 768 8 UIKitCore 0x1036c -[UINavigationController viewDidDisappear:] + 372 9 UIKitCore 0xd9c4 -[UIViewController _setViewAppearState:isAnimating:] + 1012 10 UIKitCore 0x46e61c -[UIViewController __viewDidDisappear:] + 136 11 UIKitCore 0x10e08 -[UITabBarController viewDidDisappear:] + 84 12 UIKitCore 0xd9c4 -[UIViewController _setViewAppearState:isAnimating:] + 1012 13 UIKitCore 0x46e61c -[UIViewController __viewDidDisappear:] + 136 14 UIKitCore 0x7ec024 __64-[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:]_block_invoke_3 + 44 15 UIKitCore 0x1a3f24 -[UIViewController _executeAfterAppearanceBlock] + 84 16 UIKitCore 0x1a3e68 -[_UIAfterCACommitBlock run] + 72 17 UIKitCore 0x1a3d9c -[_UIAfterCACommitQueue flush] + 176 18 UIKitCore 0x1a3ca8 _runAfterCACommitDeferredBlocks + 496 19 UIKitCore 0x3f530 _cleanUpAfterCAFlushAndRunDeferredBlocks + 108 20 UIKitCore 0x504b58 _UIApplicationFlushCATransaction + 72 21 UIKitCore 0x652740 _UIUpdateSequenceRun + 84 22 UIKitCore 0xc99fd0 schedulerStepScheduledMainSection + 172 23 UIKitCore 0xc9919c runloopSourceCallback + 92 24 CoreFoundation 0xd5f54 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28 25 CoreFoundation 0xe232c __CFRunLoopDoSource0 + 176 26 CoreFoundation 0x66210 __CFRunLoopDoSources0 + 244 27 CoreFoundation 0x7bba8 __CFRunLoopRun + 836 28 CoreFoundation 0x80ed4 CFRunLoopRunSpecific + 612 29 GraphicsServices 0x1368 GSEventRunModal + 164 30 UIKitCore 0x3a23d0 -[UIApplication _run] + 888 31 UIKitCore 0x3a2034 UIApplicationMain + 340 32 libswiftUIKit.dylib 0x35308 UIApplicationMain(_:_:_:_:) + 104 33 WLApplication 0x49d4 main + 104 (AppDelegate.swift:104) 34 ??? 0x1a84a8960 (Missing)
Topic: App & System Services SubTopic: Core OS Tags:
Nov ’22