@callstack/react-native-brownfield 3.5.0 → 3.6.0

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @callstack/react-native-brownfield
2
2
 
3
+ ## 3.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#301](https://github.com/callstack/react-native-brownfield/pull/301) [`c8816e9`](https://github.com/callstack/react-native-brownfield/commit/c8816e9418a472e0e8a388db105121381243e496) Thanks [@marcinszalski-callstack](https://github.com/marcinszalski-callstack)! - feat: add method to deallocate reactNativeFactory instance
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [[`5ac357b`](https://github.com/callstack/react-native-brownfield/commit/5ac357bb8802ecf3562d92be191f6681ae94a055)]:
12
+ - @callstack/brownfield-cli@3.6.0
13
+
14
+ ## 3.5.1
15
+
16
+ ### Patch Changes
17
+
18
+ - [#288](https://github.com/callstack/react-native-brownfield/pull/288) [`096cc3b`](https://github.com/callstack/react-native-brownfield/commit/096cc3bbf580d9bf22374fa8b67021d2f29e211c) Thanks [@marcinszalski-callstack](https://github.com/marcinszalski-callstack)! - fix: restore back-button propagation from native to RN
19
+
20
+ - Updated dependencies []:
21
+ - @callstack/brownfield-cli@3.5.1
22
+
3
23
  ## 3.5.0
4
24
 
5
25
  ### Minor Changes
@@ -167,7 +167,7 @@ class ReactNativeBrownfield private constructor(val reactHost: ReactHost) {
167
167
  val resolvedDelegate =
168
168
  reactDelegate ?: ReactDelegateWrapper(activity, reactHost, moduleName, launchOptions)
169
169
 
170
- val mBackPressedCallback: OnBackPressedCallback = object : OnBackPressedCallback(true) {
170
+ val backPressedCallback: OnBackPressedCallback = object : OnBackPressedCallback(true) {
171
171
  override fun handleOnBackPressed() {
172
172
  // invoked for JS stack back navigation
173
173
  resolvedDelegate.onBackPressed()
@@ -175,11 +175,12 @@ class ReactNativeBrownfield private constructor(val reactHost: ReactHost) {
175
175
  }
176
176
 
177
177
  // Register back press callback
178
- activity?.onBackPressedDispatcher?.addCallback(mBackPressedCallback)
178
+ activity?.onBackPressedDispatcher?.addCallback(backPressedCallback)
179
179
  // invoked on the last RN screen exit
180
180
  resolvedDelegate.setHardwareBackHandler {
181
- mBackPressedCallback.isEnabled = false
181
+ backPressedCallback.isEnabled = false
182
182
  activity?.onBackPressedDispatcher?.onBackPressed()
183
+ backPressedCallback.isEnabled = true
183
184
  }
184
185
 
185
186
  /**
@@ -28,16 +28,14 @@ final class ExpoHostRuntime {
28
28
  public func startReactNative(onBundleLoaded: (() -> Void)?) {
29
29
  guard reactNativeFactory == nil else { return }
30
30
 
31
- let factory = ExpoReactNativeFactory(delegate: delegate)
32
- delegate.dependencyProvider = RCTAppDependencyProvider()
33
-
34
- reactNativeFactory = factory
35
-
36
31
  let appDelegate = ExpoAppDelegate()
32
+ delegate.dependencyProvider = RCTAppDependencyProvider()
33
+ reactNativeFactory = ExpoReactNativeFactory(delegate: delegate)
37
34
  // below: https://github.com/expo/expo/pull/39418/changes/5abd332b55b2ee7daee848284ed5f7fe1639452e
38
35
  // has removed bindReactNativeFactory method from ExpoAppDelegate
39
36
  #if !EXPO_SDK_GTE_55 // this define comes from the Brownfield Expo config plugin
40
- appDelegate.bindReactNativeFactory(factory)
37
+ guard let reactNativeFactory else { return }
38
+ appDelegate.bindReactNativeFactory(reactNativeFactory)
41
39
  #endif
42
40
  expoDelegate = appDelegate
43
41
 
@@ -46,6 +44,19 @@ final class ExpoHostRuntime {
46
44
  }
47
45
  }
48
46
 
47
+ /**
48
+ * Stops React Native and releases the underlying factory instance.
49
+ */
50
+ public func stopReactNative() {
51
+ if !Thread.isMainThread {
52
+ DispatchQueue.main.async { [weak self] in self?.stopReactNative() }
53
+ return
54
+ }
55
+
56
+ reactNativeFactory = nil
57
+ expoDelegate = nil
58
+ }
59
+
49
60
  /**
50
61
  * Path to JavaScript root.
51
62
  * Default value: ".expo/.virtual-metro-entry"
@@ -125,19 +136,19 @@ final class ExpoHostRuntime {
125
136
  // below: https://github.com/expo/expo/commit/2013760c46cde1404872d181a691da72fbf207a4
126
137
  // has moved the recreateRootView method to ExpoReactNativeFactory
127
138
  #if EXPO_SDK_GTE_55 // this define comes from the Brownfield Expo config plugin
128
- return (reactNativeFactory as? ExpoReactNativeFactory)?.recreateRootView(
129
- withBundleURL: bundleURL,
130
- moduleName: moduleName,
131
- initialProps: initialProps,
132
- launchOptions: launchOptions
133
- )
139
+ return (reactNativeFactory as? ExpoReactNativeFactory)?.recreateRootView(
140
+ withBundleURL: bundleURL,
141
+ moduleName: moduleName,
142
+ initialProps: initialProps,
143
+ launchOptions: launchOptions
144
+ )
134
145
  #else
135
- return expoDelegate?.recreateRootView(
136
- withBundleURL: bundleURL,
137
- moduleName: moduleName,
138
- initialProps: initialProps,
139
- launchOptions: launchOptions
140
- )
146
+ return expoDelegate?.recreateRootView(
147
+ withBundleURL: bundleURL,
148
+ moduleName: moduleName,
149
+ initialProps: initialProps,
150
+ launchOptions: launchOptions
151
+ )
141
152
  #endif
142
153
  }
143
154
  }
@@ -82,6 +82,17 @@ internal import Expo
82
82
  #endif
83
83
  }
84
84
 
85
+ /**
86
+ * Stops React Native.
87
+ */
88
+ @objc public func stopReactNative() {
89
+ #if canImport(Expo)
90
+ ExpoHostRuntime.shared.stopReactNative()
91
+ #else
92
+ ReactNativeHostRuntime.shared.stopReactNative()
93
+ #endif
94
+ }
95
+
85
96
  @objc public func view(
86
97
  moduleName: String,
87
98
  initialProps: [AnyHashable: Any]?,
@@ -59,6 +59,7 @@ final class ReactNativeHostRuntime {
59
59
  delegate.bundlePath = bundlePath
60
60
  }
61
61
  }
62
+
62
63
  /**
63
64
  * Bundle instance to lookup the JavaScript bundle.
64
65
  * Default value: Bundle.main
@@ -68,6 +69,7 @@ final class ReactNativeHostRuntime {
68
69
  delegate.bundle = bundle
69
70
  }
70
71
  }
72
+
71
73
  /**
72
74
  * Dynamic bundle URL provider called on every bundle load.
73
75
  * When set, this overrides the default bundleURL() behavior in the delegate.
@@ -79,17 +81,12 @@ final class ReactNativeHostRuntime {
79
81
  delegate.bundleURLOverride = bundleURLOverride
80
82
  }
81
83
  }
84
+
82
85
  /**
83
86
  * React Native factory instance created when starting React Native.
84
87
  * Default value: nil
85
88
  */
86
89
  private var reactNativeFactory: RCTReactNativeFactory? = nil
87
- /**
88
- * Root view factory used to create React Native views.
89
- */
90
- lazy private var rootViewFactory: RCTRootViewFactory? = {
91
- return reactNativeFactory?.rootViewFactory
92
- }()
93
90
 
94
91
  /**
95
92
  * Starts React Native with default parameters.
@@ -98,12 +95,24 @@ final class ReactNativeHostRuntime {
98
95
  startReactNative(onBundleLoaded: nil)
99
96
  }
100
97
 
98
+ /**
99
+ * Stops React Native and releases the underlying factory instance.
100
+ */
101
+ public func stopReactNative() {
102
+ if !Thread.isMainThread {
103
+ DispatchQueue.main.async { [weak self] in self?.stopReactNative() }
104
+ return
105
+ }
106
+
107
+ reactNativeFactory = nil
108
+ }
109
+
101
110
  public func view(
102
111
  moduleName: String,
103
112
  initialProps: [AnyHashable: Any]?,
104
113
  launchOptions: [AnyHashable: Any]? = nil
105
114
  ) -> UIView? {
106
- rootViewFactory?.view(
115
+ reactNativeFactory?.rootViewFactory.view(
107
116
  withModuleName: moduleName,
108
117
  initialProperties: initialProps,
109
118
  launchOptions: launchOptions
@@ -145,7 +154,7 @@ final class ReactNativeHostRuntime {
145
154
  guard reactNativeFactory == nil else { return }
146
155
 
147
156
  delegate.dependencyProvider = RCTAppDependencyProvider()
148
- self.reactNativeFactory = RCTReactNativeFactory(delegate: delegate)
157
+ reactNativeFactory = RCTReactNativeFactory(delegate: delegate)
149
158
 
150
159
  if let onBundleLoaded {
151
160
  jsBundleLoadObserver.observeOnce(onBundleLoaded: onBundleLoaded)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@callstack/react-native-brownfield",
3
- "version": "3.5.0",
3
+ "version": "3.6.0",
4
4
  "license": "MIT",
5
5
  "author": "Michal Chudziak <mike.chudziak@callstack.com>",
6
6
  "bin": {
@@ -86,7 +86,7 @@
86
86
  "@expo/config-plugins": "^54.0.4"
87
87
  },
88
88
  "dependencies": {
89
- "@callstack/brownfield-cli": "^3.5.0"
89
+ "@callstack/brownfield-cli": "^3.6.0"
90
90
  },
91
91
  "devDependencies": {
92
92
  "@babel/core": "^7.25.2",