Skip to content

Commit

Permalink
working
Browse files Browse the repository at this point in the history
  • Loading branch information
karol-bisztyga committed Mar 2, 2021
1 parent 6dba77d commit dfbdb2a
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 14 deletions.
3 changes: 3 additions & 0 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import React from 'react';
import { StyleSheet, Text, View } from 'react-native';

export default function App() {
const test = global.mytest ?? 'not working :( :( :(';
console.log('here', test)
return (
<View style={styles.container}>
<Text>Open up App.js to start working on your app!</Text>
<Text>HERE: { test }</Text>
<StatusBar style="auto" />
</View>
);
Expand Down
26 changes: 19 additions & 7 deletions android/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ set(PACKAGE_NAME "my_jni_module")
#"fbjni_DIR" to a directory containing one of the above files. If "fbjni"
#provides a separate development package or SDK, be sure it has been
#installed.
#find_package(fbjni REQUIRED CONFIG)
find_package(fbjni REQUIRED CONFIG)

include_directories(
../../node_modules/react-native/React
../../node_modules/react-native/React/Base
../../node_modules/react-native/ReactCommon
../../node_modules/react-native/ReactCommon/jsi
./src/cpp/
)

add_library( # Sets the name of the library.
${PACKAGE_NAME}
Expand All @@ -33,17 +41,21 @@ add_library( # Sets the name of the library.
SHARED

# Provides a relative path to your source file(s).
../../node_modules/react-native/ReactCommon/jsi/jsi/jsi.cpp
./src/cpp/sample.cpp
)

target_link_libraries(${PACKAGE_NAME}
# fbjni::fbjni
fbjni::fbjni
android
log
)

#target_link_libraries(my_jni_module
# android
# log
# fbjni::fbjni
#)

add_library(
turbomodulejsijni
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
./src/cpp/empty.cpp
)
18 changes: 14 additions & 4 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,15 @@ repositories {
}

android {
buildFeatures {
prefab true
}
// this also causes
// Duplicate class com.facebook.jni.xxx found in modules jetified-fbjni-0.1.0-runtime (com.facebook.fbjni:fbjni:0.1.0) and jetified-fbjni-java-only-0.0.3 (com.facebook.fbjni:fbjni-java-only:0.0.3)
// where xxx are 17 different classes
dependencies {
implementation 'com.facebook.fbjni:fbjni:0.1.0'
}

// dependencies {
// implementation 'com.facebook.fbjni:fbjni:0.1.0'
// }
compileSdkVersion rootProject.ext.compileSdkVersion

compileOptions {
Expand Down Expand Up @@ -184,6 +186,14 @@ android {
}
}

defaultConfig {
externalNativeBuild {
cmake {
arguments "-DANDROID_STL=c++_shared"
}
}
}

externalNativeBuild {
cmake {
path "CMakeLists.txt"
Expand Down
Empty file added android/app/src/cpp/empty.cpp
Empty file.
26 changes: 26 additions & 0 deletions android/app/src/cpp/sample.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <jsi/jsi.h>
#include <jni.h>
#include <fbjni/fbjni.h>
// #include "DraftNativeModule.h"

using namespace facebook;
/**/
extern "C"
{
JNIEXPORT void JNICALL
Java_com_rnfbjni_MainActivity_install(JNIEnv *env, jobject thiz, jlong runtimePtr)
{
jsi::Runtime *runtime = (jsi::Runtime *)runtimePtr;
// std::shared_ptr<comm::DraftNativeModule> nativeModule = std::make_shared<comm::DraftNativeModule>(jsCallInvoker);
//
// runtime->global().setProperty(
// runtime,
// jsi::PropNameID::forAscii(*runtime, "commModule"),
// jsi::Object::createFromHostObject(runtime, nativeModule));
runtime->global().setProperty(
*runtime,
jsi::PropNameID::forAscii(*runtime, "mytest"),
jsi::Value(*runtime, 777333));
}
}
/**/
29 changes: 28 additions & 1 deletion android/app/src/main/java/com/rnfbjni/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@
import expo.modules.splashscreen.singletons.SplashScreen;
import expo.modules.splashscreen.SplashScreenImageResizeMode;

public class MainActivity extends ReactActivity {
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.turbomodule.core.CallInvokerHolderImpl;
import com.facebook.react.bridge.ReactContext;

public class MainActivity extends ReactActivity implements ReactInstanceManager.ReactInstanceEventListener {

static {
System.loadLibrary("my_jni_module");
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -19,7 +28,17 @@ protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this, SplashScreenImageResizeMode.CONTAIN, ReactRootView.class, false);
}

@Override
public void onResume() {
super.onResume();
getReactInstanceManager().addReactInstanceEventListener(this);
}

@Override
public void onPause() {
super.onPause();
getReactInstanceManager().removeReactInstanceEventListener(this);
}
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
Expand All @@ -38,4 +57,12 @@ protected ReactRootView createRootView() {
}
};
}

@Override
public void onReactContextInitialized(ReactContext context) {
CallInvokerHolderImpl holder = (CallInvokerHolderImpl)context.getCatalystInstance().getJSCallInvokerHolder();
install(context.getJavaScriptContextHolder().get());
}

public native void install(long jsContextNativePointer);
}
4 changes: 2 additions & 2 deletions android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Mar 01 17:15:43 CET 2021
#Tue Mar 02 12:48:36 CET 2021
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip

0 comments on commit dfbdb2a

Please sign in to comment.