-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: set up and created basic jsi::HostObject config with example
- Loading branch information
Maciej Makowski
committed
Jul 9, 2024
1 parent
b2bd4b9
commit 3822ed3
Showing
20 changed files
with
285 additions
and
292 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,25 @@ | ||
cmake_minimum_required(VERSION 3.4.1) | ||
project(AudioContext) | ||
cmake_minimum_required(VERSION 3.9.0) | ||
project(react-native-audio-context) | ||
|
||
set (CMAKE_VERBOSE_MAKEFILE ON) | ||
set (CMAKE_CXX_STANDARD 14) | ||
|
||
add_library(react-native-audio-context SHARED | ||
../cpp/react-native-audio-context.cpp | ||
add_library(react-native-audio-context | ||
SHARED | ||
../cpp/JSIExampleHostObject.cpp | ||
cpp-adapter.cpp | ||
) | ||
|
||
# Specifies a path to native header files. | ||
include_directories( | ||
../cpp | ||
../node_modules/react-native/ReactCommon/jsi | ||
) | ||
|
||
find_package(ReactAndroid REQUIRED CONFIG) | ||
|
||
target_link_libraries( | ||
react-native-audio-context | ||
ReactAndroid::jsi | ||
android | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
#include <jni.h> | ||
#include "react-native-audio-context.h" | ||
#include <jsi/jsi.h> | ||
#include "JSIExampleHostObject.h" | ||
|
||
using namespace facebook; | ||
|
||
void install(jsi::Runtime& runtime) { | ||
auto hostObject = std::make_shared<example::JSIExampleHostObject>(); | ||
auto object = jsi::Object::createFromHostObject(runtime, hostObject); | ||
runtime.global().setProperty(runtime, "__JSIExampleProxy", std::move(object)); | ||
} | ||
|
||
extern "C" | ||
JNIEXPORT jdouble JNICALL | ||
Java_com_audiocontext_AudioContextModule_nativeMultiply(JNIEnv *env, jclass type, jdouble a, jdouble b) { | ||
return audiocontext::multiply(a, b); | ||
JNIEXPORT void JNICALL | ||
Java_com_audiocontext_jsi_JSIExampleModule_00024Companion_nativeInstall(JNIEnv *env, jobject clazz, jlong jsiPtr) { | ||
auto runtime = reinterpret_cast<jsi::Runtime*>(jsiPtr); | ||
if (runtime) { | ||
install(*runtime); | ||
} | ||
} |
34 changes: 0 additions & 34 deletions
34
android/src/main/java/com/audiocontext/AudioContextModule.java
This file was deleted.
Oops, something went wrong.
44 changes: 0 additions & 44 deletions
44
android/src/main/java/com/audiocontext/AudioContextPackage.java
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
android/src/main/java/com/audiocontext/JSIExamplePackage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.audiocontext | ||
|
||
import com.audiocontext.jsi.JSIExampleModule | ||
import com.facebook.react.ReactPackage | ||
import com.facebook.react.bridge.NativeModule | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.uimanager.ViewManager | ||
|
||
class JSIExamplePackage : ReactPackage { | ||
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> { | ||
return listOf<NativeModule>(JSIExampleModule(reactContext)) | ||
} | ||
|
||
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> { | ||
return emptyList() | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
android/src/main/java/com/audiocontext/jsi/JSIExampleModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.audiocontext.jsi | ||
|
||
import android.util.Log | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule | ||
import com.facebook.react.bridge.ReactMethod | ||
import com.facebook.react.module.annotations.ReactModule | ||
|
||
@ReactModule(name = JSIExampleModule.NAME) | ||
class JSIExampleModule(reactContext: ReactApplicationContext?) : | ||
ReactContextBaseJavaModule(reactContext) { | ||
override fun getName(): String { | ||
return NAME | ||
} | ||
|
||
@ReactMethod(isBlockingSynchronousMethod = true) | ||
fun install(): Boolean { | ||
try { | ||
System.loadLibrary("react-native-audio-context") | ||
|
||
val jsContext = reactApplicationContext.javaScriptContextHolder | ||
|
||
nativeInstall(jsContext!!.get()) | ||
return true | ||
} catch (exception: Exception) { | ||
Log.e(NAME, "Failed to install JSI Bindings for react-native-audio-context", exception) | ||
return false | ||
} | ||
} | ||
|
||
companion object { | ||
const val NAME: String = "JSIExample" | ||
|
||
private external fun nativeInstall(jsiPtr: Long) | ||
} | ||
} |
Oops, something went wrong.