Search in sources :

Example 6 with NativeViewHierarchyManager

use of com.facebook.react.uimanager.NativeViewHierarchyManager in project react-native-camera by lwansbrough.

the class CameraModule method getCameraIds.

@ReactMethod
public void getCameraIds(final int viewTag, final Promise promise) {
    final ReactApplicationContext context = getReactApplicationContext();
    UIManagerModule uiManager = context.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {

        @Override
        public void execute(NativeViewHierarchyManager nativeViewHierarchyManager) {
            final RNCameraView cameraView;
            try {
                cameraView = (RNCameraView) nativeViewHierarchyManager.resolveView(viewTag);
                WritableArray result = Arguments.createArray();
                List<Properties> ids = cameraView.getCameraIds();
                for (Properties p : ids) {
                    WritableMap m = new WritableNativeMap();
                    m.putString("id", p.getProperty("id"));
                    m.putInt("type", Integer.valueOf(p.getProperty("type")));
                    result.pushMap(m);
                }
                promise.resolve(result);
            } catch (Exception e) {
                e.printStackTrace();
                promise.reject("E_CAMERA_FAILED", e.getMessage());
            }
        }
    });
}
Also used : UIBlock(com.facebook.react.uimanager.UIBlock) UIManagerModule(com.facebook.react.uimanager.UIManagerModule) ArrayList(java.util.ArrayList) List(java.util.List) Properties(java.util.Properties) NativeViewHierarchyManager(com.facebook.react.uimanager.NativeViewHierarchyManager)

Example 7 with NativeViewHierarchyManager

use of com.facebook.react.uimanager.NativeViewHierarchyManager in project react-native-camera by lwansbrough.

the class CameraModule method takePicture.

@ReactMethod
public void takePicture(final ReadableMap options, final int viewTag, final Promise promise) {
    final ReactApplicationContext context = getReactApplicationContext();
    final File cacheDirectory = mScopedContext.getCacheDirectory();
    UIManagerModule uiManager = context.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {

        @Override
        public void execute(NativeViewHierarchyManager nativeViewHierarchyManager) {
            RNCameraView cameraView = (RNCameraView) nativeViewHierarchyManager.resolveView(viewTag);
            try {
                if (cameraView.isCameraOpened()) {
                    cameraView.takePicture(options, promise, cacheDirectory);
                } else {
                    promise.reject("E_CAMERA_UNAVAILABLE", "Camera is not running");
                }
            } catch (Exception e) {
                promise.reject("E_TAKE_PICTURE_FAILED", e.getMessage());
            }
        }
    });
}
Also used : UIBlock(com.facebook.react.uimanager.UIBlock) UIManagerModule(com.facebook.react.uimanager.UIManagerModule) File(java.io.File) NativeViewHierarchyManager(com.facebook.react.uimanager.NativeViewHierarchyManager)

Example 8 with NativeViewHierarchyManager

use of com.facebook.react.uimanager.NativeViewHierarchyManager in project react-native-camera by lwansbrough.

the class CameraModule method getAvailablePictureSizes.

@ReactMethod
public void getAvailablePictureSizes(final String ratio, final int viewTag, final Promise promise) {
    final ReactApplicationContext context = getReactApplicationContext();
    UIManagerModule uiManager = context.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {

        @Override
        public void execute(NativeViewHierarchyManager nativeViewHierarchyManager) {
            final RNCameraView cameraView;
            try {
                cameraView = (RNCameraView) nativeViewHierarchyManager.resolveView(viewTag);
                WritableArray result = Arguments.createArray();
                if (cameraView.isCameraOpened()) {
                    SortedSet<Size> sizes = cameraView.getAvailablePictureSizes(AspectRatio.parse(ratio));
                    for (Size size : sizes) {
                        result.pushString(size.toString());
                    }
                    promise.resolve(result);
                } else {
                    promise.reject("E_CAMERA_UNAVAILABLE", "Camera is not running");
                }
            } catch (Exception e) {
                promise.reject("E_CAMERA_BAD_VIEWTAG", "getAvailablePictureSizesAsync: Expected a Camera component");
            }
        }
    });
}
Also used : UIBlock(com.facebook.react.uimanager.UIBlock) UIManagerModule(com.facebook.react.uimanager.UIManagerModule) Size(com.google.android.cameraview.Size) SortedSet(java.util.SortedSet) NativeViewHierarchyManager(com.facebook.react.uimanager.NativeViewHierarchyManager)

Example 9 with NativeViewHierarchyManager

use of com.facebook.react.uimanager.NativeViewHierarchyManager in project react-native-camera by react-native-community.

the class CameraModule method stopRecording.

@ReactMethod
public void stopRecording(final int viewTag) {
    final ReactApplicationContext context = getReactApplicationContext();
    UIManagerModule uiManager = context.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {

        @Override
        public void execute(NativeViewHierarchyManager nativeViewHierarchyManager) {
            final RNCameraView cameraView;
            try {
                cameraView = (RNCameraView) nativeViewHierarchyManager.resolveView(viewTag);
                if (cameraView.isCameraOpened()) {
                    cameraView.stopRecording();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
Also used : UIBlock(com.facebook.react.uimanager.UIBlock) UIManagerModule(com.facebook.react.uimanager.UIManagerModule) ReactApplicationContext(com.facebook.react.bridge.ReactApplicationContext) NativeViewHierarchyManager(com.facebook.react.uimanager.NativeViewHierarchyManager) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 10 with NativeViewHierarchyManager

use of com.facebook.react.uimanager.NativeViewHierarchyManager in project react-native-camera by react-native-community.

the class CameraModule method getSupportedRatios.

@ReactMethod
public void getSupportedRatios(final int viewTag, final Promise promise) {
    final ReactApplicationContext context = getReactApplicationContext();
    UIManagerModule uiManager = context.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {

        @Override
        public void execute(NativeViewHierarchyManager nativeViewHierarchyManager) {
            final RNCameraView cameraView;
            try {
                cameraView = (RNCameraView) nativeViewHierarchyManager.resolveView(viewTag);
                WritableArray result = Arguments.createArray();
                if (cameraView.isCameraOpened()) {
                    Set<AspectRatio> ratios = cameraView.getSupportedAspectRatios();
                    for (AspectRatio ratio : ratios) {
                        result.pushString(ratio.toString());
                    }
                    promise.resolve(result);
                } else {
                    promise.reject("E_CAMERA_UNAVAILABLE", "Camera is not running");
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
Also used : UIBlock(com.facebook.react.uimanager.UIBlock) AspectRatio(com.google.android.cameraview.AspectRatio) Set(java.util.Set) UIManagerModule(com.facebook.react.uimanager.UIManagerModule) WritableArray(com.facebook.react.bridge.WritableArray) ReactApplicationContext(com.facebook.react.bridge.ReactApplicationContext) NativeViewHierarchyManager(com.facebook.react.uimanager.NativeViewHierarchyManager) ReactMethod(com.facebook.react.bridge.ReactMethod)

Aggregations

NativeViewHierarchyManager (com.facebook.react.uimanager.NativeViewHierarchyManager)16 UIBlock (com.facebook.react.uimanager.UIBlock)16 UIManagerModule (com.facebook.react.uimanager.UIManagerModule)16 ReactApplicationContext (com.facebook.react.bridge.ReactApplicationContext)4 ReactMethod (com.facebook.react.bridge.ReactMethod)4 File (java.io.File)4 AspectRatio (com.google.android.cameraview.AspectRatio)2 ArrayList (java.util.ArrayList)2 Set (java.util.Set)2 SortedSet (java.util.SortedSet)2 Bitmap (android.graphics.Bitmap)1 View (android.view.View)1 ReactRootView (com.facebook.react.ReactRootView)1 JSApplicationIllegalArgumentException (com.facebook.react.bridge.JSApplicationIllegalArgumentException)1 WritableArray (com.facebook.react.bridge.WritableArray)1 Size (com.google.android.cameraview.Size)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 List (java.util.List)1 Properties (java.util.Properties)1 ResolveTakenPictureAsyncTask (org.reactnative.camera.tasks.ResolveTakenPictureAsyncTask)1