@lodev09/react-native-true-sheet 3.6.8 → 3.6.9

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.
@@ -135,6 +135,11 @@ class TrueSheetView(private val reactContext: ThemedReactContext) :
135
135
  val child = getChildAt(index)
136
136
  if (child is TrueSheetContainerView) {
137
137
  child.delegate = null
138
+
139
+ // Dismiss the sheet when container is removed
140
+ if (viewController.isPresented) {
141
+ viewController.dismiss(animated = false)
142
+ }
138
143
  }
139
144
  viewController.removeView(child)
140
145
  }
@@ -159,14 +164,12 @@ class TrueSheetView(private val reactContext: ThemedReactContext) :
159
164
  fun onDropInstance() {
160
165
  reactContext.removeLifecycleEventListener(this)
161
166
 
162
- if (viewController.isPresented) {
163
- viewController.dismiss(animated = false)
164
- }
167
+ viewController.dismiss()
168
+ viewController.delegate = null
165
169
 
166
170
  TrueSheetModule.unregisterView(id)
167
171
  TrueSheetStackManager.removeSheet(this)
168
172
 
169
- viewController.delegate = null
170
173
  didInitiallyPresent = false
171
174
  }
172
175
 
@@ -139,7 +139,6 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
139
139
 
140
140
  // Keyboard State
141
141
  private var detentIndexBeforeKeyboard: Int = -1
142
- private var isKeyboardTransitioning: Boolean = false
143
142
 
144
143
  // Promises
145
144
  var presentPromise: (() -> Unit)? = null
@@ -238,6 +237,14 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
238
237
  private val currentKeyboardInset: Int
239
238
  get() = keyboardObserver?.currentHeight ?: 0
240
239
 
240
+ private val isKeyboardTransitioning: Boolean
241
+ get() = keyboardObserver?.isTransitioning ?: false
242
+
243
+ private fun isFocusedViewWithinSheet(): Boolean {
244
+ val sheet = sheetView ?: return false
245
+ return keyboardObserver?.isFocusedViewWithinSheet(sheet) ?: false
246
+ }
247
+
241
248
  val bottomInset: Int
242
249
  get() = if (edgeToEdgeEnabled) ScreenUtils.getInsets(reactContext).bottom else 0
243
250
 
@@ -320,7 +327,6 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
320
327
  isPresented = false
321
328
  isSheetVisible = false
322
329
  wasHiddenByModal = false
323
- isKeyboardTransitioning = false
324
330
  isPresentAnimating = false
325
331
  lastEmittedPositionPx = -1
326
332
  detentIndexBeforeKeyboard = -1
@@ -872,9 +878,11 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
872
878
  // MARK: - Keyboard Handling
873
879
  // =============================================================================
874
880
 
875
- private fun shouldHandleKeyboard(): Boolean {
881
+ private fun shouldHandleKeyboard(checkFocus: Boolean = true): Boolean {
876
882
  if (wasHiddenByModal) return false
877
- return isTopmostSheet
883
+ if (!isTopmostSheet) return false
884
+ if (checkFocus && !isFocusedViewWithinSheet()) return false
885
+ return true
878
886
  }
879
887
 
880
888
  fun setupKeyboardObserver() {
@@ -886,7 +894,6 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
886
894
  keyboardObserver = TrueSheetKeyboardObserver(coordinator, reactContext).apply {
887
895
  delegate = object : TrueSheetKeyboardObserverDelegate {
888
896
  override fun keyboardWillShow(height: Int) {
889
- isKeyboardTransitioning = true
890
897
  if (!shouldHandleKeyboard()) return
891
898
  detentIndexBeforeKeyboard = currentDetentIndex
892
899
  setupSheetDetents()
@@ -894,7 +901,8 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
894
901
  }
895
902
 
896
903
  override fun keyboardWillHide() {
897
- if (!shouldHandleKeyboard()) return
904
+ if (!shouldHandleKeyboard(checkFocus = false)) return
905
+
898
906
  setupSheetDetents()
899
907
  if (!isDismissing && detentIndexBeforeKeyboard >= 0) {
900
908
  setStateForDetentIndex(detentIndexBeforeKeyboard)
@@ -902,9 +910,7 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
902
910
  }
903
911
  }
904
912
 
905
- override fun keyboardDidHide() {
906
- isKeyboardTransitioning = false
907
- }
913
+ override fun keyboardDidHide() {}
908
914
 
909
915
  override fun keyboardDidChangeHeight(height: Int) {
910
916
  if (!shouldHandleKeyboard()) return
@@ -31,6 +31,20 @@ class TrueSheetKeyboardObserver(private val targetView: View, private val reactC
31
31
  var targetHeight: Int = 0
32
32
  private set
33
33
 
34
+ var isTransitioning: Boolean = false
35
+ private set
36
+
37
+ fun isFocusedViewWithinSheet(sheetView: View): Boolean {
38
+ val focusedView = reactContext.currentActivity?.currentFocus ?: return false
39
+ var current: View? = focusedView
40
+ while (current != null && current !== targetView) {
41
+ if (current === sheetView) return true
42
+ val parent = current.parent
43
+ current = if (parent is View) parent else null
44
+ }
45
+ return false
46
+ }
47
+
34
48
  private var isHiding: Boolean = false
35
49
  private var globalLayoutListener: ViewTreeObserver.OnGlobalLayoutListener? = null
36
50
  private var activityRootView: View? = null
@@ -80,6 +94,7 @@ class TrueSheetKeyboardObserver(private val targetView: View, private val reactC
80
94
  endHeight = getKeyboardHeight()
81
95
  targetHeight = endHeight
82
96
  isHiding = endHeight < startHeight
97
+ isTransitioning = true
83
98
  if (endHeight > startHeight) {
84
99
  delegate?.keyboardWillShow(endHeight)
85
100
  } else if (isHiding) {
@@ -102,6 +117,7 @@ class TrueSheetKeyboardObserver(private val targetView: View, private val reactC
102
117
  override fun onEnd(animation: WindowInsetsAnimationCompat) {
103
118
  val finalHeight = getKeyboardHeight()
104
119
  updateHeight(startHeight, finalHeight, 1f)
120
+ isTransitioning = false
105
121
  if (isHiding) {
106
122
  delegate?.keyboardDidHide()
107
123
  isHiding = false
@@ -134,6 +150,7 @@ class TrueSheetKeyboardObserver(private val targetView: View, private val reactC
134
150
  targetHeight = newHeight
135
151
  isHiding = newHeight < previousHeight
136
152
 
153
+ isTransitioning = true
137
154
  if (newHeight > previousHeight) {
138
155
  delegate?.keyboardWillShow(newHeight)
139
156
  } else if (isHiding) {
@@ -142,6 +159,7 @@ class TrueSheetKeyboardObserver(private val targetView: View, private val reactC
142
159
 
143
160
  // On legacy API, keyboard has already animated - just update immediately
144
161
  updateHeight(previousHeight, newHeight, 1f)
162
+ isTransitioning = false
145
163
 
146
164
  if (isHiding && newHeight == 0) {
147
165
  delegate?.keyboardDidHide()
@@ -96,7 +96,12 @@ using namespace facebook::react;
96
96
 
97
97
  - (void)dealloc {
98
98
  if (_controller && _controller.presentingViewController) {
99
- [_controller dismissViewControllerAnimated:NO completion:nil];
99
+ // Find the root presenting controller to dismiss the entire stack
100
+ UIViewController *root = _controller.presentingViewController;
101
+ while (root.presentingViewController != nil) {
102
+ root = root.presentingViewController;
103
+ }
104
+ [root dismissViewControllerAnimated:YES completion:nil];
100
105
  }
101
106
 
102
107
  _controller.delegate = nil;
@@ -258,10 +263,6 @@ using namespace facebook::react;
258
263
  - (void)prepareForRecycle {
259
264
  [super prepareForRecycle];
260
265
 
261
- if (_controller && _controller.presentingViewController) {
262
- [_controller dismissViewControllerAnimated:YES completion:nil];
263
- }
264
-
265
266
  [TrueSheetModule unregisterViewWithTag:@(self.tag)];
266
267
 
267
268
  _lastStateSize = CGSizeZero;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lodev09/react-native-true-sheet",
3
- "version": "3.6.8",
3
+ "version": "3.6.9",
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",