diff --git a/react-native/android/app/build.gradle b/react-native/android/app/build.gradle index 3eef00b9..b2029b1a 100644 --- a/react-native/android/app/build.gradle +++ b/react-native/android/app/build.gradle @@ -183,7 +183,7 @@ dependencies { compile 'com.squareup.okio:okio:1.6.0' compile 'org.webkit:android-jsc:r174650' compile "com.facebook.react:react-native:0.16.+" - + compile 'com.github.KeepSafe:ReLinker:1.1' testCompile "junit:junit:${JUNIT_VERSION}" testCompile "org.powermock:powermock-api-mockito:${POWERMOCK_VERSION}" diff --git a/react-native/android/app/src/main/java/com/reacttests/RealmReactAndroid.java b/react-native/android/app/src/main/java/com/reacttests/RealmReactAndroid.java index 021d5463..6efb903c 100644 --- a/react-native/android/app/src/main/java/com/reacttests/RealmReactAndroid.java +++ b/react-native/android/app/src/main/java/com/reacttests/RealmReactAndroid.java @@ -5,14 +5,18 @@ 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 com.getkeepsafe.relinker.ReLinker; import java.util.Map; +import java.util.HashMap; +import android.widget.Toast; public class RealmReactAndroid extends ReactContextBaseJavaModule { + private static final String DURATION_SHORT_KEY = "SHORT"; + private static final String DURATION_LONG_KEY = "LONG"; public RealmReactAndroid(ReactApplicationContext reactContext) { super(reactContext); - getDefaultRealmFileDirectory(); + ReLinker.loadLibrary(reactContext, "realmreact"); } @Override @@ -20,5 +24,23 @@ public class RealmReactAndroid extends ReactContextBaseJavaModule { return "RealmReactAndroid"; } + @Override + public Map getConstants() { + final Map 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(getDefaultRealmFileDirectory()); + Toast.makeText(getReactApplicationContext(), sb.toString(), duration).show(); + } + public static native String getDefaultRealmFileDirectory(); } diff --git a/react-native/android/build.gradle b/react-native/android/build.gradle index 3938b0a1..64ad6cb2 100644 --- a/react-native/android/build.gradle +++ b/react-native/android/build.gradle @@ -17,5 +17,6 @@ allprojects { repositories { mavenLocal() jcenter() + maven { url "https://jitpack.io" } } } diff --git a/tests/react-test-app/android/app/build.gradle b/tests/react-test-app/android/app/build.gradle index ece1ff75..d53d6f00 100644 --- a/tests/react-test-app/android/app/build.gradle +++ b/tests/react-test-app/android/app/build.gradle @@ -76,4 +76,5 @@ dependencies { compile "com.android.support:appcompat-v7:23.0.1" compile "com.facebook.react:react-native:0.16.+" compile 'com.reacttests:app-debug@aar' + compile 'com.github.KeepSafe:ReLinker:1.1' } diff --git a/tests/react-test-app/android/app/src/main/java/com/demo/MainActivity.java b/tests/react-test-app/android/app/src/main/java/com/demo/MainActivity.java index 0c50fb44..749d9146 100644 --- a/tests/react-test-app/android/app/src/main/java/com/demo/MainActivity.java +++ b/tests/react-test-app/android/app/src/main/java/com/demo/MainActivity.java @@ -23,7 +23,6 @@ import com.reacttests.RealmReactAndroid; public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler { - private ReactInstanceManager mReactInstanceManager; private ReactRootView mReactRootView; diff --git a/tests/react-test-app/android/build.gradle b/tests/react-test-app/android/build.gradle index bf560221..2075df02 100644 --- a/tests/react-test-app/android/build.gradle +++ b/tests/react-test-app/android/build.gradle @@ -22,5 +22,6 @@ allprojects { flatDir{ dirs 'lib' } + maven { url "https://jitpack.io" } } } diff --git a/tests/react-test-app/index.android.js b/tests/react-test-app/index.android.js index 3ada3432..e6f5bee4 100644 --- a/tests/react-test-app/index.android.js +++ b/tests/react-test-app/index.android.js @@ -17,7 +17,7 @@ var RealmReactAndroid = require('NativeModules').RealmReactAndroid; var Demo = React.createClass({ buttonClicked: function() { - RealmReactAndroid.show("Hello Zepp"); + RealmReactAndroid.show("Hello Zepp", RealmReactAndroid.LONG); }, render: function() { return (