Search in sources :

Example 31 with ReactMethod

use of com.facebook.react.bridge.ReactMethod in project react-native-fbsdk by facebook.

the class FBShareDialogModule method canShow.

@ReactMethod
public void canShow(ReadableMap shareContent, Promise promise) {
    if (getCurrentActivity() != null) {
        ShareDialog shareDialog = new ShareDialog(getCurrentActivity());
        promise.resolve(mShareDialogMode == null ? shareDialog.canShow(Utility.buildShareContent(shareContent)) : shareDialog.canShow(Utility.buildShareContent(shareContent), mShareDialogMode));
    } else {
        promise.reject("No current activity.");
    }
}
Also used : ShareDialog(com.facebook.share.widget.ShareDialog) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 32 with ReactMethod

use of com.facebook.react.bridge.ReactMethod in project react-native-fbsdk by facebook.

the class FBMessageDialogModule method canShow.

/**
 * Indicates whether it is possible to show the dialog for ShareContent of the specified type.
 * @param shareContentMap  must be a valid {@link ShareContent}.
 * @param promise Use promise to pass message dialog result to JS.
 */
@ReactMethod
public void canShow(ReadableMap shareContentMap, Promise promise) {
    if (getCurrentActivity() != null) {
        ShareContent shareContent = Utility.buildShareContent(shareContentMap);
        MessageDialog messageDialog = new MessageDialog(getCurrentActivity());
        promise.resolve(messageDialog.canShow(shareContent));
    } else {
        promise.reject("No current activity.");
    }
}
Also used : MessageDialog(com.facebook.share.widget.MessageDialog) ShareContent(com.facebook.share.model.ShareContent) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 33 with ReactMethod

use of com.facebook.react.bridge.ReactMethod in project react-native-camera by lwansbrough.

the class RCTCameraModule method setZoom.

@ReactMethod
public void setZoom(ReadableMap options, int zoom) {
    RCTCamera instance = RCTCamera.getInstance();
    if (instance == null)
        return;
    Camera camera = instance.acquireCameraInstance(options.getInt("type"));
    if (camera == null)
        return;
    Camera.Parameters parameters = camera.getParameters();
    int maxZoom = parameters.getMaxZoom();
    if (parameters.isZoomSupported()) {
        if (zoom >= 0 && zoom < maxZoom) {
            parameters.setZoom(zoom);
            try {
                camera.setParameters(parameters);
            } catch (RuntimeException e) {
                Log.e("RCTCameraModule", "setParameters failed", e);
            }
        }
    }
}
Also used : Camera(android.hardware.Camera) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 34 with ReactMethod

use of com.facebook.react.bridge.ReactMethod in project react-native-image-picker by marcshilling.

the class ImagePickerModule method launchCamera.

// NOTE: Currently not reentrant / doesn't support concurrent requests
@ReactMethod
public void launchCamera(final ReadableMap options, final Callback callback) {
    if (!isCameraAvailable()) {
        responseHelper.invokeError(callback, "Camera not available");
        return;
    }
    final Activity currentActivity = getCurrentActivity();
    if (currentActivity == null) {
        responseHelper.invokeError(callback, "can't find current Activity");
        return;
    }
    this.options = options;
    if (!permissionsCheck(currentActivity, callback, REQUEST_PERMISSIONS_FOR_CAMERA)) {
        return;
    }
    parseOptions(this.options);
    int requestCode;
    Intent cameraIntent;
    if (pickVideo) {
        requestCode = REQUEST_LAUNCH_VIDEO_CAPTURE;
        cameraIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
        cameraIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, videoQuality);
        if (videoDurationLimit > 0) {
            cameraIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, videoDurationLimit);
        }
    } else {
        requestCode = REQUEST_LAUNCH_IMAGE_CAPTURE;
        cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        final File original = createNewFile(reactContext, this.options, false);
        imageConfig = imageConfig.withOriginalFile(original);
        if (imageConfig.original != null) {
            cameraCaptureURI = RealPathUtil.compatUriFromFile(reactContext, imageConfig.original);
        } else {
            responseHelper.invokeError(callback, "Couldn't get file path for photo");
            return;
        }
        if (cameraCaptureURI == null) {
            responseHelper.invokeError(callback, "Couldn't get file path for photo");
            return;
        }
        cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, cameraCaptureURI);
    }
    if (cameraIntent.resolveActivity(reactContext.getPackageManager()) == null) {
        responseHelper.invokeError(callback, "Cannot launch camera");
        return;
    }
    this.callback = callback;
    // see https://code.google.com/p/android/issues/detail?id=76683
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
        List<ResolveInfo> resInfoList = reactContext.getPackageManager().queryIntentActivities(cameraIntent, PackageManager.MATCH_DEFAULT_ONLY);
        for (ResolveInfo resolveInfo : resInfoList) {
            String packageName = resolveInfo.activityInfo.packageName;
            reactContext.grantUriPermission(packageName, cameraCaptureURI, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
        }
    }
    try {
        currentActivity.startActivityForResult(cameraIntent, requestCode);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
        responseHelper.invokeError(callback, "Cannot launch camera");
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ActivityNotFoundException(android.content.ActivityNotFoundException) ReactActivity(com.facebook.react.ReactActivity) Activity(android.app.Activity) Intent(android.content.Intent) MediaUtils.createNewFile(com.imagepicker.utils.MediaUtils.createNewFile) File(java.io.File) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 35 with ReactMethod

use of com.facebook.react.bridge.ReactMethod in project react-native-navigation by wix.

the class NavigationModule method setRoot.

@ReactMethod
public void setRoot(String commandId, ReadableMap rawLayoutTree, Promise promise) {
    final LayoutNode layoutTree = LayoutNodeParser.parse(Objects.requireNonNull(jsonParser.parse(rawLayoutTree).optJSONObject("root")));
    handle(() -> {
        final ViewController<?> viewController = layoutFactory.create(layoutTree);
        navigator().setRoot(viewController, new NativeCommandListener("setRoot", commandId, promise, eventEmitter, now), reactInstanceManager);
    });
}
Also used : LayoutNode(com.reactnativenavigation.options.LayoutNode) ReactMethod(com.facebook.react.bridge.ReactMethod)

Aggregations

ReactMethod (com.facebook.react.bridge.ReactMethod)82 Activity (android.app.Activity)21 Intent (android.content.Intent)11 WritableMap (com.facebook.react.bridge.WritableMap)11 Bundle (android.os.Bundle)9 ReactApplicationContext (com.facebook.react.bridge.ReactApplicationContext)6 WritableArray (com.facebook.react.bridge.WritableArray)6 ArrayList (java.util.ArrayList)5 Camera (android.hardware.Camera)4 NativeViewHierarchyManager (com.facebook.react.uimanager.NativeViewHierarchyManager)4 UIBlock (com.facebook.react.uimanager.UIBlock)4 UIManagerModule (com.facebook.react.uimanager.UIManagerModule)4 ShareContent (com.facebook.share.model.ShareContent)4 LayoutNode (com.reactnativenavigation.options.LayoutNode)4 LoginManager (com.facebook.login.LoginManager)3 ReactActivity (com.facebook.react.ReactActivity)3 LatLng (com.google.android.gms.maps.model.LatLng)3 ActivityNotFoundException (android.content.ActivityNotFoundException)2 RemoteException (android.os.RemoteException)2 JSApplicationIllegalArgumentException (com.facebook.react.bridge.JSApplicationIllegalArgumentException)2