, NativeModule
- , .
, setCurrentActivity
ReactInstanceManager
, getCurrentActivity
ReactPackage
ReactModule
.
MyReactModule.java
public class MyReactModule extends ReactContextBaseJavaModule {
public MyReactModule(ReactApplicationContext reactContext) {
super(reactContext);
}
@Override
public String getName() {
return getClass().getSimpleName();
}
@ReactMethod
public void finish() {
Activity activity = getCurrentActivity();
if (activity != null) {
activity.finish();
}
}
}
MyReactPackage.java
MyReactPackage ReactPackage {
@Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
modules.add(new MyReactModule(reactContext));
return modules;
}
}
ReactInstanceManager
mReactInstanceManager = ReactInstanceManager.builder()
.addPackage(new MyReactPackage())
.setCurrentActivity(this)
.build();