@lodev09/react-native-true-sheet 3.3.0-beta.3 → 3.3.0-beta.4
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.
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetViewController.kt +22 -6
- package/android/src/main/java/com/lodev09/truesheet/core/RNScreensFragmentObserver.kt +2 -2
- package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetDialogObserver.kt +9 -6
- package/android/src/main/res/anim/true_sheet_fade_in.xml +6 -0
- package/android/src/main/res/anim/true_sheet_fade_out.xml +6 -0
- package/android/src/main/res/values/styles.xml +6 -0
- package/package.json +1 -1
|
@@ -127,6 +127,9 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
|
|
|
127
127
|
private var windowAnimation: Int = 0
|
|
128
128
|
private var lastEmittedPositionPx: Int = -1
|
|
129
129
|
|
|
130
|
+
/** Tracks if this sheet was hidden due to a RN Screens modal (vs sheet stacking) */
|
|
131
|
+
private var wasHiddenByModal = false
|
|
132
|
+
|
|
130
133
|
var presentPromise: (() -> Unit)? = null
|
|
131
134
|
var dismissPromise: (() -> Unit)? = null
|
|
132
135
|
|
|
@@ -265,6 +268,7 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
|
|
|
265
268
|
isDismissing = false
|
|
266
269
|
isPresented = false
|
|
267
270
|
isDialogVisible = false
|
|
271
|
+
wasHiddenByModal = false
|
|
268
272
|
lastEmittedPositionPx = -1
|
|
269
273
|
}
|
|
270
274
|
|
|
@@ -381,13 +385,16 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
|
|
|
381
385
|
rnScreensObserver = RNScreensFragmentObserver(
|
|
382
386
|
reactContext = reactContext,
|
|
383
387
|
onModalPresented = {
|
|
384
|
-
if (isPresented) {
|
|
385
|
-
hideDialog()
|
|
388
|
+
if (isPresented && isDialogVisible) {
|
|
389
|
+
hideDialog(animated = true)
|
|
390
|
+
wasHiddenByModal = true
|
|
386
391
|
}
|
|
387
392
|
},
|
|
388
393
|
onModalDismissed = {
|
|
389
|
-
if
|
|
390
|
-
|
|
394
|
+
// Only show if we were the one hidden by modal, not by sheet stacking
|
|
395
|
+
if (isPresented && wasHiddenByModal) {
|
|
396
|
+
showDialog(animated = true)
|
|
397
|
+
wasHiddenByModal = false
|
|
391
398
|
}
|
|
392
399
|
}
|
|
393
400
|
)
|
|
@@ -437,8 +444,11 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
|
|
|
437
444
|
}
|
|
438
445
|
|
|
439
446
|
/** Hides without dismissing. Used for sheet stacking and RN Screens modals. */
|
|
440
|
-
fun hideDialog(emitPosition: Boolean = false) {
|
|
447
|
+
fun hideDialog(emitPosition: Boolean = false, animated: Boolean = false) {
|
|
441
448
|
isDialogVisible = false
|
|
449
|
+
if (animated) {
|
|
450
|
+
dialog?.window?.setWindowAnimations(com.lodev09.truesheet.R.style.TrueSheetFadeAnimation)
|
|
451
|
+
}
|
|
442
452
|
dialog?.window?.decorView?.visibility = INVISIBLE
|
|
443
453
|
if (emitPosition) {
|
|
444
454
|
emitDismissedPosition()
|
|
@@ -446,12 +456,18 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
|
|
|
446
456
|
}
|
|
447
457
|
|
|
448
458
|
/** Shows a previously hidden dialog. */
|
|
449
|
-
fun showDialog(emitPosition: Boolean = false) {
|
|
459
|
+
fun showDialog(emitPosition: Boolean = false, animated: Boolean = false) {
|
|
450
460
|
isDialogVisible = true
|
|
451
461
|
dialog?.window?.decorView?.visibility = VISIBLE
|
|
452
462
|
if (emitPosition) {
|
|
453
463
|
bottomSheetView?.let { emitChangePositionDelegate(it, realtime = false) }
|
|
454
464
|
}
|
|
465
|
+
if (animated) {
|
|
466
|
+
// Restore original animation after fade-in completes (100ms)
|
|
467
|
+
sheetContainer?.postDelayed({
|
|
468
|
+
dialog?.window?.setWindowAnimations(windowAnimation)
|
|
469
|
+
}, 100)
|
|
470
|
+
}
|
|
455
471
|
}
|
|
456
472
|
|
|
457
473
|
// ====================================================================
|
|
@@ -27,8 +27,8 @@ class RNScreensFragmentObserver(
|
|
|
27
27
|
val fragmentManager = activity.supportFragmentManager
|
|
28
28
|
|
|
29
29
|
fragmentLifecycleCallback = object : FragmentManager.FragmentLifecycleCallbacks() {
|
|
30
|
-
override fun
|
|
31
|
-
super.
|
|
30
|
+
override fun onFragmentPreAttached(fm: FragmentManager, fragment: Fragment, context: android.content.Context) {
|
|
31
|
+
super.onFragmentPreAttached(fm, fragment, context)
|
|
32
32
|
|
|
33
33
|
if (isModalFragment(fragment) && !activeModalFragments.contains(fragment)) {
|
|
34
34
|
activeModalFragments.add(fragment)
|
|
@@ -20,12 +20,15 @@ object TrueSheetDialogObserver {
|
|
|
20
20
|
val parentSheet = presentedSheetStack.lastOrNull()
|
|
21
21
|
?.takeIf { it.viewController.isPresented && it.viewController.isDialogVisible }
|
|
22
22
|
|
|
23
|
-
// Hide parent
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (
|
|
28
|
-
|
|
23
|
+
// Hide any parent sheets that would be visible behind the new sheet
|
|
24
|
+
val newSheetTop = sheetView.viewController.getExpectedSheetTop(detentIndex)
|
|
25
|
+
for (sheet in presentedSheetStack) {
|
|
26
|
+
if (!sheet.viewController.isDialogVisible) continue
|
|
27
|
+
if (sheet.viewController.isExpanded) continue
|
|
28
|
+
|
|
29
|
+
val sheetTop = sheet.viewController.currentSheetTop
|
|
30
|
+
if (sheetTop < newSheetTop) {
|
|
31
|
+
sheet.viewController.hideDialog(emitPosition = true)
|
|
29
32
|
}
|
|
30
33
|
}
|
|
31
34
|
|
|
@@ -6,6 +6,12 @@
|
|
|
6
6
|
<item name="android:windowExitAnimation">@anim/true_sheet_slide_out</item>
|
|
7
7
|
</style>
|
|
8
8
|
|
|
9
|
+
<!-- Fast fade animation - used for hide/show when modal is presented -->
|
|
10
|
+
<style name="TrueSheetFadeAnimation" parent="Animation.AppCompat.Dialog">
|
|
11
|
+
<item name="android:windowEnterAnimation">@anim/true_sheet_fade_in</item>
|
|
12
|
+
<item name="android:windowExitAnimation">@anim/true_sheet_fade_out</item>
|
|
13
|
+
</style>
|
|
14
|
+
|
|
9
15
|
<!-- Default BottomSheetDialog style with smooth animations -->
|
|
10
16
|
<style name="TrueSheetDialog" parent="Theme.Design.Light.BottomSheetDialog">
|
|
11
17
|
<item name="android:windowAnimationStyle">@style/TrueSheetAnimation</item>
|
package/package.json
CHANGED