@lodev09/react-native-true-sheet 3.5.1 → 3.5.2
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.
|
@@ -24,6 +24,7 @@ class RNScreensFragmentObserver(
|
|
|
24
24
|
private var activityLifecycleObserver: DefaultLifecycleObserver? = null
|
|
25
25
|
private val activeModalFragments: MutableSet<Fragment> = mutableSetOf()
|
|
26
26
|
private var isActivityInForeground = true
|
|
27
|
+
private var pendingDismissRunnable: Runnable? = null
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
30
|
* Start observing fragment lifecycle events.
|
|
@@ -52,6 +53,9 @@ class RNScreensFragmentObserver(
|
|
|
52
53
|
if (!isActivityInForeground) return
|
|
53
54
|
|
|
54
55
|
if (isModalFragment(f) && !activeModalFragments.contains(f)) {
|
|
56
|
+
// Cancel any pending dismiss since a modal is being presented
|
|
57
|
+
cancelPendingDismiss()
|
|
58
|
+
|
|
55
59
|
activeModalFragments.add(f)
|
|
56
60
|
|
|
57
61
|
if (activeModalFragments.size == 1) {
|
|
@@ -71,7 +75,8 @@ class RNScreensFragmentObserver(
|
|
|
71
75
|
activeModalFragments.remove(f)
|
|
72
76
|
|
|
73
77
|
if (activeModalFragments.isEmpty()) {
|
|
74
|
-
|
|
78
|
+
// Post dismiss to allow fragment attach to cancel if navigation is happening
|
|
79
|
+
schedulePendingDismiss()
|
|
75
80
|
}
|
|
76
81
|
}
|
|
77
82
|
}
|
|
@@ -79,7 +84,7 @@ class RNScreensFragmentObserver(
|
|
|
79
84
|
override fun onFragmentDestroyed(fm: FragmentManager, f: Fragment) {
|
|
80
85
|
super.onFragmentDestroyed(fm, f)
|
|
81
86
|
|
|
82
|
-
if (activeModalFragments.isEmpty()) {
|
|
87
|
+
if (activeModalFragments.isEmpty() && pendingDismissRunnable == null) {
|
|
83
88
|
onModalDidDismiss()
|
|
84
89
|
}
|
|
85
90
|
}
|
|
@@ -94,6 +99,8 @@ class RNScreensFragmentObserver(
|
|
|
94
99
|
fun stop() {
|
|
95
100
|
val activity = reactContext.currentActivity as? AppCompatActivity
|
|
96
101
|
|
|
102
|
+
cancelPendingDismiss()
|
|
103
|
+
|
|
97
104
|
fragmentLifecycleCallback?.let { callback ->
|
|
98
105
|
activity?.supportFragmentManager?.unregisterFragmentLifecycleCallbacks(callback)
|
|
99
106
|
}
|
|
@@ -107,6 +114,31 @@ class RNScreensFragmentObserver(
|
|
|
107
114
|
activeModalFragments.clear()
|
|
108
115
|
}
|
|
109
116
|
|
|
117
|
+
private fun schedulePendingDismiss() {
|
|
118
|
+
val activity = reactContext.currentActivity ?: return
|
|
119
|
+
val decorView = activity.window?.decorView ?: return
|
|
120
|
+
|
|
121
|
+
cancelPendingDismiss()
|
|
122
|
+
|
|
123
|
+
pendingDismissRunnable = Runnable {
|
|
124
|
+
pendingDismissRunnable = null
|
|
125
|
+
if (activeModalFragments.isEmpty()) {
|
|
126
|
+
onModalWillDismiss()
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
decorView.post(pendingDismissRunnable)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private fun cancelPendingDismiss() {
|
|
133
|
+
val activity = reactContext.currentActivity ?: return
|
|
134
|
+
val decorView = activity.window?.decorView ?: return
|
|
135
|
+
|
|
136
|
+
pendingDismissRunnable?.let {
|
|
137
|
+
decorView.removeCallbacks(it)
|
|
138
|
+
pendingDismissRunnable = null
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
110
142
|
companion object {
|
|
111
143
|
/**
|
|
112
144
|
* Check if fragment is from react-native-screens.
|
package/package.json
CHANGED