@@ -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 }
@@ -104,9 +100,17 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
104
100
touchHandler. detach ( from: subview)
105
101
surfaceTouchHandler. detach ( from: subview)
106
102
103
+ // Remove all constraints
104
+ // Fixes New Arch weird layout degration
105
+ containerView? . unpin ( )
106
+ footerView? . unpin ( )
107
+ contentView? . unpin ( )
108
+ scrollView? . unpin ( )
109
+
107
110
containerView = nil
108
111
contentView = nil
109
112
footerView = nil
113
+ scrollView = nil
110
114
}
111
115
112
116
override func didUpdateReactSubviews( ) {
@@ -131,8 +135,7 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
131
135
// Set footer constraints
132
136
if let footerView {
133
137
footerView. pinTo ( view: viewController. view, from: [ . left, . right, . bottom] , with: 0 ) { constraints in
134
- self . footerViewBottomConstraint = constraints. bottom
135
- self . footerViewHeightConstraint = constraints. height
138
+ self . footerConstraints = constraints
136
139
}
137
140
138
141
// Set initial footer height
@@ -153,19 +156,15 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
153
156
// MARK: - ViewController delegate
154
157
155
158
func viewControllerKeyboardWillHide( ) {
156
- guard let footerViewBottomConstraint else { return }
157
-
158
- footerViewBottomConstraint. constant = 0
159
+ footerConstraints? . bottom? . constant = 0
159
160
160
161
UIView . animate ( withDuration: 0.3 ) {
161
162
self . viewController. view. layoutIfNeeded ( )
162
163
}
163
164
}
164
165
165
166
func viewControllerKeyboardWillShow( _ keyboardHeight: CGFloat ) {
166
- guard let footerViewBottomConstraint else { return }
167
-
168
- footerViewBottomConstraint. constant = - keyboardHeight
167
+ footerConstraints? . bottom? . constant = - keyboardHeight
169
168
170
169
UIView . animate ( withDuration: 0.3 ) {
171
170
self . viewController. view. layoutIfNeeded ( )
@@ -193,7 +192,13 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
193
192
}
194
193
195
194
func viewControllerWillAppear( ) {
196
- setupScrollable ( )
195
+ guard let contentView, let scrollView, let containerView else {
196
+ return
197
+ }
198
+
199
+ // Add constraints to fix weirdness and support ScrollView
200
+ contentView. pinTo ( view: containerView, constraints: nil )
201
+ scrollView. pinTo ( view: contentView, constraints: nil )
197
202
}
198
203
199
204
func viewControllerDidDismiss( ) {
@@ -257,19 +262,18 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
257
262
@objc
258
263
func setFooterHeight( _ height: NSNumber ) {
259
264
let footerHeight = CGFloat ( height. floatValue)
260
- guard let footerView, let footerViewHeightConstraint,
261
- viewController. footerHeight != footerHeight else {
265
+ guard let footerView, viewController. footerHeight != footerHeight else {
262
266
return
263
267
}
264
268
265
269
viewController. footerHeight = footerHeight
266
270
267
271
if footerView. subviews. first != nil {
268
272
containerView? . bringSubviewToFront ( footerView)
269
- footerViewHeightConstraint . constant = viewController. footerHeight
273
+ footerConstraints ? . height ? . constant = viewController. footerHeight
270
274
} else {
271
275
containerView? . sendSubviewToBack ( footerView)
272
- footerViewHeightConstraint . constant = 0
276
+ footerConstraints ? . height ? . constant = 0
273
277
}
274
278
275
279
if #available( iOS 15 . 0 , * ) {
@@ -366,7 +370,7 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
366
370
367
371
@objc
368
372
func setScrollableHandle( _ tag: NSNumber ? ) {
369
- scrollableTag = tag
373
+ scrollView = uiManager ? . view ( forReactTag : tag)
370
374
}
371
375
372
376
// MARK: - Methods
@@ -391,20 +395,6 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
391
395
}
392
396
}
393
397
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
398
func dispatchEvent( name: String , data: [ String : Any ] ? ) {
409
399
eventDispatcher? . send ( TrueSheetEvent ( viewTag: reactTag, name: name, data: data) )
410
400
}
0 commit comments