From b6ca2fe5b48d4e1cbf494650731dafe236acc646 Mon Sep 17 00:00:00 2001 From: Hailey Date: Thu, 1 May 2025 18:54:34 -0700 Subject: [PATCH] fix bottom sheet --- modules/bottom-sheet/ios/SheetView.swift | 37 ++++++++++--------- .../bottom-sheet/ios/SurfaceTouchHandler.h | 3 ++ 2 files changed, 22 insertions(+), 18 deletions(-) create mode 100644 modules/bottom-sheet/ios/SurfaceTouchHandler.h diff --git a/modules/bottom-sheet/ios/SheetView.swift b/modules/bottom-sheet/ios/SheetView.swift index 346fe3f413..48b9a48730 100644 --- a/modules/bottom-sheet/ios/SheetView.swift +++ b/modules/bottom-sheet/ios/SheetView.swift @@ -6,7 +6,7 @@ class SheetView: ExpoView, UISheetPresentationControllerDelegate { // Views private var sheetVc: SheetViewController? private var innerView: UIView? - private var touchHandler: RCTTouchHandler? + private var touchHandler: RCTSurfaceTouchHandler? // Native content height observation (eliminates JS bridge round-trip) private var contentHeightObservation: NSKeyValueObservation? @@ -78,33 +78,35 @@ class SheetView: ExpoView, UISheetPresentationControllerDelegate { required init (appContext: AppContext? = nil) { super.init(appContext: appContext) self.maxHeight = Util.getScreenHeight() - self.touchHandler = RCTTouchHandler(bridge: appContext?.reactBridge) + self.touchHandler = RCTSurfaceTouchHandler() SheetManager.shared.add(self) } deinit { self.destroy() } - - // We don't want this view to actually get added to the tree, so we'll simply store it for adding - // to the SheetViewController - override func insertReactSubview(_ subview: UIView!, at atIndex: Int) { - self.touchHandler?.attach(to: subview) - self.innerView = subview + + override func mountChildComponentView( + _ childComponentView: UIView, + index: Int + ) { + self.innerView = childComponentView + touchHandler?.attach(to: childComponentView) + } + + override func unmountChildComponentView( + _ childComponentView: UIView, + index: Int + ) { + touchHandler?.detach(from: childComponentView) + if self.innerView === childComponentView { + self.innerView = nil + } } // We'll grab the content height from here so we know the initial detent to set override func layoutSubviews() { super.layoutSubviews() - - guard let innerView = self.innerView else { - return - } - - if innerView.subviews.count != 1 { - return - } - self.present() } @@ -114,7 +116,6 @@ class SheetView: ExpoView, UISheetPresentationControllerDelegate { self.isClosing = false self.isOpen = false self.sheetVc = nil - self.touchHandler?.detach(from: self.innerView) self.touchHandler = nil self.innerView = nil SheetManager.shared.remove(self) diff --git a/modules/bottom-sheet/ios/SurfaceTouchHandler.h b/modules/bottom-sheet/ios/SurfaceTouchHandler.h new file mode 100644 index 0000000000..784a5cbfba --- /dev/null +++ b/modules/bottom-sheet/ios/SurfaceTouchHandler.h @@ -0,0 +1,3 @@ +#if __has_include() +#import +#endif