Skip to content

Commit 358789e

Browse files
committed
first commit
1 parent e1fd4fd commit 358789e

21 files changed

Lines changed: 30938 additions & 5938 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# react-native-jsi-template
1+
# react-native-raw
22

33
This is an example library that explains how anyone can build jsi modules from scratch in React Native. This code is written as a support project for my [blog](https://blog.notesnook.com/getting-started-react-native-jsi/).
44

@@ -27,7 +27,7 @@ The relevant code is present in `cpp/example.cpp` file.
2727
```
2828

2929
### Platform specific
30-
The relevant code on android is in `android/cpp-adapter.cpp` and `ios/SimpleJsi.mm` on iOS.
30+
The relevant code on android is in `android/cpp-adapter.cpp` and `ios/raw.mm` on iOS.
3131
```ts
3232
getDeviceName():string
3333

@@ -38,7 +38,7 @@ The relevant code on android is in `android/cpp-adapter.cpp` and `ios/SimpleJsi.
3838

3939
## Basic usage example
4040
```tsx
41-
import simpleJsiModule from "react-native-jsi-template";
41+
import simpleJsiModule from "react-native-raw";
4242

4343
simpleJsiModule.helloWorld() // returns helloworld.
4444
```

android/cpp-adapter.cpp

Lines changed: 0 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -83,122 +83,6 @@ static jstring string2jstring(JNIEnv *env, const string &str) {
8383
}
8484

8585

86-
void install(facebook::jsi::Runtime &jsiRuntime) {
87-
88-
auto getDeviceName = Function::createFromHostFunction(jsiRuntime,
89-
PropNameID::forAscii(jsiRuntime,
90-
"getDeviceName"),
91-
0,
92-
[](Runtime &runtime,
93-
const Value &thisValue,
94-
const Value *arguments,
95-
size_t count) -> Value {
96-
97-
JNIEnv *jniEnv = GetJniEnv();
98-
99-
java_class = jniEnv->GetObjectClass(
100-
java_object);
101-
jmethodID getModel = jniEnv->GetMethodID(
102-
java_class, "getModel",
103-
"()Ljava/lang/String;");
104-
jobject result = jniEnv->CallObjectMethod(
105-
java_object, getModel);
106-
const char *str = jniEnv->GetStringUTFChars(
107-
(jstring) result, NULL);
108-
109-
return Value(runtime,
110-
String::createFromUtf8(
111-
runtime, str));
112-
113-
});
114-
115-
jsiRuntime.global().setProperty(jsiRuntime, "getDeviceName", move(getDeviceName));
116-
117-
118-
auto setItem = Function::createFromHostFunction(jsiRuntime,
119-
PropNameID::forAscii(jsiRuntime,
120-
"setItem"),
121-
2,
122-
[](Runtime &runtime,
123-
const Value &thisValue,
124-
const Value *arguments,
125-
size_t count) -> Value {
126-
127-
string key = arguments[0].getString(
128-
runtime).utf8(runtime);
129-
string value = arguments[1].getString(
130-
runtime).utf8(runtime);
131-
132-
JNIEnv *jniEnv = GetJniEnv();
133-
134-
java_class = jniEnv->GetObjectClass(
135-
java_object);
136-
137-
138-
jmethodID set = jniEnv->GetMethodID(
139-
java_class, "setItem",
140-
"(Ljava/lang/String;Ljava/lang/String;)V");
141-
142-
jstring jstr1 = string2jstring(jniEnv,
143-
key);
144-
jstring jstr2 = string2jstring(jniEnv,
145-
value);
146-
jvalue params[2];
147-
params[0].l = jstr1;
148-
params[1].l = jstr2;
149-
150-
jniEnv->CallVoidMethodA(
151-
java_object, set, params);
152-
153-
return Value(true);
154-
155-
});
156-
157-
jsiRuntime.global().setProperty(jsiRuntime, "setItem", move(setItem));
158-
159-
160-
auto getItem = Function::createFromHostFunction(jsiRuntime,
161-
PropNameID::forAscii(jsiRuntime,
162-
"getItem"),
163-
1,
164-
[](Runtime &runtime,
165-
const Value &thisValue,
166-
const Value *arguments,
167-
size_t count) -> Value {
168-
169-
string key = arguments[0].getString(
170-
runtime)
171-
.utf8(
172-
runtime);
173-
174-
JNIEnv *jniEnv = GetJniEnv();
175-
176-
java_class = jniEnv->GetObjectClass(
177-
java_object);
178-
jmethodID get = jniEnv->GetMethodID(
179-
java_class, "getItem",
180-
"(Ljava/lang/String;)Ljava/lang/String;");
181-
182-
jstring jstr1 = string2jstring(jniEnv,
183-
key);
184-
jvalue params[2];
185-
params[0].l = jstr1;
186-
187-
jobject result = jniEnv->CallObjectMethodA(
188-
java_object, get, params);
189-
const char *str = jniEnv->GetStringUTFChars(
190-
(jstring) result, NULL);
191-
192-
return Value(runtime,
193-
String::createFromUtf8(
194-
runtime, str));
195-
196-
});
197-
198-
jsiRuntime.global().setProperty(jsiRuntime, "getItem", move(getItem));
199-
200-
}
201-
20286
extern "C"
20387
JNIEXPORT void JNICALL
20488
Java_com_reactnativesimplejsi_SimpleJsiModule_nativeInstall(JNIEnv *env, jobject thiz, jlong jsi) {
@@ -207,7 +91,6 @@ Java_com_reactnativesimplejsi_SimpleJsiModule_nativeInstall(JNIEnv *env, jobject
20791

20892
if (runtime) {
20993
example::install(*runtime);
210-
install(*runtime);
21194
}
21295

21396
env->GetJavaVM(&java_vm);
57.8 KB
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

android/gradlew

Lines changed: 185 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)