@@ -6,15 +6,115 @@ _Note: JavaScriptCore has been extracted from core react-native as a part of [Le
66
77## Installation
88
9- // TODO
9+ > [ !IMPORTANT]
10+ > This library only supports React Native 0.79 and above with new architecture enabled.
11+
12+ ``` sh
13+ yarn add @react-native-community/javascriptcore
14+ ```
15+
16+ ### iOS
17+
18+ Install pods:
19+
20+ ``` sh
21+ cd ios && USE_THIRD_PARTY_JSC=1 USE_HERMES=0 bundle exec pod install
22+ ```
23+ > [ !NOTE]
24+ > Note: ` USE_THIRD_PARTY_JSC=1 ` is required to use JavaScriptCore from this package until JavaScriptCore is removed from core react-native.
25+
26+ ### Android
27+
28+ Add the following to your ` android/gradle.properties ` :
29+
30+ ``` properties
31+ # Disable Hermes
32+ hermesEnabled =false
33+
34+ # Enable third-party JSC
35+ useThirdPartyJSC =true
36+ ```
1037
1138## Usage
1239
13- // TODO
40+ ### iOS
41+
42+ Open AppDelegate.swift and overwrite ` createJSRuntimeFactory ` method:
43+
44+ ``` swift
45+ import React
46+ import React_RCTAppDelegate
47+ import ReactAppDependencyProvider
48+ import UIKit
49+ import RCTRuntime
50+
51+ // AppDelegate code
52+
53+ class ReactNativeDelegate : RCTDefaultReactNativeFactoryDelegate {
54+ override func sourceURL (for bridge : RCTBridge) -> URL? {
55+ self .bundleURL ()
56+ }
57+
58+ override func bundleURL () -> URL? {
59+ #if DEBUG
60+ RCTBundleURLProvider.sharedSettings ().jsBundleURL (forBundleRoot : " index" )
61+ #else
62+ Bundle.main .url (forResource : " main" , withExtension : " jsbundle" )
63+ #endif
64+ }
65+
66+ override func createJSRuntimeFactory () -> JSRuntimeFactory {
67+ jsrt_create_jsc_factory () // Use JavaScriptCore runtime
68+ }
69+ }
70+ ```
71+
72+ ### Android
73+
74+ Open ` MainApplication.java ` and overwrite ` getJavaScriptExecutorFactory ` method:
75+
76+ ``` java
77+ import io.github.reactnativecommunity.javascriptcore.JSCExecutorFactory
78+ import io.github.reactnativecommunity.javascriptcore.JSCRuntimeFactory
79+
80+ class MainApplication : Application(), ReactApplication {
81+
82+ override val reactNativeHost: ReactNativeHost =
83+ object : DefaultReactNativeHost (this ) {
84+ override fun getPackages(): List<ReactPackage > =
85+ PackageList(this ). packages. apply {
86+ // Packages that cannot be autolinked yet can be added manually here, for example:
87+ // add(MyReactNativePackage())
88+ }
89+
90+ override fun getJSMainModuleName(): String = " index"
91+
92+ override fun getUseDeveloperSupport(): Boolean = BuildConfig . DEBUG
93+
94+ override val isNewArchEnabled: Boolean = BuildConfig . IS_NEW_ARCHITECTURE_ENABLED
95+ override val isHermesEnabled: Boolean = BuildConfig . IS_HERMES_ENABLED
96+
97+ override fun getJavaScriptExecutorFactory(): JavaScriptExecutorFactory =
98+ JSCExecutorFactory(packageName, AndroidInfoHelpers . getFriendlyDeviceName())
99+ }
100+
101+ override val reactHost: ReactHost
102+ get () = getDefaultReactHost (applicationContext , reactNativeHost , JSCRuntimeFactory ())
103+
104+ override fun onCreate () {
105+ super . onCreate()
106+ SoLoader . init(this , OpenSourceMergedSoMapping )
107+ if (BuildConfig . IS_NEW_ARCHITECTURE_ENABLED ) {
108+ // If you opted-in for the New Architecture, we load the native entry point for this app.
109+ load()
110+ }
111+ }
112+ }
113+ ```
14114
15115## Maintainers
16116
17- // TODO
117+ This library is maintained by [ Callstack ] ( https://callstack.com/ ) a Total Software Engineering Consultancy that transforms organizations and teams through transformative apps.
18118
19119## License
20120
0 commit comments