A LiquidCore surface that exposes the React Native (v. 0.56) API. This is a work in progress.
Refer to the React Native documentation for how to get started with React Native. This assumes you are already familiar with it.
Important: you must use only version 0.56.0 of React Native. Create a new project from the command line:
$ react-native init --version=0.56.0 HelloWorld
First, install the command-line utilties:
$ npm install -g liquidcore-cli
Then, initialize your project for use with LiquidCore:
$ liquidcore init --surface=.reactnative.ReactNative HelloWorld
$ cd HelloWorld && npm install
You should now have the basic React Native starter project that is available for use with LiquidCore. To run the development server, simply:
$ npm run server
Your project will remain entirely compatible with React Native. The LiquidCore dev server does not conflict with the Metro server. It uses port 8082 instead of 8081 by default. You can still debug and develop your React Native project according to the documentation without conflict. LiquidCore simply installs a little shim (namely, liquid.js
) and enables a LiquidCore-specific server and bundler.
Create a new app in either Android Studio or XCode as normal. Or if you already have an existing app, you can use that. Refer to the documentation for your IDE on how to set up an app. For the sake of this section, we will assume you have an app named HelloWorld.
Go to your root-level build.grade
file and add the jitpack
dependency:
...
allprojects {
repositories {
jcenter()
maven { url 'https://jitpack.io' }
}
}
...
Then, add the dependencies to your app's build.gradle
:
dependencies {
...
implementation 'com.github.LiquidPlayer:LiquidCore:0.5.1'
implementation 'com.github.LiquidPlayer:ReactNativeSurface:0.56.0006'
/*
* Note: You must also include these React Native dependencies. In future
* releases, hopefully this won't be necessary.
*/
implementation 'javax.inject:javax.inject:1'
implementation 'com.facebook.fbui.textlayoutbuilder:textlayoutbuilder:1.0.0'
implementation 'com.facebook.fresco:fresco:1.9.0'
implementation 'com.facebook.fresco:imagepipeline-okhttp3:1.9.0'
implementation 'com.facebook.soloader:soloader:0.3.0'
implementation 'com.google.code.findbugs:jsr305:3.0.0'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.10.0'
implementation 'com.squareup.okio:okio:1.14.0'
}
-
Install Carthage as described here.
-
Create a Cartfile that includes the following frameworks:
git "git@github.com:LiquidPlayer/LiquidCore.git" ~> 0.5.1 git "git@github.com:LiquidPlayer/ReactNativeSurface.git" ~> 0.56.0006
-
Run
carthage update --cache-builds
. This will fetch dependencies into a Carthage/Checkouts folder, then build each one or download a pre-compiled framework. NOTE:: You may have to do this twice -- it seems to fail the first time and succeed the second. -
On your application targets’ General settings tab, in the “Linked Frameworks and Libraries” section, drag and drop
LiquidCore.framework
andReactNativeSurface.framework
from the Carthage/Build folder on disk. -
On your application targets’ Build Phases settings tab, click the + icon and choose New Run Script Phase. Create a Run Script in which you specify your shell (ex:
/bin/sh
), add the following contents to the script area below the shell:/usr/local/bin/carthage copy-frameworks
Then, add the paths to the frameworks under “Input Files":
$(SRCROOT)/Carthage/Build/iOS/LiquidCore.framework $(SRCROOT)/Carthage/Build/iOS/ReactNativeSurface.framework
And finally, add the paths to the copied frameworks to the “Output Files”:
$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/LiquidCore.framework $(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/ReactNativeSurface.framework
You can either add the view in the interface builder or programmatically. To add the view:
You can insert the view into any layout like so:
<org.liquidplayer.service.LiquidView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/liquidview"
/>
Drag a UIView
onto your storyboard in a ViewController
. Go to the identity inspector on the right and
set its custom class to LCLiquidView
.
import org.liquidplayer.service.LiquidView;
...
LiquidView liquidView = new LiquidView(androidContext);
import LiquidCore
...
let liquidView = LCLiquidView(frame: CGRect.zero)
This is all that is required to get up and running. LiquidView
defaults to using the dev server at port
8082. See the documentation for LiquidView
(Android) and LCLiquidView
(iOS) in the LiquidCore project for options.
This is very hastily thrown together documentation as this project is under active development. So I am adding some disorganized thoughts here.
ReactNativeSurface
is not yet suitable as a general-purpose surface. No (or very little) consideration has been made regarding security. Only use whitelisted domains or better yet, use local resource bundles until there has been more work in the area of security.- On Android, the back button doesn't always work like you want it to. This is a known issue.
- Developer mode doesn't work on either Android or iOS. It doesn't work at all on Android and only somewhat works on iOS. For the moment, use old fashioned React Native to do your debugging until this is resolved.