@rnx-kit/react-native-host 0.2.7 → 0.2.8

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/README.md CHANGED
@@ -26,6 +26,10 @@ npm add --save-dev @rnx-kit/react-native-host
26
26
 
27
27
  ### iOS/macOS
28
28
 
29
+ > To see a working example how to use this library for iOS/macOS, please refer
30
+ > to
31
+ > [react-native-test-app](https://github.com/microsoft/react-native-test-app/tree/trunk/ios/ReactTestApp).
32
+
29
33
  [Autolinking](https://github.com/react-native-community/cli/blob/10.x/docs/autolinking.md)
30
34
  should make this module available to your app project.
31
35
 
@@ -71,7 +75,7 @@ For example, if you previously had something like this:
71
75
  You should instead have:
72
76
 
73
77
  ```objc
74
- // AppDelegate.m
78
+ // AppDelegate.h
75
79
  @import ReactNativeHost;
76
80
  @import UIKit;
77
81
 
@@ -95,3 +99,114 @@ You should instead have:
95
99
 
96
100
  @end
97
101
  ```
102
+
103
+ ## API
104
+
105
+ ### ReactNativeHost
106
+
107
+ Instantiates the appropriate modules required for the setup. It handles New
108
+ Architecture if necessary.
109
+
110
+ #### `initWithConfig:`
111
+
112
+ **Swift name:** `init(_:)`
113
+
114
+ Creates an instance of `ReactNativeHost` using the designated initializer.
115
+
116
+ Objective-C:
117
+
118
+ ```objc
119
+ ReactNativeHost *host = [[ReactNativeHost alloc] initWithConfig:self];
120
+ ```
121
+
122
+ Swift:
123
+
124
+ ```swift
125
+ let host = ReactNativeHost(config: self)
126
+ ```
127
+
128
+ #### `shutdown`
129
+
130
+ Shuts down the React Native instance
131
+
132
+ #### `usingModule:block:`
133
+
134
+ **Swift name:** `using(module:block:)`
135
+
136
+ Retrieves or initializes a desired native module. Parameters:
137
+
138
+ - `moduleClass` - class of the native module to initialize or retrieve
139
+ - `block` - block that gets called when the native module is retrieved
140
+
141
+ Objective-C:
142
+
143
+ ```objc
144
+ [host usingModule:[MyNativeModuleClass class] block:^(id<RCTBridgeModule> module) {
145
+ if (![module isKindOfClass:[MyNativeModuleClass class]]) {
146
+ return;
147
+ }
148
+ MyNativeModuleClass *myNativeModule = (MyNativeModuleClass *)module;
149
+ // Use the native module here
150
+ }];
151
+ ```
152
+
153
+ Swift:
154
+
155
+ ```swift
156
+ host.using(module: MyNativeModuleClass.self) {
157
+ guard let myNativeModule = module as? MyNativeModuleClass else {
158
+ return
159
+ }
160
+ // Use the native module here
161
+ }
162
+ ```
163
+
164
+ #### `hostFromRootView:`
165
+
166
+ **Swift name:** `host(from:)`
167
+
168
+ Retrieves the `ReactNativeHost` instance that view belongs to.
169
+
170
+ #### `viewWithModuleName:initialProperties:`
171
+
172
+ **Swift name:** `view(moduleName:initialProperties:)`
173
+
174
+ Creates a React root view with the specified module and initial properties.
175
+ Parameters:
176
+
177
+ - `moduleName` - name of the module to create root view of
178
+ - `initialProperties` - properties passed to the module
179
+
180
+ Objective-C:
181
+
182
+ ```objc
183
+ ReactNativeHost *host = [[ReactNativeHost alloc] initWithConfig:self];
184
+ UIView *rootView = [host viewWithModuleName:moduleName
185
+ initialProperties:initialProperties];
186
+ ```
187
+
188
+ Swift:
189
+
190
+ ```swift
191
+ let view = host.view(
192
+ moduleName: moduleName,
193
+ initialProperties: initialProperties
194
+ )
195
+ ```
196
+
197
+ ### RNXConfig
198
+
199
+ `RNXHostConfig` is a superset of `RCTBridgeDelegate` and it's backwards
200
+ compatible.
201
+
202
+ #### `isDevLoadingViewEnabled`
203
+
204
+ Returns whether the loading view should be visible while loading JavaScript
205
+
206
+ #### `shouldReleaseBridgeWhenBackgrounded`
207
+
208
+ Returns whether the bridge should be released when the app is in the background
209
+
210
+ #### `onFatalError`
211
+
212
+ Handles a fatal error
@@ -24,15 +24,6 @@ NS_ASSUME_NONNULL_BEGIN
24
24
  message:(NSString *)message
25
25
  __attribute__((__swift_name__("log(_:source:filename:line:message:)")));
26
26
 
27
- // Called when the bridge has been instantiated.
28
- - (void)onBridgeInstantiated:(RCTBridge *)bridge;
29
-
30
- // Called when the bridge is about to be shut down.
31
- - (void)onBridgeWillShutDown:(RCTBridge *)bridge;
32
-
33
- // Called when the bridge has been shut down.
34
- - (void)onBridgeDidShutDown;
35
-
36
27
  /// Handles a fatal error.
37
28
  - (void)onFatalError:(NSError *)error;
38
29
 
@@ -17,6 +17,9 @@ NS_ASSUME_NONNULL_BEGIN
17
17
  /// Hosts a React Native instance.
18
18
  @interface ReactNativeHost : NSObject <RCTBridgeDelegate>
19
19
 
20
+ /// Returns the current `RCTBridge` instance.
21
+ ///
22
+ /// - Note: This is not forwards compatible and will be removed in the future.
20
23
  @property (nonatomic, readonly, nullable) RCTBridge *bridge;
21
24
 
22
25
  - (instancetype)init NS_UNAVAILABLE;
@@ -80,9 +80,6 @@
80
80
  _bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:nil];
81
81
  _surfacePresenterBridgeAdapter = RNXInstallSurfacePresenterBridgeAdapter(_bridge);
82
82
  [_hostReleaser setBridge:_bridge];
83
- if ([_config respondsToSelector:@selector(onBridgeInstantiated:)]) {
84
- [_config onBridgeInstantiated:_bridge];
85
- }
86
83
  }
87
84
 
88
85
  return _bridge;
@@ -93,19 +90,11 @@
93
90
 
94
91
  - (void)shutdown
95
92
  {
96
- if ([_config respondsToSelector:@selector(onBridgeWillShutDown:)]) {
97
- [_config onBridgeWillShutDown:_bridge];
98
- }
99
-
100
93
  [_isShuttingDown lock];
101
94
 
102
95
  @try {
103
96
  [_bridge invalidate];
104
97
  _bridge = nil;
105
-
106
- if ([_config respondsToSelector:@selector(onBridgeDidShutDown)]) {
107
- [_config onBridgeDidShutDown];
108
- }
109
98
  } @finally {
110
99
  [_isShuttingDown unlock];
111
100
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rnx-kit/react-native-host",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "description": "Simplify React Native initialization",
5
5
  "homepage": "https://github.com/microsoft/rnx-kit/tree/main/packages/react-native-host#readme",
6
6
  "license": "MIT",
@@ -19,10 +19,15 @@
19
19
  "directory": "packages/react-native-host"
20
20
  },
21
21
  "scripts": {
22
+ "format": "rnx-kit-scripts format",
22
23
  "format:c": "clang-format -i $(git ls-files '*.c' '*.cpp' '*.h' '*.m' '*.mm')",
23
24
  "lint:kt": "ktlint --relative --verbose 'android/src/**/*.kt'"
24
25
  },
25
26
  "peerDependencies": {
26
27
  "react-native": ">=0.64"
28
+ },
29
+ "devDependencies": {
30
+ "@rnx-kit/scripts": "*",
31
+ "prettier": "^3.0.0"
27
32
  }
28
33
  }