update android code and readme for react-native 0.18

This commit is contained in:
Andy Prock 2016-02-02 15:39:04 -08:00
parent 4458d6a089
commit 7192886658
4 changed files with 51 additions and 82 deletions

View File

@ -48,23 +48,10 @@ public class MainActivity extends Activity implements DefaultHardwareBackBtnHand
... ...
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected List<ReactPackage> getPackages() {
super.onCreate(savedInstanceState); return Arrays.<ReactPackage>asList(
mReactRootView = new ReactRootView(this); new MainReactPackage(),
new TcpSocketsModule()); // <- add here
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setBundleAssetName("index.android.bundle")
.setJSMainModuleName("index.android")
.addPackage(new MainReactPackage())
.addPackage(new TcpSocketsModule()) // <- add here
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
mReactRootView.startReactApplication(mReactInstanceManager, "YourProject", null);
setContentView(mReactRootView);
} }
} }
``` ```

View File

@ -48,6 +48,6 @@ android {
dependencies { dependencies {
compile fileTree(dir: "libs", include: ["*.jar"]) compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1" compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:0.17.+" compile "com.facebook.react:react-native:0.18.+"
compile project(':react-native-tcp') compile project(':react-native-tcp')
} }

View File

@ -1,81 +1,63 @@
package com.rctsockets; package com.rctsockets;
import android.app.Activity; import com.facebook.react.ReactActivity;
import android.os.Bundle; import com.facebook.react.ReactPackage;
import android.view.KeyEvent;
import com.facebook.react.LifecycleState;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactRootView;
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
import com.facebook.react.shell.MainReactPackage; import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import java.util.Arrays;
import java.util.List;
import com.peel.react.*; // <--- import import com.peel.react.*; // <--- import
public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler { public class MainActivity extends ReactActivity {
/**
private ReactInstanceManager mReactInstanceManager; * Returns the name of the main component registered from JavaScript.
private ReactRootView mReactRootView; * This is used to schedule rendering of the component.
*/
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected String getMainComponentName() {
super.onCreate(savedInstanceState); return "rctsockets";
mReactRootView = new ReactRootView(this);
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setBundleAssetName("index.bundle")
.setJSMainModuleName("index")
.addPackage(new MainReactPackage())
.addPackage(new TcpSocketsModule()) // <- add here
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
mReactRootView.startReactApplication(mReactInstanceManager, "rctsockets", null);
setContentView(mReactRootView);
} }
/**
* Returns whether dev mode should be enabled.
* This enables e.g. the dev menu.
*/
@Override @Override
public boolean onKeyUp(int keyCode, KeyEvent event) { protected boolean getUseDeveloperSupport() {
if (keyCode == KeyEvent.KEYCODE_MENU && mReactInstanceManager != null) { return BuildConfig.DEBUG;
mReactInstanceManager.showDevOptionsDialog();
return true;
}
return super.onKeyUp(keyCode, event);
} }
/**
* Returns the name of the bundle in assets. If this is null, and no file path is specified for
* the bundle, the app will only work with {@code getUseDeveloperSupport} enabled and will
* always try to load the JS bundle from the packager server.
* e.g. "index.android.bundle"
*/
@Override @Override
public void onBackPressed() { protected String getBundleAssetName() {
if (mReactInstanceManager != null) { return "index.bundle";
mReactInstanceManager.onBackPressed(); };
} else {
super.onBackPressed();
}
}
/**
* Returns the name of the main module. Determines the URL used to fetch the JS bundle
* from the packager server. It is only used when dev support is enabled.
* This is the first file to be executed once the {@link ReactInstanceManager} is created.
* e.g. "index.android"
*/
@Override @Override
public void invokeDefaultOnBackPressed() { protected String getJSMainModuleName() {
super.onBackPressed(); return "index";
} }
/**
* A list of packages used by the app. If the app uses additional views
* or modules besides the default ones, add more packages here.
*/
@Override @Override
protected void onPause() { protected List<ReactPackage> getPackages() {
super.onPause(); return Arrays.<ReactPackage>asList(
new MainReactPackage(),
if (mReactInstanceManager != null) { new TcpSocketsModule()); // <- add here
mReactInstanceManager.onPause();
}
}
@Override
protected void onResume() {
super.onResume();
if (mReactInstanceManager != null) {
mReactInstanceManager.onResume(this, this);
}
} }
} }

View File

@ -11,7 +11,7 @@
"dependencies": { "dependencies": {
"buffer": "^3.5.3", "buffer": "^3.5.3",
"events": "^1.1.0", "events": "^1.1.0",
"react-native": "^0.17.0", "react-native": "^0.18.1",
"react-native-tcp": "../../", "react-native-tcp": "../../",
"util": "^0.10.3" "util": "^0.10.3"
}, },