Skip to content

Commit cf5dc04

Browse files
committed
fix(ios): events in new arch
1 parent c4a6e37 commit cf5dc04

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

example/ios/Podfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ENV['RCT_NEW_ARCH_ENABLED'] = '0'
1+
ENV['RCT_NEW_ARCH_ENABLED'] = '1'
22

33
# Resolve react_native_pods.rb with node to allow for hoisting
44
require Pod::Executable.execute_command('node', ['-p',

example/src/App.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const App = () => {
1111
<NavigationContainer>
1212
<Stack.Navigator
1313
screenOptions={{ headerTransparent: true, headerTintColor: 'white' }}
14-
initialRouteName="Navigation"
14+
initialRouteName="Map"
1515
>
1616
<Stack.Screen options={{ headerShown: false }} name="Map" component={MapScreen} />
1717
<Stack.Screen

ios/TrueSheetView.swift

+20-11
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,14 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
9797

9898
super.removeReactSubview(subview)
9999

100+
// Touch handler for Old Arch
100101
touchHandler.detach(from: subview)
102+
103+
// Touch handler that works in New Arch
101104
surfaceTouchHandler.detach(from: subview)
102105

103106
// Remove all constraints
104-
// Fixes New Arch weird layout degration
107+
// Fixes New Arch weird layout issue :/
105108
containerView?.unpin()
106109
footerView?.unpin()
107110
contentView?.unpin()
@@ -149,7 +152,7 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
149152
present(at: initialIndex, promise: nil, animated: initialIndexAnimated)
150153
}
151154

152-
dispatchEvent(name: "onMount", data: nil)
155+
dispatchEvent(name: "onMount", block: onMount, data: nil)
153156
}
154157
}
155158

@@ -173,19 +176,19 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
173176

174177
func viewControllerDidChangeWidth(_ width: CGFloat) {
175178
// We only pass width to JS since height is handled by the constraints
176-
dispatchEvent(name: "onContainerSizeChange", data: ["width": width])
179+
dispatchEvent(name: "onContainerSizeChange", block: onContainerSizeChange, data: ["width": width])
177180
}
178181

179182
func viewControllerDidDrag(_ state: UIGestureRecognizer.State, _ height: CGFloat) {
180183
let sizeInfo = SizeInfo(index: activeIndex ?? 0, value: height)
181184

182185
switch state {
183186
case .began:
184-
dispatchEvent(name: "onDragBegin", data: sizeInfoData(from: sizeInfo))
187+
dispatchEvent(name: "onDragBegin", block: onDragBegin, data: sizeInfoData(from: sizeInfo))
185188
case .changed:
186-
dispatchEvent(name: "onDragChange", data: sizeInfoData(from: sizeInfo))
189+
dispatchEvent(name: "onDragChange", block: onDragChange, data: sizeInfoData(from: sizeInfo))
187190
case .ended, .cancelled:
188-
dispatchEvent(name: "onDragEnd", data: sizeInfoData(from: sizeInfo))
191+
dispatchEvent(name: "onDragEnd", block: onDragEnd, data: sizeInfoData(from: sizeInfo))
189192
default:
190193
Logger.info("Drag state is not supported")
191194
}
@@ -204,15 +207,15 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
204207
func viewControllerDidDismiss() {
205208
isPresented = false
206209
activeIndex = nil
207-
dispatchEvent(name: "onDismiss", data: nil)
210+
dispatchEvent(name: "onDismiss", block: onDismiss, data: nil)
208211
}
209212

210213
func viewControllerDidChangeSize(_ sizeInfo: SizeInfo?) {
211214
guard let sizeInfo else { return }
212215

213216
if sizeInfo.index != activeIndex {
214217
activeIndex = sizeInfo.index
215-
dispatchEvent(name: "onSizeChange", data: sizeInfoData(from: sizeInfo))
218+
dispatchEvent(name: "onSizeChange", block: onSizeChange, data: sizeInfoData(from: sizeInfo))
216219
}
217220
}
218221

@@ -395,8 +398,14 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
395398
}
396399
}
397400

398-
func dispatchEvent(name: String, data: [String: Any]?) {
399-
eventDispatcher?.send(TrueSheetEvent(viewTag: reactTag, name: name, data: data))
401+
func dispatchEvent(name: String, block: RCTDirectEventBlock?, data: [String: Any]?) {
402+
// eventDispatcher doesn't work in New Arch so we need to call it directly :/
403+
// we needed eventDispatcher for Reanimated to work on old arch.
404+
#if RCT_NEW_ARCH_ENABLED
405+
block?(data)
406+
#else
407+
eventDispatcher?.send(TrueSheetEvent(viewTag: reactTag, name: name, data: data))
408+
#endif
400409
}
401410

402411
func dismiss(promise: Promise) {
@@ -443,7 +452,7 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
443452
}
444453

445454
let data = self.sizeInfoData(from: self.viewController.currentSizeInfo)
446-
self.dispatchEvent(name: "onPresent", data: data)
455+
self.dispatchEvent(name: "onPresent", block: self.onPresent, data: data)
447456
promise?.resolve(nil)
448457
}
449458
}

0 commit comments

Comments
 (0)