@rnx-kit/react-native-host 0.1.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/README.md +97 -0
- package/ReactNativeHost.podspec +30 -0
- package/package.json +57 -0
package/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# @rnx-kit/react-native-host
|
|
2
|
+
|
|
3
|
+
[](https://github.com/microsoft/rnx-kit/actions/workflows/build.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/@rnx-kit/react-native-host)
|
|
5
|
+
|
|
6
|
+
`@rnx-kit/react-native-host` simplifies React Native initialization.
|
|
7
|
+
|
|
8
|
+
The aim of this package is to provide a backwards (and forwards) compatible way
|
|
9
|
+
of initializing React Native, regardless of whether you're on New Architecture
|
|
10
|
+
or have gone fully bridgeless.`@rnx-kit/react-native-host` will also a provide a
|
|
11
|
+
simple way to enable split bundles and service delivery.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
yarn add @rnx-kit/react-native-host --dev
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
or if you're using npm
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
npm add --save-dev @rnx-kit/react-native-host
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
### iOS/macOS
|
|
28
|
+
|
|
29
|
+
[Autolinking](https://github.com/react-native-community/cli/blob/10.x/docs/autolinking.md)
|
|
30
|
+
should make this module available to your app project.
|
|
31
|
+
|
|
32
|
+
- Replace instances of `RCTBridgeDelegate` with `RNXHostConfig`. The latter is a
|
|
33
|
+
superset and is backwards compatible.
|
|
34
|
+
- Replace instantiation of `RCTBridge` with `ReactNativeHost`. `ReactNativeHost`
|
|
35
|
+
will instantiate the appropriate modules required for your setup. It will also
|
|
36
|
+
handle New Architecture configuration as necessary.
|
|
37
|
+
- Instead of instantiating `RCTRootView` directly, use
|
|
38
|
+
`-[ReactNativeHost viewWithModuleName:initialProperties:]` to create your root
|
|
39
|
+
views.
|
|
40
|
+
|
|
41
|
+
For example, if you previously had something like this:
|
|
42
|
+
|
|
43
|
+
```objc
|
|
44
|
+
// AppDelegate.h
|
|
45
|
+
@import React;
|
|
46
|
+
@import UIKit;
|
|
47
|
+
|
|
48
|
+
@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate>
|
|
49
|
+
@end
|
|
50
|
+
|
|
51
|
+
// AppDelegate.m
|
|
52
|
+
@implementation AppDelegate
|
|
53
|
+
|
|
54
|
+
- (BOOL)application:(UIApplication *)application
|
|
55
|
+
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
|
56
|
+
{
|
|
57
|
+
...
|
|
58
|
+
|
|
59
|
+
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self
|
|
60
|
+
launchOptions:launchOptions];
|
|
61
|
+
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
|
|
62
|
+
moduleName:moduleName
|
|
63
|
+
initialProperties:initialProperties];
|
|
64
|
+
|
|
65
|
+
...
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@end
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
You should instead have:
|
|
72
|
+
|
|
73
|
+
```objc
|
|
74
|
+
// AppDelegate.m
|
|
75
|
+
@import ReactNativeHost;
|
|
76
|
+
@import UIKit;
|
|
77
|
+
|
|
78
|
+
@interface AppDelegate : UIResponder <UIApplicationDelegate, RNXHostConfig>
|
|
79
|
+
@end
|
|
80
|
+
|
|
81
|
+
// AppDelegate.m
|
|
82
|
+
@implementation AppDelegate
|
|
83
|
+
|
|
84
|
+
- (BOOL)application:(UIApplication *)application
|
|
85
|
+
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
|
86
|
+
{
|
|
87
|
+
...
|
|
88
|
+
|
|
89
|
+
ReactNativeHost *host = [[ReactNativeHost alloc] initWithConfig:self];
|
|
90
|
+
UIView *rootView = [host viewWithModuleName:moduleName
|
|
91
|
+
initialProperties:initialProperties];
|
|
92
|
+
|
|
93
|
+
...
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@end
|
|
97
|
+
```
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
version = package['version']
|
|
5
|
+
repository = package['repository']
|
|
6
|
+
|
|
7
|
+
Pod::Spec.new do |s|
|
|
8
|
+
s.name = 'ReactNativeHost'
|
|
9
|
+
s.version = version
|
|
10
|
+
s.author = { package['author']['name'] => package['author']['email'] }
|
|
11
|
+
s.license = package['license']
|
|
12
|
+
s.homepage = package['homepage']
|
|
13
|
+
s.source = { :git => repository['url'], :tag => "#{package['name']}@#{version}" }
|
|
14
|
+
s.summary = package['description']
|
|
15
|
+
|
|
16
|
+
s.ios.deployment_target = '13.0'
|
|
17
|
+
s.osx.deployment_target = '10.15'
|
|
18
|
+
|
|
19
|
+
s.dependency 'React-Core'
|
|
20
|
+
|
|
21
|
+
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
|
|
22
|
+
|
|
23
|
+
# Include both package and repository relative paths to allow the podspec to
|
|
24
|
+
# be consumed from both a local path, and as a podspec outside a spec
|
|
25
|
+
# repository.
|
|
26
|
+
s.source_files = 'cocoa/*.{h,m,mm}', # :path
|
|
27
|
+
"#{repository['directory']}/cocoa/*.{h,m,mm}" # :podspec
|
|
28
|
+
s.public_header_files = 'cocoa/*.h', # :path
|
|
29
|
+
"#{repository['directory']}/cocoa/*.h" # :podspec
|
|
30
|
+
end
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rnx-kit/react-native-host",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Simplify React Native initialization",
|
|
5
|
+
"homepage": "https://github.com/microsoft/rnx-kit/tree/main/packages/react-native-host#readme",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "Microsoft Open Source",
|
|
9
|
+
"email": "microsoftopensource@users.noreply.github.com"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"ReactNativeHost.podspec",
|
|
13
|
+
"android/",
|
|
14
|
+
"mac/"
|
|
15
|
+
],
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/microsoft/rnx-kit",
|
|
19
|
+
"directory": "packages/react-native-host"
|
|
20
|
+
},
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=14.15"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"format:c": "clang-format -i $(git ls-files '*.c' '*.cpp' '*.h' '*.m' '*.mm')",
|
|
26
|
+
"lint:kt": "ktlint --relative --verbose 'android/src/**/*.kt'"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"react": "17.0.1 || 17.0.2 || 18.0.0 || 18.1.0 || 18.2.0",
|
|
30
|
+
"react-native": "^0.64.2 || ^0.65.0 || ^0.66.0 || ^0.67.0 || ^0.68.0 || ^0.69.0 || ^0.70.0 || ^0.71.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@babel/core": "^7.12.9",
|
|
34
|
+
"@babel/preset-env": "^7.1.6",
|
|
35
|
+
"react": "17.0.2",
|
|
36
|
+
"react-native": "^0.68.0"
|
|
37
|
+
},
|
|
38
|
+
"eslintConfig": {
|
|
39
|
+
"extends": "@rnx-kit/eslint-config"
|
|
40
|
+
},
|
|
41
|
+
"rnx-kit": {
|
|
42
|
+
"alignDeps": {
|
|
43
|
+
"requirements": {
|
|
44
|
+
"development": [
|
|
45
|
+
"react-native@0.68"
|
|
46
|
+
],
|
|
47
|
+
"production": [
|
|
48
|
+
"react-native@>=0.64 <1.0"
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
"capabilities": [
|
|
52
|
+
"core-android",
|
|
53
|
+
"core-ios"
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|