forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some temp code to test array buffers
- Loading branch information
Showing
7 changed files
with
126 additions
and
2 deletions.
There are no files selected for viewing
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,16 @@ | ||
cmake_minimum_required(VERSION 3.13.2) | ||
|
||
project(JSITest) | ||
|
||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../../../ReactCommon/jsi/jsi ${CMAKE_CURRENT_BINARY_DIR}/jsi) | ||
include_directories( | ||
${CMAKE_CURRENT_LIST_DIR}/../../../ReactCommon/jsi | ||
) | ||
|
||
add_library(JSITest SHARED src/main/cpp/JSITest.cpp) | ||
|
||
target_link_libraries(JSITest | ||
# link with these libraries: | ||
android | ||
log | ||
jsi) |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include <jni.h> | ||
#include <jsi/jsi.h> | ||
#include <android/log.h> | ||
#include <sstream> | ||
|
||
using namespace facebook; | ||
|
||
namespace | ||
{ | ||
void log(const char *str) | ||
{ | ||
__android_log_print(ANDROID_LOG_VERBOSE, "JSITest", "%s", str); | ||
} | ||
} | ||
|
||
extern "C" JNIEXPORT void JNICALL Java_com_facebook_react_uiapp_JSITestModule_initialize(JNIEnv* env, jclass clazz, jlong jsiPtr) | ||
{ | ||
auto& jsiRuntime = *reinterpret_cast<facebook::jsi::Runtime*>(jsiPtr); | ||
|
||
auto testFunction = jsi::Function::createFromHostFunction(jsiRuntime, jsi::PropNameID::forAscii(jsiRuntime, "testArrayBuffer"), 1, [](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* arguments, size_t count) -> jsi::Value | ||
{ | ||
auto arrayBufferArg = arguments[0].asObject(runtime); | ||
bool isArrayBuffer = arrayBufferArg.isArrayBuffer(runtime); | ||
if (isArrayBuffer) | ||
{ | ||
jsi::ArrayBuffer arrayBuffer = arrayBufferArg.getArrayBuffer(runtime); | ||
uint8_t* arrayBufferData = arrayBuffer.data(runtime); | ||
size_t arrayBufferSize = arrayBuffer.size(runtime); | ||
|
||
for (int i = 0; i < arrayBufferSize; i++) | ||
{ | ||
uint8_t element = arrayBufferData[i]; | ||
std::ostringstream message; | ||
message << "Element at index " << i << ": " << std::to_string(element); | ||
log(message.str().c_str()); | ||
arrayBufferData[i] = element * 2; | ||
} | ||
} | ||
|
||
return nullptr; | ||
}); | ||
jsiRuntime.global().setProperty(jsiRuntime, "testArrayBuffer", std::move(testFunction)); | ||
} |
52 changes: 52 additions & 0 deletions
52
RNTester/android/app/src/main/java/com/facebook/react/uiapp/JSITestPackage.java
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,52 @@ | ||
package com.facebook.react.uiapp; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import com.facebook.react.ReactPackage; | ||
import com.facebook.react.bridge.NativeModule; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
import com.facebook.react.uimanager.ViewManager; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
class JSITestModule extends ReactContextBaseJavaModule { | ||
static { | ||
System.loadLibrary("JSITest"); | ||
} | ||
|
||
private static native void initialize(long jsiPtr); | ||
|
||
public JSITestModule(ReactApplicationContext reactContext) { | ||
super(reactContext); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public String getName() { | ||
return "JSITestModule"; | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
super.initialize(); | ||
|
||
JSITestModule.initialize(this.getReactApplicationContext().getJavaScriptContextHolder().get()); | ||
} | ||
} | ||
|
||
class JSITestPackage implements ReactPackage { | ||
@NonNull | ||
@Override | ||
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) { | ||
return Arrays.<NativeModule>asList(new JSITestModule(reactContext)); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) { | ||
return Collections.emptyList(); | ||
} | ||
} |
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
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