@@ -97,11 +97,14 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
97
97
98
98
super. removeReactSubview ( subview)
99
99
100
+ // Touch handler for Old Arch
100
101
touchHandler. detach ( from: subview)
102
+
103
+ // Touch handler that works in New Arch
101
104
surfaceTouchHandler. detach ( from: subview)
102
105
103
106
// Remove all constraints
104
- // Fixes New Arch weird layout degration
107
+ // Fixes New Arch weird layout issue :/
105
108
containerView? . unpin ( )
106
109
footerView? . unpin ( )
107
110
contentView? . unpin ( )
@@ -149,7 +152,7 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
149
152
present ( at: initialIndex, promise: nil , animated: initialIndexAnimated)
150
153
}
151
154
152
- dispatchEvent ( name: " onMount " , data: nil )
155
+ dispatchEvent ( name: " onMount " , block : onMount , data: nil )
153
156
}
154
157
}
155
158
@@ -173,19 +176,19 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
173
176
174
177
func viewControllerDidChangeWidth( _ width: CGFloat ) {
175
178
// 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] )
177
180
}
178
181
179
182
func viewControllerDidDrag( _ state: UIGestureRecognizer . State , _ height: CGFloat ) {
180
183
let sizeInfo = SizeInfo ( index: activeIndex ?? 0 , value: height)
181
184
182
185
switch state {
183
186
case . began:
184
- dispatchEvent ( name: " onDragBegin " , data: sizeInfoData ( from: sizeInfo) )
187
+ dispatchEvent ( name: " onDragBegin " , block : onDragBegin , data: sizeInfoData ( from: sizeInfo) )
185
188
case . changed:
186
- dispatchEvent ( name: " onDragChange " , data: sizeInfoData ( from: sizeInfo) )
189
+ dispatchEvent ( name: " onDragChange " , block : onDragChange , data: sizeInfoData ( from: sizeInfo) )
187
190
case . ended, . cancelled:
188
- dispatchEvent ( name: " onDragEnd " , data: sizeInfoData ( from: sizeInfo) )
191
+ dispatchEvent ( name: " onDragEnd " , block : onDragEnd , data: sizeInfoData ( from: sizeInfo) )
189
192
default :
190
193
Logger . info ( " Drag state is not supported " )
191
194
}
@@ -204,15 +207,15 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
204
207
func viewControllerDidDismiss( ) {
205
208
isPresented = false
206
209
activeIndex = nil
207
- dispatchEvent ( name: " onDismiss " , data: nil )
210
+ dispatchEvent ( name: " onDismiss " , block : onDismiss , data: nil )
208
211
}
209
212
210
213
func viewControllerDidChangeSize( _ sizeInfo: SizeInfo ? ) {
211
214
guard let sizeInfo else { return }
212
215
213
216
if sizeInfo. index != activeIndex {
214
217
activeIndex = sizeInfo. index
215
- dispatchEvent ( name: " onSizeChange " , data: sizeInfoData ( from: sizeInfo) )
218
+ dispatchEvent ( name: " onSizeChange " , block : onSizeChange , data: sizeInfoData ( from: sizeInfo) )
216
219
}
217
220
}
218
221
@@ -395,8 +398,14 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
395
398
}
396
399
}
397
400
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
400
409
}
401
410
402
411
func dismiss( promise: Promise ) {
@@ -443,7 +452,7 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
443
452
}
444
453
445
454
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)
447
456
promise? . resolve ( nil )
448
457
}
449
458
}
0 commit comments