Skip to content

Instantly share code, notes, and snippets.

@MaxPleaner
Created January 2, 2023 23:03
Show Gist options
  • Save MaxPleaner/e02cc868ea021dae08ba20ada0a6277f to your computer and use it in GitHub Desktop.
Save MaxPleaner/e02cc868ea021dae08ba20ada0a6277f to your computer and use it in GitHub Desktop.
CameraViewWrapper
// Just an excerpt of the relevant part here
<Button
title="Click to invoke your native module!"
color="#841584"
onPress={() => {CameraViewWrapper.testEvent()}}
/>
package com.shadercam;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import java.util.Map;
import java.util.HashMap;
import android.util.Log;
public class CameraViewWrapper extends ReactContextBaseJavaModule {
CameraViewWrapper(ReactApplicationContext context) {
super(context);
}
@Override
public String getName() {
return "CameraViewWrapper";
}
@ReactMethod
public void testEvent() {
Log.d("ReactNative","Notify App");
}
}
package com.shadercam;
import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class CameraViewWrapperPackage implements ReactPackage {
@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 CameraViewWrapper(reactContext));
return modules;
}
}
// Just an excerpt of the changed part here
@Override
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here, for example:
packages.add(new CameraViewWrapperPackage());
return packages;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment