put our react module in our aar

This commit is contained in:
Ari Lazier 2015-12-10 18:34:09 -08:00
parent 15ad6a12ac
commit eea8658627
8 changed files with 32 additions and 61 deletions

View File

@ -182,6 +182,8 @@ dependencies {
compile 'com.squareup.okhttp:okhttp-ws:2.5.0' compile 'com.squareup.okhttp:okhttp-ws:2.5.0'
compile 'com.squareup.okio:okio:1.6.0' compile 'com.squareup.okio:okio:1.6.0'
compile 'org.webkit:android-jsc:r174650' compile 'org.webkit:android-jsc:r174650'
compile "com.facebook.react:react-native:0.16.+"
testCompile "junit:junit:${JUNIT_VERSION}" testCompile "junit:junit:${JUNIT_VERSION}"
testCompile "org.powermock:powermock-api-mockito:${POWERMOCK_VERSION}" testCompile "org.powermock:powermock-api-mockito:${POWERMOCK_VERSION}"

View File

@ -1,5 +0,0 @@
package com.reacttests;
public class API {
public static native String getDefaultRealmFileDirectory();
}

View File

@ -0,0 +1,23 @@
package com.reacttests;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import java.util.Map;
public class RealmReactAndroid extends ReactContextBaseJavaModule {
public RealmReactAndroid(ReactApplicationContext reactContext) {
super(reactContext);
}
@Override
public String getName() {
return "RealmReactAndroid";
}
public static native String getDefaultRealmFileDirectory();
}

View File

@ -9,7 +9,7 @@
* Method: getDefaultRealmFileDirectory * Method: getDefaultRealmFileDirectory
* Signature: ()Ljava/lang/String; * Signature: ()Ljava/lang/String;
*/ */
JNIEXPORT jstring JNICALL Java_com_reacttests_API_getDefaultRealmFileDirectory JNIEXPORT jstring JNICALL Java_com_reacttests_RealmReactAndroid_getDefaultRealmFileDirectory
(JNIEnv *env, jclass) (JNIEnv *env, jclass)
{ {

View File

@ -12,7 +12,7 @@ extern "C" {
* Method: getDefaultRealmFileDirectory * Method: getDefaultRealmFileDirectory
* Signature: ()Ljava/lang/String; * Signature: ()Ljava/lang/String;
*/ */
JNIEXPORT jstring JNICALL Java_com_reacttests_API_getDefaultRealmFileDirectory JNIEXPORT jstring JNICALL Java_com_reacttests_RealmReactAndroid_getDefaultRealmFileDirectory
(JNIEnv *, jclass); (JNIEnv *, jclass);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -4,7 +4,6 @@ import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import android.view.KeyEvent; import android.view.KeyEvent;
import com.demo.module.JniToastModule;
import com.facebook.react.LifecycleState; import com.facebook.react.LifecycleState;
import com.facebook.react.ReactInstanceManager; import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactPackage; import com.facebook.react.ReactPackage;
@ -20,6 +19,8 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import com.reacttests.RealmReactAndroid;
public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler { public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
@ -93,7 +94,7 @@ public class MainActivity extends Activity implements DefaultHardwareBackBtnHand
ReactApplicationContext reactContext) { ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>(); List<NativeModule> modules = new ArrayList<>();
modules.add(new JniToastModule(reactContext)); modules.add(new RealmReactAndroid(reactContext));
return modules; return modules;
} }

View File

@ -1,50 +0,0 @@
package com.demo.module;
import android.widget.Toast;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.reacttests.API;
import java.util.HashMap;
import java.util.Map;
/**
* Created by Nabil on 30/11/15.
*/
public class JniToastModule extends ReactContextBaseJavaModule {
private static final String DURATION_SHORT_KEY = "SHORT";
private static final String DURATION_LONG_KEY = "LONG";
public JniToastModule(ReactApplicationContext reactContext) {
super(reactContext);
}
@Override
public String getName() {
return "JniToastAndroid";
}
@Override
public Map<String, Object> getConstants() {
final Map<String, Object> constants = new HashMap<>();
constants.put(DURATION_SHORT_KEY, Toast.LENGTH_SHORT);
constants.put(DURATION_LONG_KEY, Toast.LENGTH_LONG);
return constants;
}
@ReactMethod
public void show(String message, int duration) {
StringBuilder sb = new StringBuilder("String from Java: ")
.append(message)
.append("\n")
.append("String from JNI: ")
.append(API.getDefaultRealmFileDirectory());
Toast.makeText(getReactApplicationContext(), sb.toString(), duration).show();
}
static {
System.loadLibrary("realmreact");
}
}

View File

@ -13,11 +13,11 @@ var {
TouchableNativeFeedback, TouchableNativeFeedback,
} = React; } = React;
var JniToastAndroid = require('NativeModules').JniToastAndroid; var RealmReactAndroid = require('NativeModules').RealmReactAndroid;
var Demo = React.createClass({ var Demo = React.createClass({
buttonClicked: function() { buttonClicked: function() {
JniToastAndroid.show("Hello Zepp", JniToastAndroid.LONG); RealmReactAndroid.show("Hello Zepp");
}, },
render: function() { render: function() {
return ( return (