@@ -70,6 +70,7 @@ class ReactNativeBrownfieldDelegate: RCTDefaultReactNativeFactoryDelegate {
7070 * Default value: nil
7171 */
7272 private var reactNativeFactory : RCTReactNativeFactory ? = nil
73+ private var hasStartedReactNative = false
7374
7475 private var factory : RCTReactNativeFactory ? {
7576 if let existingFactory = reactNativeFactory {
@@ -125,8 +126,8 @@ class ReactNativeBrownfieldDelegate: RCTDefaultReactNativeFactoryDelegate {
125126 * @param launchOptions Launch options, typically passed from AppDelegate.
126127 */
127128 @objc public func startReactNative( onBundleLoaded: ( ( ) -> Void ) ? , launchOptions: [ AnyHashable : Any ] ? ) {
128- guard reactNativeFactory == nil else { return }
129- _ = factory
129+ guard !hasStartedReactNative else { return }
130+ guard factory != nil else { return }
130131
131132 if let onBundleLoaded {
132133 self . onBundleLoaded = onBundleLoaded
@@ -146,6 +147,8 @@ class ReactNativeBrownfieldDelegate: RCTDefaultReactNativeFactoryDelegate {
146147 )
147148 }
148149 }
150+
151+ hasStartedReactNative = true
149152 }
150153
151154 /**
@@ -157,13 +160,17 @@ class ReactNativeBrownfieldDelegate: RCTDefaultReactNativeFactoryDelegate {
157160 return
158161 }
159162
160- guard let factory = reactNativeFactory else { return }
163+ guard let factory = reactNativeFactory else {
164+ hasStartedReactNative = false
165+ return
166+ }
161167
162168 factory. bridge? . invalidate ( )
163169
164170 NotificationCenter . default. removeObserver ( self )
165171 onBundleLoaded = nil
166172
173+ hasStartedReactNative = false
167174 reactNativeFactory = nil
168175 }
169176
0 commit comments