@lodev09/react-native-true-sheet 3.10.0-beta.4 → 3.10.1

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.
@@ -479,9 +479,9 @@ class TrueSheetView(private val reactContext: ThemedReactContext) :
479
479
  * Resets this sheet's translation and restores dragging when it becomes topmost.
480
480
  * Parent recalculates its translation based on this sheet's position.
481
481
  */
482
- fun resetTranslation() {
482
+ fun resetTranslation(onTranslateEnd: (() -> Unit)? = null) {
483
483
  viewController.sheetView?.behavior?.isDraggable = viewController.draggable
484
- viewController.translateSheet(0)
484
+ viewController.translateSheet(0, onEnd = onTranslateEnd)
485
485
 
486
486
  // Parent should recalculate its translation based on this sheet's position
487
487
  val mySheetTop = viewController.detentCalculator.getSheetTopForDetentIndex(viewController.currentDetentIndex)
@@ -510,7 +510,7 @@ class TrueSheetView(private val reactContext: ThemedReactContext) :
510
510
  eventDispatcher?.dispatchEvent(WillDismissEvent(surfaceId, id))
511
511
  }
512
512
 
513
- override fun viewControllerDidDismiss(hadParent: Boolean) {
513
+ override fun viewControllerDidDismiss(parent: TrueSheetView?) {
514
514
  // Detach coordinator from the root container view
515
515
  viewController.coordinatorLayout?.let { rootContainerView?.removeView(it) }
516
516
  rootContainerView = null
@@ -520,7 +520,14 @@ class TrueSheetView(private val reactContext: ThemedReactContext) :
520
520
  val surfaceId = UIManagerHelper.getSurfaceId(this)
521
521
  eventDispatcher?.dispatchEvent(DidDismissEvent(surfaceId, id))
522
522
 
523
- TrueSheetStackManager.unregisterSheet(this, hadParent)
523
+ TrueSheetStackManager.unregisterSheet(this)
524
+
525
+ parent?.resetTranslation {
526
+ val parentController = parent.viewController
527
+ if (parentController.isPresented && !parentController.isBeingDismissed) {
528
+ parent.viewControllerDidFocus()
529
+ }
530
+ }
524
531
  }
525
532
 
526
533
  override fun viewControllerDidChangeDetent(index: Int, position: Float, detent: Float) {
@@ -50,7 +50,7 @@ interface TrueSheetViewControllerDelegate {
50
50
  fun viewControllerWillPresent(index: Int, position: Float, detent: Float)
51
51
  fun viewControllerDidPresent(index: Int, position: Float, detent: Float)
52
52
  fun viewControllerWillDismiss()
53
- fun viewControllerDidDismiss(hadParent: Boolean)
53
+ fun viewControllerDidDismiss(parent: TrueSheetView?)
54
54
  fun viewControllerDidChangeDetent(index: Int, position: Float, detent: Float)
55
55
  fun viewControllerDidDragBegin(index: Int, position: Float, detent: Float)
56
56
  fun viewControllerDidDragChange(index: Int, position: Float, detent: Float)
@@ -757,6 +757,11 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
757
757
  private fun dismissKeyboard() {
758
758
  isKeyboardDismissProgrammatic = true
759
759
  KeyboardUtils.dismiss(reactContext)
760
+
761
+ // Clear focus from any focused view within the sheet to prevent
762
+ // Android from autofocusing the next focusable view on the main
763
+ // screen when the sheet is removed from the hierarchy.
764
+ sheetView?.findFocus()?.clearFocus()
760
765
  }
761
766
 
762
767
  fun handleBackPress() {
@@ -1158,12 +1163,11 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
1158
1163
  }
1159
1164
 
1160
1165
  private fun emitDidDismissEvents() {
1161
- val hadParent = parentSheetView != null
1162
- parentSheetView?.viewControllerDidFocus()
1166
+ val parent = parentSheetView
1163
1167
  parentSheetView = null
1164
1168
 
1165
1169
  delegate?.viewControllerDidBlur()
1166
- delegate?.viewControllerDidDismiss(hadParent)
1170
+ delegate?.viewControllerDidDismiss(parent)
1167
1171
 
1168
1172
  dismissPromise?.invoke()
1169
1173
  dismissPromise = null
@@ -1219,7 +1223,7 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
1219
1223
  }
1220
1224
  }
1221
1225
 
1222
- fun translateSheet(translationY: Int) {
1226
+ fun translateSheet(translationY: Int, onEnd: (() -> Unit)? = null) {
1223
1227
  val sheet = sheetView ?: return
1224
1228
 
1225
1229
  sheet.animate()
@@ -1229,6 +1233,7 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
1229
1233
  val effectiveTop = sheet.top + sheet.translationY.toInt()
1230
1234
  emitChangePositionDelegate(effectiveTop)
1231
1235
  }
1236
+ .withEndAction { onEnd?.invoke() }
1232
1237
  .start()
1233
1238
  }
1234
1239
 
@@ -48,15 +48,12 @@ object TrueSheetStackManager {
48
48
  }
49
49
 
50
50
  /**
51
- * Unregisters a sheet from the stack and resets parent translation if needed.
51
+ * Unregisters a sheet from the stack.
52
52
  */
53
53
  @JvmStatic
54
- fun unregisterSheet(sheetView: TrueSheetView, hadParent: Boolean) {
54
+ fun unregisterSheet(sheetView: TrueSheetView) {
55
55
  synchronized(presentedSheetStack) {
56
56
  presentedSheetStack.remove(sheetView)
57
- if (hadParent) {
58
- presentedSheetStack.lastOrNull()?.resetTranslation()
59
- }
60
57
  }
61
58
  }
62
59
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lodev09/react-native-true-sheet",
3
- "version": "3.10.0-beta.4",
3
+ "version": "3.10.1",
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",