@callstack/react-native-brownfield 5.0.2 → 5.1.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.
Files changed (45) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/android/src/main/java/com/callstack/reactnativebrownfield/ReactNativeBrownfield.kt +47 -4
  3. package/android/src/main/java/com/callstack/reactnativebrownfield/ReactNativeFragment.kt +23 -1
  4. package/gradle-plugin/brownfield/build.gradle.kts +7 -0
  5. package/gradle-plugin/brownfield/gradle/libs.versions.toml +2 -0
  6. package/gradle-plugin/brownfield/gradle.properties +1 -1
  7. package/gradle-plugin/brownfield/src/main/kotlin/com/callstack/react/brownfield/artifacts/RncTransitiveDependencyDiscoverer.kt +96 -0
  8. package/gradle-plugin/brownfield/src/main/kotlin/com/callstack/react/brownfield/expo/ExpoPublishingHelper.kt +10 -214
  9. package/gradle-plugin/brownfield/src/main/kotlin/com/callstack/react/brownfield/expo/utils/BrownfieldPublishingInfo.kt +7 -0
  10. package/gradle-plugin/brownfield/src/main/kotlin/com/callstack/react/brownfield/plugin/RNBrownfieldPlugin.kt +92 -1
  11. package/gradle-plugin/brownfield/src/main/kotlin/com/callstack/react/brownfield/shared/Constants.kt +12 -1
  12. package/gradle-plugin/brownfield/src/main/kotlin/com/callstack/react/brownfield/{expo/utils/BrownfieldPrimitives.kt → shared/DependencyInfo.kt} +3 -8
  13. package/gradle-plugin/brownfield/src/main/kotlin/com/callstack/react/brownfield/shared/DependencyPublishability.kt +22 -0
  14. package/gradle-plugin/brownfield/src/main/kotlin/com/callstack/react/brownfield/shared/GradleDependencyCollector.kt +44 -0
  15. package/gradle-plugin/brownfield/src/main/kotlin/com/callstack/react/brownfield/shared/PublishingMetadataInjector.kt +181 -0
  16. package/gradle-plugin/brownfield/src/main/kotlin/com/callstack/react/brownfield/shared/TransitiveDependencyFiltering.kt +17 -0
  17. package/gradle-plugin/brownfield/src/main/kotlin/com/callstack/react/brownfield/{expo/utils → shared}/VersionMediatingDependencySet.kt +1 -1
  18. package/gradle-plugin/brownfield/src/main/kotlin/com/callstack/react/brownfield/utils/Extension.kt +11 -0
  19. package/gradle-plugin/brownfield/src/test/kotlin/com/callstack/react/brownfield/artifacts/RncTransitiveDependencyDiscovererTest.kt +171 -0
  20. package/gradle-plugin/brownfield/src/test/kotlin/com/callstack/react/brownfield/expo/ExpoPublishingHelperGradleFallbackTest.kt +47 -0
  21. package/gradle-plugin/brownfield/src/test/kotlin/com/callstack/react/brownfield/plugin/LegacyConsumerConfigurationTest.kt +110 -0
  22. package/gradle-plugin/brownfield/src/test/kotlin/com/callstack/react/brownfield/shared/DependencyPublishabilityTest.kt +67 -0
  23. package/gradle-plugin/brownfield/src/test/kotlin/com/callstack/react/brownfield/shared/PublishingMetadataInjectorTest.kt +222 -0
  24. package/gradle-plugin/brownfield/src/test/kotlin/com/callstack/react/brownfield/shared/TransitiveDependencyFilteringTest.kt +37 -0
  25. package/gradle-plugin/brownfield/src/test/kotlin/com/callstack/react/brownfield/shared/VersionMediatingDependencySetTest.kt +42 -0
  26. package/gradle-plugin/brownfield/src/test/kotlin/com/callstack/react/brownfield/utils/ExtensionTest.kt +11 -0
  27. package/ios/BrownfieldReactHostPreloader.h +30 -0
  28. package/ios/BrownfieldReactHostPreloader.m +113 -0
  29. package/ios/BrownfieldSurfaceRegistry.swift +93 -0
  30. package/ios/Expo/ExpoHostRuntime.swift +70 -8
  31. package/ios/JSBundleLoadObserver.swift +64 -17
  32. package/ios/ReactHostPreloading.swift +177 -0
  33. package/ios/ReactNativeBrownfield.swift +36 -1
  34. package/ios/Vanilla/ReactNativeHostRuntime.swift +28 -6
  35. package/ios/Views/ReactNativeView.swift +34 -5
  36. package/ios/Views/ReactNativeViewController.swift +120 -1
  37. package/lib/commonjs/expo-config-plugin/android/utils/constants.js +1 -1
  38. package/lib/commonjs/expo-config-plugin/template/android/ReactNativeHostManager.post55.kt +6 -1
  39. package/lib/module/expo-config-plugin/android/utils/constants.js +1 -1
  40. package/lib/module/expo-config-plugin/template/android/ReactNativeHostManager.post55.kt +6 -1
  41. package/lib/typescript/commonjs/src/expo-config-plugin/android/utils/constants.d.ts +2 -2
  42. package/lib/typescript/module/src/expo-config-plugin/android/utils/constants.d.ts +2 -2
  43. package/package.json +2 -2
  44. package/src/expo-config-plugin/android/utils/constants.ts +1 -1
  45. package/src/expo-config-plugin/template/android/ReactNativeHostManager.post55.kt +6 -1
@@ -46,7 +46,7 @@ class ReactNativeBrownfieldDelegate: RCTDefaultReactNativeFactoryDelegate {
46
46
 
47
47
  final class ReactNativeHostRuntime {
48
48
  public static let shared = ReactNativeHostRuntime()
49
- private let jsBundleLoadObserver = JSBundleLoadObserver()
49
+ let preloadState = ReactHostPreloadState()
50
50
  private var delegate = ReactNativeBrownfieldDelegate()
51
51
 
52
52
  private func configureDevLoadingView() {
@@ -133,6 +133,7 @@ final class ReactNativeHostRuntime {
133
133
  }
134
134
 
135
135
  reactNativeFactory = nil
136
+ preloadState.reset()
136
137
  }
137
138
 
138
139
  public func view(
@@ -145,7 +146,7 @@ final class ReactNativeHostRuntime {
145
146
  return reactNativeFactory?.rootViewFactory.view(
146
147
  withModuleName: moduleName,
147
148
  initialProperties: initialProps,
148
- launchOptions: launchOptions
149
+ launchOptions: preloadState.launchOptions(overriddenBy: launchOptions)
149
150
  )
150
151
  }
151
152
 
@@ -188,17 +189,38 @@ final class ReactNativeHostRuntime {
188
189
  /**
189
190
  * Starts React Native with optional callback when bundle is loaded.
190
191
  *
191
- * @param onBundleLoaded Optional callback invoked after JS bundle is fully loaded.
192
+ * @param onBundleLoaded Optional callback invoked on the main thread after JS bundle is fully loaded.
192
193
  */
193
194
  public func startReactNative(onBundleLoaded: (() -> Void)?) {
195
+ // The callback registration is outside of the guard below. An earlier `startReactNative` call
196
+ // can already have made the factory, and the callback must still run.
197
+ if let onBundleLoaded {
198
+ preloadState.jsBundleLoadObserver.observe(onBundleLoaded: onBundleLoaded)
199
+ }
200
+
194
201
  guard reactNativeFactory == nil else { return }
195
202
 
196
203
  delegate.dependencyProvider = RCTAppDependencyProvider()
197
204
  reactNativeFactory = RCTReactNativeFactory(delegate: delegate)
205
+ }
206
+ }
198
207
 
199
- if let onBundleLoaded {
200
- jsBundleLoadObserver.observeOnce(onBundleLoaded: onBundleLoaded)
201
- }
208
+ extension ReactNativeHostRuntime: ReactHostPreloading {
209
+ var reactNativeFactoryForPreload: AnyObject? {
210
+ return reactNativeFactory
211
+ }
212
+
213
+ /**
214
+ * The bare React Native delegate resolves the bundle URL from the override, from Metro, or from
215
+ * the embedded bundle. No step waits for an asynchronous operation. Thus a preload uses the same
216
+ * bundle as the first view.
217
+ */
218
+ func canPreloadReactNative() -> Bool {
219
+ return true
220
+ }
221
+
222
+ func prepareDevLoadingView() {
223
+ configureDevLoadingView()
202
224
  }
203
225
  }
204
226
  #endif
@@ -1,20 +1,38 @@
1
1
  import SwiftUI
2
2
 
3
+ /**
4
+ Links a SwiftUI `ReactNativeView` to the view controller it hosts, so the
5
+ SwiftUI layer can ask whether this surface may act on `popToNative()`.
6
+ */
7
+ final class BrownfieldSurfaceHost {
8
+ weak var controller: ReactNativeViewController?
9
+
10
+ var isPopTarget: Bool { controller?.isPopTarget ?? false }
11
+ }
12
+
3
13
  /**
4
14
  A UIViewControllerRepresentable that bridges ReactNativeViewController to SwiftUI.
5
15
  */
6
16
  struct ReactNativeViewRepresentable: UIViewControllerRepresentable {
7
17
  var moduleName: String
8
18
  var initialProperties: [String: Any] = [:]
19
+ var host: BrownfieldSurfaceHost
9
20
 
10
21
  func makeUIViewController(context: Context) -> UIViewController {
11
- return ReactNativeViewController(
22
+ let controller = ReactNativeViewController(
12
23
  moduleName: moduleName,
13
24
  initialProperties: initialProperties
14
25
  )
26
+ controller.isHostedBySwiftUI = true
27
+ host.controller = controller
28
+ return controller
15
29
  }
16
30
 
17
- func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
31
+ func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
32
+ if let controller = uiViewController as? ReactNativeViewController {
33
+ host.controller = controller
34
+ }
35
+ }
18
36
  }
19
37
 
20
38
  /**
@@ -24,6 +42,7 @@ struct ReactNativeViewRepresentable: UIViewControllerRepresentable {
24
42
  @available(iOS 15.0, *)
25
43
  public struct ReactNativeView: View {
26
44
  @Environment(\.dismiss) var dismiss
45
+ @State private var host = BrownfieldSurfaceHost()
27
46
  var moduleName: String
28
47
  var initialProperties: [String: Any] = [:]
29
48
 
@@ -35,11 +54,21 @@ public struct ReactNativeView: View {
35
54
  public var body: some View {
36
55
  ReactNativeViewRepresentable(
37
56
  moduleName: moduleName,
38
- initialProperties: initialProperties
57
+ initialProperties: initialProperties,
58
+ host: host
39
59
  )
40
60
  .ignoresSafeArea(.all)
41
- .onReceive(NotificationCenter.default.publisher(for: NSNotification.Name.popToNative))
42
- { notification in
61
+ // `.popToNative` is public API and may be posted from any thread, while
62
+ // `host.isPopTarget` reads UIKit state — so deliver on main.
63
+ .onReceive(
64
+ NotificationCenter.default
65
+ .publisher(for: NSNotification.Name.popToNative)
66
+ .receive(on: DispatchQueue.main)
67
+ ) { _ in
68
+ // Every live surface receives this app-wide notification; only the
69
+ // topmost on-screen one may dismiss.
70
+ // https://github.com/callstack/react-native-brownfield/issues/354
71
+ guard host.isPopTarget else { return }
43
72
  dismiss()
44
73
  }
45
74
  }
@@ -7,6 +7,25 @@ internal import EXUpdates
7
7
  @objc public class ReactNativeViewController: UIViewController {
8
8
  private var moduleName: String
9
9
  private var initialProperties: [String: Any]?
10
+ /// Identifies this surface in `BrownfieldSurfaceRegistry`, which decides
11
+ /// which single surface may act on `popToNative()`.
12
+ private var surfaceID: BrownfieldSurfaceID?
13
+
14
+ /// Set by `ReactNativeView`. SwiftUI owns its navigation state, so an
15
+ /// imperative `popViewController` is reverted; the SwiftUI host dismisses
16
+ /// instead and this controller stands down.
17
+ internal var isHostedBySwiftUI = false
18
+
19
+ /// True from the start of a disappearance transition until the surface next
20
+ /// appears. `view.window` stays non-nil for the whole animation, so this is
21
+ /// what distinguishes "the host already dismissed us" from "nothing happened".
22
+ private var isDisappearing = false
23
+
24
+ /// Whether this surface is the one allowed to act on `popToNative()`.
25
+ internal var isPopTarget: Bool {
26
+ guard let surfaceID else { return false }
27
+ return BrownfieldSurfaceRegistry.shared.isPopTarget(surfaceID)
28
+ }
10
29
 
11
30
  #if canImport(EXUpdates)
12
31
  private let expoUpdatesDelegate = ReactNativeExpoUpdatesDelegate()
@@ -39,6 +58,12 @@ internal import EXUpdates
39
58
  #if !canImport(EXUpdates)
40
59
  renderReactNativeView()
41
60
  #endif
61
+
62
+ // Visibility is resolved live: SwiftUI recreates hosted controllers, so a
63
+ // cached lifecycle flag is stale when the notification arrives.
64
+ surfaceID = BrownfieldSurfaceRegistry.shared.register { [weak self] in
65
+ self?.viewIfLoaded?.window != nil
66
+ }
42
67
 
43
68
  NotificationCenter.default.addObserver(
44
69
  self,
@@ -56,8 +81,31 @@ internal import EXUpdates
56
81
  }
57
82
  }
58
83
 
84
+ public override func viewWillAppear(_ animated: Bool) {
85
+ super.viewWillAppear(animated)
86
+
87
+ isDisappearing = false
88
+
89
+ // Ordered here rather than in `viewDidAppear`: during a modal presentation
90
+ // the covered surface is still in a window, so waiting for `viewDidAppear`
91
+ // would let it out-rank the surface being presented over it.
92
+ if let surfaceID {
93
+ BrownfieldSurfaceRegistry.shared.markShown(surfaceID)
94
+ }
95
+ }
96
+
97
+ public override func viewWillDisappear(_ animated: Bool) {
98
+ super.viewWillDisappear(animated)
99
+
100
+ isDisappearing = true
101
+ }
102
+
59
103
  deinit {
60
104
  NotificationCenter.default.removeObserver(self)
105
+
106
+ if let surfaceID {
107
+ BrownfieldSurfaceRegistry.shared.unregister(surfaceID)
108
+ }
61
109
  }
62
110
 
63
111
  @objc private func togglePopGestureRecognizer(_ notification: Notification) {
@@ -73,11 +121,82 @@ internal import EXUpdates
73
121
  guard let userInfo = notification.userInfo,
74
122
  let animated = userInfo["animated"] as? Bool else { return }
75
123
 
124
+ // `.popToNative` is public API, so a host may post it from any thread.
125
+ // Everything below reads UIKit state — including the registry's visibility
126
+ // check — so hop to main first.
76
127
  DispatchQueue.main.async { [weak self] in
77
- self?.navigationController?.popViewController(animated: animated)
128
+ guard let self else { return }
129
+
130
+ // The notification is app-wide, so every live surface receives it. Only
131
+ // the topmost visible one may act, otherwise surfaces buried under other
132
+ // screens tear down the whole navigation stack.
133
+ // https://github.com/callstack/react-native-brownfield/issues/354
134
+ let target = BrownfieldSurfaceRegistry.shared.popTarget()
135
+
136
+ guard let surfaceID = self.surfaceID, target == surfaceID else {
137
+ if target == nil {
138
+ NSLog("[ReactBrownfield] popToNative(): no React Native surface is on screen; ignoring.")
139
+ }
140
+ return
141
+ }
142
+
143
+ guard self.isHostedBySwiftUI else {
144
+ self.popFromNativeNavigationStack(animated: animated)
145
+ return
146
+ }
147
+
148
+ // SwiftUI owns its navigation state and reverts an imperative pop, so the
149
+ // SwiftUI host dismisses instead. It cannot always succeed though — a
150
+ // `ReactNativeView` inside a `UIHostingController` pushed onto a UIKit
151
+ // navigation stack has nothing for `dismiss()` to act on. Give the host a
152
+ // moment, then fall back, so `popToNative()` is never silently inert.
153
+ //
154
+ // `isDisappearing` — not the delay — is what makes this safe: a dismiss
155
+ // that is merely slow has already begun its transition by the time this
156
+ // runs, so a late timer stands down instead of popping a second entry.
157
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
158
+ guard let self,
159
+ !self.isDisappearing,
160
+ self.viewIfLoaded?.window != nil,
161
+ // Re-established: the entitlement was resolved before the wait.
162
+ self.isPopTarget else { return }
163
+
164
+ self.popFromNativeNavigationStack(animated: animated)
165
+ }
78
166
  }
79
167
  }
80
168
 
169
+ /// Pops this surface off the host's `UINavigationController`.
170
+ ///
171
+ /// Deliberately does not fall back to `dismiss()` when there is no navigation
172
+ /// stack: `presentingViewController` is inherited, so an inline surface hosted
173
+ /// inside a presented native screen would tear down that whole screen — the
174
+ /// same over-dismissal this fix exists to prevent.
175
+ private func popFromNativeNavigationStack(animated: Bool) {
176
+ guard let navigationController else { return }
177
+
178
+ // This controller is usually a child of a host controller (SwiftUI wraps it
179
+ // in one), so find the stack entry containing it rather than assuming it is
180
+ // itself on the stack — and pop to the entry below that, so a screen pushed
181
+ // while we were waiting is not the one that gets popped.
182
+ let stack = navigationController.viewControllers
183
+ guard let index = stack.firstIndex(where: { $0 === self || self.isDescendant(of: $0) }),
184
+ index > 0 else { return }
185
+
186
+ navigationController.popToViewController(stack[index - 1], animated: animated)
187
+ }
188
+
189
+ private func isDescendant(of controller: UIViewController) -> Bool {
190
+ var ancestor = parent
191
+
192
+ while let current = ancestor {
193
+ if current === controller { return true }
194
+ ancestor = current.parent
195
+ }
196
+
197
+ return false
198
+ }
199
+
81
200
  private func renderReactNativeView() {
82
201
  guard !moduleName.isEmpty else { return }
83
202
 
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,"__esModule",{value:true});exports.brownfieldGradlePluginDependency=exports.BROWNFIELD_PLUGIN_VERSION=void 0;var BROWNFIELD_PLUGIN_VERSION=exports.BROWNFIELD_PLUGIN_VERSION='2.0.0-alpha08';var brownfieldGradlePluginDependency=exports.brownfieldGradlePluginDependency=`classpath("com.callstack.react:brownfield-gradle-plugin:${BROWNFIELD_PLUGIN_VERSION}")`;
1
+ Object.defineProperty(exports,"__esModule",{value:true});exports.brownfieldGradlePluginDependency=exports.BROWNFIELD_PLUGIN_VERSION=void 0;var BROWNFIELD_PLUGIN_VERSION=exports.BROWNFIELD_PLUGIN_VERSION='2.0.0-alpha09';var brownfieldGradlePluginDependency=exports.brownfieldGradlePluginDependency=`classpath("com.callstack.react:brownfield-gradle-plugin:${BROWNFIELD_PLUGIN_VERSION}")`;
2
2
  //# sourceMappingURL=constants.js.map
@@ -7,10 +7,15 @@ import com.callstack.reactnativebrownfield.ReactNativeBrownfield
7
7
  import com.facebook.react.PackageList
8
8
  import expo.modules.ApplicationLifecycleDispatcher
9
9
  import expo.modules.ExpoReactHostFactory
10
+ import java.util.concurrent.atomic.AtomicBoolean
10
11
 
11
12
  object ReactNativeHostManager {
13
+ private val applicationCreateDispatched = AtomicBoolean()
14
+
12
15
  fun initialize(application: Application, onJSBundleLoaded: OnJSBundleLoaded? = null) {
13
- ApplicationLifecycleDispatcher.onApplicationCreate(application)
16
+ if (applicationCreateDispatched.compareAndSet(false, true)) {
17
+ ApplicationLifecycleDispatcher.onApplicationCreate(application)
18
+ }
14
19
 
15
20
  ReactNativeBrownfield.initialize(application, onJSBundleLoaded) {
16
21
  ExpoReactHostFactory.getDefaultReactHost(
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,"__esModule",{value:true});exports.brownfieldGradlePluginDependency=exports.BROWNFIELD_PLUGIN_VERSION=void 0;var BROWNFIELD_PLUGIN_VERSION=exports.BROWNFIELD_PLUGIN_VERSION='2.0.0-alpha08';var brownfieldGradlePluginDependency=exports.brownfieldGradlePluginDependency=`classpath("com.callstack.react:brownfield-gradle-plugin:${BROWNFIELD_PLUGIN_VERSION}")`;
1
+ Object.defineProperty(exports,"__esModule",{value:true});exports.brownfieldGradlePluginDependency=exports.BROWNFIELD_PLUGIN_VERSION=void 0;var BROWNFIELD_PLUGIN_VERSION=exports.BROWNFIELD_PLUGIN_VERSION='2.0.0-alpha09';var brownfieldGradlePluginDependency=exports.brownfieldGradlePluginDependency=`classpath("com.callstack.react:brownfield-gradle-plugin:${BROWNFIELD_PLUGIN_VERSION}")`;
2
2
  //# sourceMappingURL=constants.js.map
@@ -7,10 +7,15 @@ import com.callstack.reactnativebrownfield.ReactNativeBrownfield
7
7
  import com.facebook.react.PackageList
8
8
  import expo.modules.ApplicationLifecycleDispatcher
9
9
  import expo.modules.ExpoReactHostFactory
10
+ import java.util.concurrent.atomic.AtomicBoolean
10
11
 
11
12
  object ReactNativeHostManager {
13
+ private val applicationCreateDispatched = AtomicBoolean()
14
+
12
15
  fun initialize(application: Application, onJSBundleLoaded: OnJSBundleLoaded? = null) {
13
- ApplicationLifecycleDispatcher.onApplicationCreate(application)
16
+ if (applicationCreateDispatched.compareAndSet(false, true)) {
17
+ ApplicationLifecycleDispatcher.onApplicationCreate(application)
18
+ }
14
19
 
15
20
  ReactNativeBrownfield.initialize(application, onJSBundleLoaded) {
16
21
  ExpoReactHostFactory.getDefaultReactHost(
@@ -1,3 +1,3 @@
1
- export declare const BROWNFIELD_PLUGIN_VERSION = "2.0.0-alpha08";
2
- export declare const brownfieldGradlePluginDependency = "classpath(\"com.callstack.react:brownfield-gradle-plugin:2.0.0-alpha08\")";
1
+ export declare const BROWNFIELD_PLUGIN_VERSION = "2.0.0-alpha09";
2
+ export declare const brownfieldGradlePluginDependency = "classpath(\"com.callstack.react:brownfield-gradle-plugin:2.0.0-alpha09\")";
3
3
  //# sourceMappingURL=constants.d.ts.map
@@ -1,3 +1,3 @@
1
- export declare const BROWNFIELD_PLUGIN_VERSION = "2.0.0-alpha08";
2
- export declare const brownfieldGradlePluginDependency = "classpath(\"com.callstack.react:brownfield-gradle-plugin:2.0.0-alpha08\")";
1
+ export declare const BROWNFIELD_PLUGIN_VERSION = "2.0.0-alpha09";
2
+ export declare const brownfieldGradlePluginDependency = "classpath(\"com.callstack.react:brownfield-gradle-plugin:2.0.0-alpha09\")";
3
3
  //# sourceMappingURL=constants.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@callstack/react-native-brownfield",
3
- "version": "5.0.2",
3
+ "version": "5.1.1",
4
4
  "license": "MIT",
5
5
  "author": "Michal Chudziak <mike.chudziak@callstack.com>",
6
6
  "bin": {
@@ -89,7 +89,7 @@
89
89
  "@expo/config-plugins": ">=54 <100"
90
90
  },
91
91
  "dependencies": {
92
- "@callstack/brownfield-cli": "^5.0.2"
92
+ "@callstack/brownfield-cli": "^5.1.1"
93
93
  },
94
94
  "devDependencies": {
95
95
  "@babel/core": "^7.29.6",
@@ -1,2 +1,2 @@
1
- export const BROWNFIELD_PLUGIN_VERSION = '2.0.0-alpha08';
1
+ export const BROWNFIELD_PLUGIN_VERSION = '2.0.0-alpha09';
2
2
  export const brownfieldGradlePluginDependency = `classpath("com.callstack.react:brownfield-gradle-plugin:${BROWNFIELD_PLUGIN_VERSION}")`;
@@ -7,10 +7,15 @@ import com.callstack.reactnativebrownfield.ReactNativeBrownfield
7
7
  import com.facebook.react.PackageList
8
8
  import expo.modules.ApplicationLifecycleDispatcher
9
9
  import expo.modules.ExpoReactHostFactory
10
+ import java.util.concurrent.atomic.AtomicBoolean
10
11
 
11
12
  object ReactNativeHostManager {
13
+ private val applicationCreateDispatched = AtomicBoolean()
14
+
12
15
  fun initialize(application: Application, onJSBundleLoaded: OnJSBundleLoaded? = null) {
13
- ApplicationLifecycleDispatcher.onApplicationCreate(application)
16
+ if (applicationCreateDispatched.compareAndSet(false, true)) {
17
+ ApplicationLifecycleDispatcher.onApplicationCreate(application)
18
+ }
14
19
 
15
20
  ReactNativeBrownfield.initialize(application, onJSBundleLoaded) {
16
21
  ExpoReactHostFactory.getDefaultReactHost(