-
-
Notifications
You must be signed in to change notification settings - Fork 263
/
MmkvModule.java
49 lines (40 loc) · 1.57 KB
/
MmkvModule.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.reactnativemmkv;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.JavaScriptContextHolder;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.module.annotations.ReactModule;
@ReactModule(name = MmkvModule.NAME)
public class MmkvModule extends ReactContextBaseJavaModule {
public static final String NAME = "MMKV";
public MmkvModule(ReactApplicationContext reactContext) {
super(reactContext);
}
@NonNull
@Override
public String getName() {
return NAME;
}
@ReactMethod(isBlockingSynchronousMethod = true)
public boolean install(@Nullable String rootDirectory) {
try {
Log.i(NAME, "Loading C++ library...");
System.loadLibrary("reactnativemmkv");
JavaScriptContextHolder jsContext = getReactApplicationContext().getJavaScriptContextHolder();
if (rootDirectory == null) {
rootDirectory = getReactApplicationContext().getFilesDir().getAbsolutePath() + "/mmkv";
}
Log.i(NAME, "Installing MMKV JSI Bindings for MMKV root directory: " + rootDirectory);
nativeInstall(jsContext.get(), rootDirectory);
Log.i(NAME, "Successfully installed MMKV JSI Bindings!");
return true;
} catch (Exception exception) {
Log.e(NAME, "Failed to install MMKV JSI Bindings!", exception);
return false;
}
}
private static native void nativeInstall(long jsiPtr, String path);
}