@lodev09/react-native-true-sheet 3.5.1 → 3.5.3

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
- onModalWillDismiss()
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.
@@ -14,6 +14,7 @@
14
14
  #import <react/renderer/components/TrueSheetSpec/EventEmitters.h>
15
15
  #import <react/renderer/components/TrueSheetSpec/Props.h>
16
16
  #import <react/renderer/components/TrueSheetSpec/RCTComponentViewHelpers.h>
17
+ #import "TrueSheetView.h"
17
18
  #import "TrueSheetViewController.h"
18
19
  #import "utils/LayoutUtil.h"
19
20
 
@@ -128,6 +129,9 @@ using namespace facebook::react;
128
129
 
129
130
  - (RCTScrollViewComponentView *)findScrollViewInSubviews:(NSArray<UIView *> *)subviews {
130
131
  for (UIView *subview in subviews) {
132
+ if ([subview isKindOfClass:TrueSheetView.class]) {
133
+ continue;
134
+ }
131
135
  if ([subview isKindOfClass:RCTScrollViewComponentView.class]) {
132
136
  return (RCTScrollViewComponentView *)subview;
133
137
  }
@@ -161,7 +165,7 @@ using namespace facebook::react;
161
165
  CGFloat closestDistance = CGFLOAT_MAX;
162
166
 
163
167
  for (UIView *sibling in self.subviews) {
164
- if (sibling == scrollView) {
168
+ if (sibling == scrollView || [sibling isKindOfClass:TrueSheetView.class]) {
165
169
  continue;
166
170
  }
167
171
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lodev09/react-native-true-sheet",
3
- "version": "3.5.1",
3
+ "version": "3.5.3",
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",