@lodev09/react-native-true-sheet 3.6.5 → 3.6.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46,7 +46,7 @@ class TrueSheetView(private val reactContext: ThemedReactContext) :
46
46
  // Initial present configuration (set by ViewManager before mount)
47
47
  var initialDetentIndex: Int = -1
48
48
  var initialDetentAnimated: Boolean = true
49
- private var pendingInitialPresentation: Boolean = false
49
+ private var didInitiallyPresent: Boolean = false
50
50
 
51
51
  var stateWrapper: StateWrapper? = null
52
52
  set(value) {
@@ -100,7 +100,15 @@ class TrueSheetView(private val reactContext: ThemedReactContext) :
100
100
 
101
101
  override fun onAttachedToWindow() {
102
102
  super.onAttachedToWindow()
103
- presentInitialDetentIfNeeded()
103
+
104
+ if (initialDetentIndex >= 0 && !didInitiallyPresent) {
105
+ didInitiallyPresent = true
106
+ if (initialDetentAnimated) {
107
+ present(initialDetentIndex, true) { }
108
+ } else {
109
+ post { present(initialDetentIndex, false) { } }
110
+ }
111
+ }
104
112
  }
105
113
 
106
114
  override fun addView(child: View?, index: Int) {
@@ -110,29 +118,11 @@ class TrueSheetView(private val reactContext: ThemedReactContext) :
110
118
  child.delegate = this
111
119
  viewController.createSheet()
112
120
 
113
- if (initialDetentIndex >= 0 && !viewController.isPresented) {
114
- pendingInitialPresentation = true
115
- presentInitialDetentIfNeeded()
116
- }
117
-
118
121
  val surfaceId = UIManagerHelper.getSurfaceId(this)
119
122
  eventDispatcher?.dispatchEvent(MountEvent(surfaceId, id))
120
123
  }
121
124
  }
122
125
 
123
- private fun presentInitialDetentIfNeeded() {
124
- if (!pendingInitialPresentation || initialDetentIndex < 0 || viewController.isPresented || !isAttachedToWindow) {
125
- return
126
- }
127
-
128
- pendingInitialPresentation = false
129
- if (initialDetentAnimated) {
130
- present(initialDetentIndex, true) { }
131
- } else {
132
- post { present(initialDetentIndex, false) { } }
133
- }
134
- }
135
-
136
126
  override fun getChildCount(): Int = viewController.childCount
137
127
 
138
128
  override fun getChildAt(index: Int): View? = viewController.getChildAt(index)
@@ -164,13 +154,16 @@ class TrueSheetView(private val reactContext: ThemedReactContext) :
164
154
 
165
155
  fun onDropInstance() {
166
156
  reactContext.removeLifecycleEventListener(this)
167
- TrueSheetModule.unregisterView(id)
168
- TrueSheetStackManager.removeSheet(this)
169
157
 
170
158
  if (viewController.isPresented) {
171
159
  viewController.dismiss(animated = false)
172
160
  }
161
+
162
+ TrueSheetModule.unregisterView(id)
163
+ TrueSheetStackManager.removeSheet(this)
164
+
173
165
  viewController.delegate = null
166
+ didInitiallyPresent = false
174
167
  }
175
168
 
176
169
  /**
@@ -295,8 +295,6 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
295
295
  sheetView = TrueSheetBottomSheetView(reactContext).apply {
296
296
  delegate = this@TrueSheetViewController
297
297
  }
298
-
299
- setupModalObserver()
300
298
  }
301
299
 
302
300
  private fun cleanupSheet() {
@@ -594,11 +592,6 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
594
592
  return
595
593
  }
596
594
 
597
- val activity = reactContext.currentActivity ?: run {
598
- RNLog.w(reactContext, "TrueSheet: No activity available for presentation.")
599
- return
600
- }
601
-
602
595
  if (isPresented) {
603
596
  setupDimmedBackground(detentIndex)
604
597
  setStateForDetentIndex(detentIndex)
@@ -611,14 +604,38 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
611
604
  setupSheetInCoordinator(coordinator, sheet)
612
605
 
613
606
  // Add coordinator to activity
607
+ val activity = reactContext.currentActivity ?: run {
608
+ RNLog.w(reactContext, "TrueSheet: No activity available for presentation.")
609
+ return
610
+ }
611
+
614
612
  val contentView = activity.findViewById<ViewGroup>(android.R.id.content)
615
613
  contentView?.addView(coordinator)
616
614
 
617
- // Setup back button handling
615
+ emitWillPresentEvents()
616
+
617
+ setupSheetDetents()
618
+ setupDimmedBackground(currentDetentIndex)
619
+ setupKeyboardObserver()
620
+ setupModalObserver()
618
621
  setupBackCallback()
619
622
 
620
- // Start presentation
621
- onSheetShow()
623
+ sheet.setupBackground()
624
+ sheet.setupElevation()
625
+ sheet.setupGrabber()
626
+
627
+ if (shouldAnimatePresent) {
628
+ isPresentAnimating = true
629
+ post { setStateForDetentIndex(currentDetentIndex) }
630
+ } else {
631
+ setStateForDetentIndex(currentDetentIndex)
632
+ emitChangePositionDelegate(detentCalculator.getSheetTopForDetentIndex(currentDetentIndex))
633
+ updateDimAmount()
634
+ finishPresent()
635
+ }
636
+
637
+ isPresented = true
638
+ isSheetVisible = true
622
639
  }
623
640
  }
624
641
 
@@ -641,35 +658,6 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
641
658
  coordinator.addView(sheet, params)
642
659
  }
643
660
 
644
- private fun onSheetShow() {
645
- val sheet = sheetView ?: run {
646
- RNLog.e(reactContext, "TrueSheet: sheetView is null in onSheetShow")
647
- return
648
- }
649
-
650
- emitWillPresentEvents()
651
-
652
- setupSheetDetents()
653
- setupDimmedBackground(currentDetentIndex)
654
- setupKeyboardObserver()
655
- sheet.setupBackground()
656
- sheet.setupElevation()
657
- sheet.setupGrabber()
658
-
659
- if (shouldAnimatePresent) {
660
- isPresentAnimating = true
661
- post { setStateForDetentIndex(currentDetentIndex) }
662
- } else {
663
- setStateForDetentIndex(currentDetentIndex)
664
- emitChangePositionDelegate(detentCalculator.getSheetTopForDetentIndex(currentDetentIndex))
665
- updateDimAmount()
666
- finishPresent()
667
- }
668
-
669
- isPresented = true
670
- isSheetVisible = true
671
- }
672
-
673
661
  fun dismiss(animated: Boolean = true) {
674
662
  if (isDismissing) return
675
663
 
@@ -51,7 +51,7 @@ using namespace facebook::react;
51
51
  BOOL _initialDetentAnimated;
52
52
  BOOL _isSheetUpdatePending;
53
53
  BOOL _pendingLayoutUpdate;
54
- BOOL _pendingInitialPresentation;
54
+ BOOL _didInitiallyPresent;
55
55
  }
56
56
 
57
57
  #pragma mark - Initialization
@@ -74,7 +74,6 @@ using namespace facebook::react;
74
74
  _initialDetentAnimated = YES;
75
75
  _scrollable = NO;
76
76
  _isSheetUpdatePending = NO;
77
- _pendingInitialPresentation = NO;
78
77
  }
79
78
  return self;
80
79
  }
@@ -85,13 +84,14 @@ using namespace facebook::react;
85
84
  if (!self.window)
86
85
  return;
87
86
 
88
- // Register with TurboModule when tag is set
89
87
  if (self.tag > 0) {
90
88
  [TrueSheetModule registerView:self withTag:@(self.tag)];
91
89
  }
92
90
 
93
- // Handle pending initial presentation after view is in window hierarchy
94
- [self presentInitialDetentIfNeeded];
91
+ if (_initialDetentIndex >= 0 && !_didInitiallyPresent) {
92
+ _didInitiallyPresent = YES;
93
+ [self presentAtIndex:_initialDetentIndex animated:_initialDetentAnimated completion:nil];
94
+ }
95
95
  }
96
96
 
97
97
  - (void)dealloc {
@@ -252,21 +252,20 @@ using namespace facebook::react;
252
252
  [_controller setupDraggable];
253
253
  } else if (_initialDetentIndex >= 0) {
254
254
  _pendingLayoutUpdate = NO;
255
- _pendingInitialPresentation = YES;
256
- [self presentInitialDetentIfNeeded];
257
255
  }
258
256
  }
259
257
 
260
258
  - (void)prepareForRecycle {
261
259
  [super prepareForRecycle];
262
260
 
263
- _lastStateSize = CGSizeZero;
264
-
265
261
  if (_controller && _controller.presentingViewController) {
266
262
  [_controller dismissViewControllerAnimated:YES completion:nil];
267
263
  }
268
264
 
269
265
  [TrueSheetModule unregisterViewWithTag:@(self.tag)];
266
+
267
+ _lastStateSize = CGSizeZero;
268
+ _didInitiallyPresent = NO;
270
269
  }
271
270
 
272
271
  #pragma mark - Child Component Mounting
@@ -501,14 +500,6 @@ using namespace facebook::react;
501
500
 
502
501
  #pragma mark - Private Helpers
503
502
 
504
- - (void)presentInitialDetentIfNeeded {
505
- if (!_pendingInitialPresentation || _initialDetentIndex < 0 || _controller.isPresented || !self.window)
506
- return;
507
-
508
- _pendingInitialPresentation = NO;
509
- [self presentAtIndex:_initialDetentIndex animated:_initialDetentAnimated completion:nil];
510
- }
511
-
512
503
  - (UIViewController *)findPresentingViewController {
513
504
  UIWindow *keyWindow = [WindowUtil keyWindow];
514
505
  if (!keyWindow)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lodev09/react-native-true-sheet",
3
- "version": "3.6.5",
3
+ "version": "3.6.7",
4
4
  "description": "The true native bottom sheet experience for your React Native Apps.",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./lib/module/index.js",