@@ -41,17 +41,13 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
41
41
// MARK: - Content properties
42
42
43
43
private var containerView : UIView ?
44
-
45
44
private var contentView : UIView ?
46
45
private var footerView : UIView ?
46
+ private var scrollView : UIView ?
47
47
48
- // Reference the bottom constraint to adjust during keyboard event
49
- private var footerViewBottomConstraint : NSLayoutConstraint ?
50
-
51
- // Reference height constraint during content updates
52
- private var footerViewHeightConstraint : NSLayoutConstraint ?
53
-
54
- private var scrollableTag : NSNumber ?
48
+ // Bottom: Reference the bottom constraint to adjust during keyboard event
49
+ // Height: Reference height constraint during content updates
50
+ private var footerConstraints : Constraints ?
55
51
56
52
private var uiManager : RCTUIManager ? {
57
53
guard let uiManager = bridge? . uiManager else { return nil }
@@ -101,12 +97,23 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
101
97
102
98
super. removeReactSubview ( subview)
103
99
100
+ // Touch handler for Old Arch
104
101
touchHandler. detach ( from: subview)
102
+
103
+ // Touch handler that works in New Arch
105
104
surfaceTouchHandler. detach ( from: subview)
106
105
106
+ // Remove all constraints
107
+ // Fixes New Arch weird layout issue :/
108
+ containerView? . unpin ( )
109
+ footerView? . unpin ( )
110
+ contentView? . unpin ( )
111
+ scrollView? . unpin ( )
112
+
107
113
containerView = nil
108
114
contentView = nil
109
115
footerView = nil
116
+ scrollView = nil
110
117
}
111
118
112
119
override func didUpdateReactSubviews( ) {
@@ -131,8 +138,7 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
131
138
// Set footer constraints
132
139
if let footerView {
133
140
footerView. pinTo ( view: viewController. view, from: [ . left, . right, . bottom] , with: 0 ) { constraints in
134
- self . footerViewBottomConstraint = constraints. bottom
135
- self . footerViewHeightConstraint = constraints. height
141
+ self . footerConstraints = constraints
136
142
}
137
143
138
144
// Set initial footer height
@@ -146,26 +152,22 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
146
152
present ( at: initialIndex, promise: nil , animated: initialIndexAnimated)
147
153
}
148
154
149
- dispatchEvent ( name: " onMount " , data: nil )
155
+ dispatchEvent ( name: " onMount " , block : onMount , data: nil )
150
156
}
151
157
}
152
158
153
159
// MARK: - ViewController delegate
154
160
155
161
func viewControllerKeyboardWillHide( ) {
156
- guard let footerViewBottomConstraint else { return }
157
-
158
- footerViewBottomConstraint. constant = 0
162
+ footerConstraints? . bottom? . constant = 0
159
163
160
164
UIView . animate ( withDuration: 0.3 ) {
161
165
self . viewController. view. layoutIfNeeded ( )
162
166
}
163
167
}
164
168
165
169
func viewControllerKeyboardWillShow( _ keyboardHeight: CGFloat ) {
166
- guard let footerViewBottomConstraint else { return }
167
-
168
- footerViewBottomConstraint. constant = - keyboardHeight
170
+ footerConstraints? . bottom? . constant = - keyboardHeight
169
171
170
172
UIView . animate ( withDuration: 0.3 ) {
171
173
self . viewController. view. layoutIfNeeded ( )
@@ -174,40 +176,46 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
174
176
175
177
func viewControllerDidChangeWidth( _ width: CGFloat ) {
176
178
// We only pass width to JS since height is handled by the constraints
177
- dispatchEvent ( name: " onContainerSizeChange " , data: [ " width " : width] )
179
+ dispatchEvent ( name: " onContainerSizeChange " , block : onContainerSizeChange , data: [ " width " : width] )
178
180
}
179
181
180
182
func viewControllerDidDrag( _ state: UIGestureRecognizer . State , _ height: CGFloat ) {
181
183
let sizeInfo = SizeInfo ( index: activeIndex ?? 0 , value: height)
182
184
183
185
switch state {
184
186
case . began:
185
- dispatchEvent ( name: " onDragBegin " , data: sizeInfoData ( from: sizeInfo) )
187
+ dispatchEvent ( name: " onDragBegin " , block : onDragBegin , data: sizeInfoData ( from: sizeInfo) )
186
188
case . changed:
187
- dispatchEvent ( name: " onDragChange " , data: sizeInfoData ( from: sizeInfo) )
189
+ dispatchEvent ( name: " onDragChange " , block : onDragChange , data: sizeInfoData ( from: sizeInfo) )
188
190
case . ended, . cancelled:
189
- dispatchEvent ( name: " onDragEnd " , data: sizeInfoData ( from: sizeInfo) )
191
+ dispatchEvent ( name: " onDragEnd " , block : onDragEnd , data: sizeInfoData ( from: sizeInfo) )
190
192
default :
191
193
Logger . info ( " Drag state is not supported " )
192
194
}
193
195
}
194
196
195
197
func viewControllerWillAppear( ) {
196
- setupScrollable ( )
198
+ guard let contentView, let scrollView, let containerView else {
199
+ return
200
+ }
201
+
202
+ // Add constraints to fix weirdness and support ScrollView
203
+ contentView. pinTo ( view: containerView, constraints: nil )
204
+ scrollView. pinTo ( view: contentView, constraints: nil )
197
205
}
198
206
199
207
func viewControllerDidDismiss( ) {
200
208
isPresented = false
201
209
activeIndex = nil
202
- dispatchEvent ( name: " onDismiss " , data: nil )
210
+ dispatchEvent ( name: " onDismiss " , block : onDismiss , data: nil )
203
211
}
204
212
205
213
func viewControllerDidChangeSize( _ sizeInfo: SizeInfo ? ) {
206
214
guard let sizeInfo else { return }
207
215
208
216
if sizeInfo. index != activeIndex {
209
217
activeIndex = sizeInfo. index
210
- dispatchEvent ( name: " onSizeChange " , data: sizeInfoData ( from: sizeInfo) )
218
+ dispatchEvent ( name: " onSizeChange " , block : onSizeChange , data: sizeInfoData ( from: sizeInfo) )
211
219
}
212
220
}
213
221
@@ -257,19 +265,18 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
257
265
@objc
258
266
func setFooterHeight( _ height: NSNumber ) {
259
267
let footerHeight = CGFloat ( height. floatValue)
260
- guard let footerView, let footerViewHeightConstraint,
261
- viewController. footerHeight != footerHeight else {
268
+ guard let footerView, viewController. footerHeight != footerHeight else {
262
269
return
263
270
}
264
271
265
272
viewController. footerHeight = footerHeight
266
273
267
274
if footerView. subviews. first != nil {
268
275
containerView? . bringSubviewToFront ( footerView)
269
- footerViewHeightConstraint . constant = viewController. footerHeight
276
+ footerConstraints ? . height ? . constant = viewController. footerHeight
270
277
} else {
271
278
containerView? . sendSubviewToBack ( footerView)
272
- footerViewHeightConstraint . constant = 0
279
+ footerConstraints ? . height ? . constant = 0
273
280
}
274
281
275
282
if #available( iOS 15 . 0 , * ) {
@@ -366,7 +373,7 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
366
373
367
374
@objc
368
375
func setScrollableHandle( _ tag: NSNumber ? ) {
369
- scrollableTag = tag
376
+ scrollView = uiManager ? . view ( forReactTag : tag)
370
377
}
371
378
372
379
// MARK: - Methods
@@ -391,22 +398,14 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
391
398
}
392
399
}
393
400
394
- func setupScrollable( ) {
395
- guard let contentView, let containerView, let scrollableTag else {
396
- return
397
- }
398
-
399
- let scrollView = uiManager? . view ( forReactTag: scrollableTag)
400
-
401
- // Add constraints to fix weirdness and support ScrollView
402
- if let scrollView {
403
- contentView. pinTo ( view: containerView, constraints: nil )
404
- scrollView. pinTo ( view: contentView, constraints: nil )
405
- }
406
- }
407
-
408
- func dispatchEvent( name: String , data: [ String : Any ] ? ) {
409
- 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
410
409
}
411
410
412
411
func dismiss( promise: Promise ) {
@@ -453,7 +452,7 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
453
452
}
454
453
455
454
let data = self . sizeInfoData ( from: self . viewController. currentSizeInfo)
456
- self . dispatchEvent ( name: " onPresent " , data: data)
455
+ self . dispatchEvent ( name: " onPresent " , block : self . onPresent , data: data)
457
456
promise? . resolve ( nil )
458
457
}
459
458
}
0 commit comments