react-native-screens 3.33.0 → 3.34.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.
@@ -41,28 +41,37 @@ find_package(ReactAndroid REQUIRED CONFIG)
41
41
  if(${RNS_NEW_ARCH_ENABLED})
42
42
  find_package(fbjni REQUIRED CONFIG)
43
43
 
44
- target_link_libraries(
45
- rnscreens
44
+ if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
45
+ target_link_libraries(rnscreens
46
+ ReactAndroid::reactnative
46
47
  ReactAndroid::jsi
47
- ReactAndroid::react_nativemodule_core
48
- ReactAndroid::react_utils
49
- ReactAndroid::reactnativejni
50
- ReactAndroid::fabricjni
51
- ReactAndroid::react_debug
52
- ReactAndroid::react_render_core
53
- ReactAndroid::runtimeexecutor
54
- ReactAndroid::react_render_graphics
55
- ReactAndroid::rrc_view
56
- ReactAndroid::yoga
57
- ReactAndroid::rrc_text
58
- ReactAndroid::glog
59
- ReactAndroid::react_render_componentregistry
60
- ReactAndroid::react_render_consistency
61
- ReactAndroid::react_performance_timeline
62
- ReactAndroid::react_render_observers_events
63
48
  fbjni::fbjni
64
49
  android
65
- )
50
+ )
51
+ else()
52
+ target_link_libraries(
53
+ rnscreens
54
+ ReactAndroid::jsi
55
+ ReactAndroid::react_nativemodule_core
56
+ ReactAndroid::react_utils
57
+ ReactAndroid::reactnativejni
58
+ ReactAndroid::fabricjni
59
+ ReactAndroid::react_debug
60
+ ReactAndroid::react_render_core
61
+ ReactAndroid::runtimeexecutor
62
+ ReactAndroid::react_render_graphics
63
+ ReactAndroid::rrc_view
64
+ ReactAndroid::yoga
65
+ ReactAndroid::rrc_text
66
+ ReactAndroid::glog
67
+ ReactAndroid::react_render_componentregistry
68
+ ReactAndroid::react_render_consistency
69
+ ReactAndroid::react_performance_timeline
70
+ ReactAndroid::react_render_observers_events
71
+ fbjni::fbjni
72
+ android
73
+ )
74
+ endif()
66
75
  else()
67
76
  target_link_libraries(rnscreens
68
77
  ReactAndroid::jsi
@@ -5,6 +5,7 @@ import android.util.Log
5
5
  import android.view.View
6
6
  import androidx.appcompat.widget.Toolbar
7
7
  import androidx.coordinatorlayout.widget.CoordinatorLayout
8
+ import com.facebook.react.bridge.LifecycleEventListener
8
9
  import com.facebook.react.bridge.ReactApplicationContext
9
10
  import com.facebook.react.uimanager.PixelUtil
10
11
  import com.google.android.material.appbar.AppBarLayout
@@ -19,7 +20,7 @@ import java.lang.ref.WeakReference
19
20
  */
20
21
  internal class ScreenDummyLayoutHelper(
21
22
  reactContext: ReactApplicationContext,
22
- ) {
23
+ ) : LifecycleEventListener {
23
24
  // The state required to compute header dimensions. We want this on instance rather than on class
24
25
  // for context access & being tied to instance lifetime.
25
26
  private lateinit var coordinatorLayout: CoordinatorLayout
@@ -39,7 +40,6 @@ internal class ScreenDummyLayoutHelper(
39
40
  WeakReference(reactContext)
40
41
 
41
42
  init {
42
-
43
43
  // We load the library so that we are able to communicate with our C++ code (descriptor & shadow nodes).
44
44
  // Basically we leak this object to C++, as its lifecycle should span throughout whole application
45
45
  // lifecycle anyway.
@@ -50,16 +50,25 @@ internal class ScreenDummyLayoutHelper(
50
50
  }
51
51
 
52
52
  weakInstance = WeakReference(this)
53
- ensureDummyLayoutWithHeader(reactContext)
53
+
54
+ if (!(reactContext.hasCurrentActivity() && maybeInitDummyLayoutWithHeader(reactContext))) {
55
+ reactContext.addLifecycleEventListener(this)
56
+ }
54
57
  }
55
58
 
56
59
  /**
57
60
  * Initializes dummy view hierarchy with CoordinatorLayout, AppBarLayout and dummy View.
58
61
  * We utilize this to compute header height (app bar layout height) from C++ layer when its needed.
62
+ *
63
+ * @return boolean whether the layout was initialised or not
59
64
  */
60
- private fun ensureDummyLayoutWithHeader(reactContext: ReactApplicationContext) {
61
- if (::coordinatorLayout.isInitialized) {
62
- return
65
+ private fun maybeInitDummyLayoutWithHeader(reactContext: ReactApplicationContext): Boolean {
66
+ if (isLayoutInitialized) {
67
+ return true
68
+ }
69
+
70
+ if (!reactContext.hasCurrentActivity()) {
71
+ return false
63
72
  }
64
73
 
65
74
  // We need to use activity here, as react context does not have theme attributes required by
@@ -108,6 +117,9 @@ internal class ScreenDummyLayoutHelper(
108
117
  addView(appBarLayout)
109
118
  addView(dummyContentView)
110
119
  }
120
+
121
+ isLayoutInitialized = true
122
+ return true
111
123
  }
112
124
 
113
125
  /**
@@ -121,12 +133,18 @@ internal class ScreenDummyLayoutHelper(
121
133
  fontSize: Int,
122
134
  isTitleEmpty: Boolean,
123
135
  ): Float {
124
- if (!::coordinatorLayout.isInitialized) {
125
- Log.e(
126
- TAG,
127
- "[RNScreens] Attempt to access dummy view hierarchy before it is initialized",
128
- )
129
- return 0.0f
136
+ if (!isLayoutInitialized) {
137
+ val reactContext =
138
+ requireReactContext { "[RNScreens] Context was null-ed before dummy layout was initialized" }
139
+ if (!maybeInitDummyLayoutWithHeader(reactContext)) {
140
+ // This theoretically might happen at Fabric + "bridgefull" combination, due to race condition where `reactContext.currentActivity`
141
+ // is still null at this execution point. We don't wanna crash in such case, thus returning zeroed height.
142
+ Log.e(
143
+ TAG,
144
+ "[RNScreens] Failed to late-init layout while computing header height. This is a race-condition-bug in react-native-screens, please file an issue at https://github.com/software-mansion/react-native-screens/issues"
145
+ )
146
+ return 0.0f
147
+ }
130
148
  }
131
149
 
132
150
  if (cache.hasKey(CacheKey(fontSize, isTitleEmpty))) {
@@ -168,10 +186,10 @@ internal class ScreenDummyLayoutHelper(
168
186
  return headerHeight
169
187
  }
170
188
 
171
- private fun requireReactContext(): ReactApplicationContext =
172
- requireNotNull(reactContextRef.get()) {
173
- "[RNScreens] Attempt to require missing react context"
174
- }
189
+ private fun requireReactContext(lazyMessage: (() -> Any)? = null): ReactApplicationContext =
190
+ requireNotNull(
191
+ reactContextRef.get(),
192
+ lazyMessage ?: { "[RNScreens] Attempt to require missing react context" })
175
193
 
176
194
  private fun requireActivity(): Activity =
177
195
  requireNotNull(requireReactContext().currentActivity) {
@@ -195,6 +213,19 @@ internal class ScreenDummyLayoutHelper(
195
213
  @JvmStatic
196
214
  fun getInstance(): ScreenDummyLayoutHelper? = weakInstance.get()
197
215
  }
216
+
217
+ private var isLayoutInitialized = false
218
+
219
+ override fun onHostResume() {
220
+ // This is the earliest we have guarantee that the context has a reference to an activity.
221
+ val reactContext = requireReactContext { "[RNScreens] ReactContext missing in onHostResume! This should not happen." }
222
+ check(maybeInitDummyLayoutWithHeader(reactContext)) { "[RNScreens] Failed to initialise dummy layout in onHostResume. This is not expected."}
223
+ reactContext.removeLifecycleEventListener(this)
224
+ }
225
+
226
+ override fun onHostPause() = Unit
227
+
228
+ override fun onHostDestroy() = Unit
198
229
  }
199
230
 
200
231
  private data class CacheKey(
@@ -38,25 +38,34 @@ target_include_directories(
38
38
  ${LIB_ANDROID_GENERATED_COMPONENTS_DIR}
39
39
  )
40
40
 
41
- target_link_libraries(
42
- ${LIB_TARGET_NAME}
43
- fbjni
44
- folly_runtime
45
- glog
46
- jsi
47
- react_codegen_rncore
48
- react_debug
49
- react_nativemodule_core
50
- react_render_core
51
- react_render_debug
52
- react_render_graphics
53
- react_render_mapbuffer
54
- react_render_componentregistry
55
- react_utils
56
- rrc_view
57
- turbomodulejsijni
58
- yoga
59
- )
41
+ if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
42
+ target_link_libraries(
43
+ ${LIB_TARGET_NAME}
44
+ ReactAndroid::reactnative
45
+ ReactAndroid::jsi
46
+ fbjni::fbjni
47
+ )
48
+ else()
49
+ target_link_libraries(
50
+ ${LIB_TARGET_NAME}
51
+ fbjni
52
+ folly_runtime
53
+ glog
54
+ jsi
55
+ react_codegen_rncore
56
+ react_debug
57
+ react_nativemodule_core
58
+ react_render_core
59
+ react_render_debug
60
+ react_render_graphics
61
+ react_render_mapbuffer
62
+ react_render_componentregistry
63
+ react_utils
64
+ rrc_view
65
+ turbomodulejsijni
66
+ yoga
67
+ )
68
+ endif()
60
69
 
61
70
  target_compile_options(
62
71
  ${LIB_TARGET_NAME}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-screens",
3
- "version": "3.33.0",
3
+ "version": "3.34.1",
4
4
  "description": "Native navigation primitives for your React Native app.",
5
5
  "scripts": {
6
6
  "submodules": "git submodule update --init --recursive && (cd react-navigation && yarn)",