Search in sources :

Example 1 with NativeViewHierarchyManager

use of com.facebook.react.uimanager.NativeViewHierarchyManager in project react-native-gesture-handler by kmagiera.

the class RNGestureHandlerModule method tryInitializeHandlerForReactRootView.

private void tryInitializeHandlerForReactRootView(int ancestorViewTag) {
    UIManagerModule uiManager = getReactApplicationContext().getNativeModule(UIManagerModule.class);
    final int rootViewTag = uiManager.resolveRootTagFromReactTag(ancestorViewTag);
    if (rootViewTag < 1) {
        throw new JSApplicationIllegalArgumentException("Could find root view for a given ancestor with tag " + ancestorViewTag);
    }
    synchronized (mRoots) {
        for (int i = 0; i < mRoots.size(); i++) {
            RNGestureHandlerRootHelper root = mRoots.get(i);
            if (root.getRootView().getRootViewTag() == rootViewTag) {
                // initialize a new one then
                return;
            }
        }
    }
    synchronized (mEnqueuedRootViewInit) {
        if (mEnqueuedRootViewInit.contains(rootViewTag)) {
            // root view initialization already enqueued -> we skip
            return;
        }
        mEnqueuedRootViewInit.add(rootViewTag);
    }
    // root helper for a given root tag has not been found, we may wat to check if the root view is
    // an instance of RNGestureHandlerEnabledRootView and then initialize gesture handler with it
    uiManager.addUIBlock(new UIBlock() {

        @Override
        public void execute(NativeViewHierarchyManager nativeViewHierarchyManager) {
            View view = nativeViewHierarchyManager.resolveView(rootViewTag);
            if (view instanceof RNGestureHandlerEnabledRootView) {
                ((RNGestureHandlerEnabledRootView) view).initialize();
            } else {
            // Seems like the root view is something else than RNGestureHandlerEnabledRootView, this
            // is fine though as long as gestureHandlerRootHOC is used in JS
            // FIXME: check and warn about gestureHandlerRootHOC
            }
            synchronized (mEnqueuedRootViewInit) {
                mEnqueuedRootViewInit.remove(new Integer(rootViewTag));
            }
        }
    });
}
Also used : UIBlock(com.facebook.react.uimanager.UIBlock) UIManagerModule(com.facebook.react.uimanager.UIManagerModule) JSApplicationIllegalArgumentException(com.facebook.react.bridge.JSApplicationIllegalArgumentException) View(android.view.View) ReactRootView(com.facebook.react.ReactRootView) NativeViewHierarchyManager(com.facebook.react.uimanager.NativeViewHierarchyManager)

Example 2 with NativeViewHierarchyManager

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

the class CameraModule method record.

@ReactMethod
public void record(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) {
            final RNCameraView cameraView;
            try {
                cameraView = (RNCameraView) nativeViewHierarchyManager.resolveView(viewTag);
                if (cameraView.isCameraOpened()) {
                    cameraView.record(options, promise, cacheDirectory);
                } else {
                    promise.reject("E_CAMERA_UNAVAILABLE", "Camera is not running");
                }
            } catch (Exception e) {
                promise.reject("E_CAMERA_BAD_VIEWTAG", "recordAsync: Expected a Camera component");
            }
        }
    });
}
Also used : UIBlock(com.facebook.react.uimanager.UIBlock) UIManagerModule(com.facebook.react.uimanager.UIManagerModule) ReactApplicationContext(com.facebook.react.bridge.ReactApplicationContext) File(java.io.File) NativeViewHierarchyManager(com.facebook.react.uimanager.NativeViewHierarchyManager) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 3 with NativeViewHierarchyManager

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

the class CameraModule method pausePreview.

@ReactMethod
public void pausePreview(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.pausePreview();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
Also used : UIBlock(com.facebook.react.uimanager.UIBlock) UIManagerModule(com.facebook.react.uimanager.UIManagerModule) NativeViewHierarchyManager(com.facebook.react.uimanager.NativeViewHierarchyManager)

Example 4 with NativeViewHierarchyManager

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

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) SortedSet(java.util.SortedSet) Set(java.util.Set) UIManagerModule(com.facebook.react.uimanager.UIManagerModule) NativeViewHierarchyManager(com.facebook.react.uimanager.NativeViewHierarchyManager)

Example 5 with NativeViewHierarchyManager

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

the class CameraModule method getSupportedPreviewFpsRange.

@ReactMethod
public void getSupportedPreviewFpsRange(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();
                ArrayList<int[]> ranges = cameraView.getSupportedPreviewFpsRange();
                for (int[] range : ranges) {
                    WritableMap m = new WritableNativeMap();
                    m.putInt("MINIMUM_FPS", range[0]);
                    m.putInt("MAXIMUM_FPS", range[1]);
                    result.pushMap(m);
                }
                promise.resolve(result);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
Also used : UIBlock(com.facebook.react.uimanager.UIBlock) UIManagerModule(com.facebook.react.uimanager.UIManagerModule) ArrayList(java.util.ArrayList) NativeViewHierarchyManager(com.facebook.react.uimanager.NativeViewHierarchyManager)

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