Search in sources :

Example 1 with ReactApplicationContext

use of com.facebook.react.bridge.ReactApplicationContext 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 2 with ReactApplicationContext

use of com.facebook.react.bridge.ReactApplicationContext in project react-native-fbads by callstack.

the class NativeAdManager method init.

/**
 * Initialises native ad manager for a given placement id and ads to request.
 * This method is run on the UI thread
 *
 * @param placementId
 * @param adsToRequest
 */
@ReactMethod
public void init(final String placementId, final int adsToRequest) {
    final ReactApplicationContext reactContext = this.getReactApplicationContext();
    UiThreadUtil.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            final NativeAdsManager adsManager = new NativeAdsManager(reactContext, placementId, adsToRequest);
            adsManager.setListener(NativeAdManager.this);
            mAdsManagers.put(placementId, adsManager);
            adsManager.loadAds();
        }
    });
}
Also used : ReactApplicationContext(com.facebook.react.bridge.ReactApplicationContext) NativeAdsManager(com.facebook.ads.NativeAdsManager) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 3 with ReactApplicationContext

use of com.facebook.react.bridge.ReactApplicationContext in project react-native-twilio-programmable-voice by hoxfon.

the class HeadsetManager method startWiredHeadsetEvent.

public void startWiredHeadsetEvent(ReactApplicationContext context) {
    if (wiredHeadsetReceiver != null) {
        return;
    }
    if (context == null) {
        if (BuildConfig.DEBUG) {
            Log.d(TAG, "startWiredHeadsetEvent() reactContext is null");
        }
        return;
    }
    if (BuildConfig.DEBUG) {
        Log.d(TAG, "startWiredHeadsetEvent()");
    }
    wiredHeadsetReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            if (ACTION_HEADSET_PLUG.equals(intent.getAction())) {
                String deviceName = intent.getStringExtra("name");
                if (deviceName == null) {
                    deviceName = "";
                }
                WritableMap data = Arguments.createMap();
                data.putBoolean("isPlugged", (intent.getIntExtra("state", 0) == 1) ? true : false);
                data.putBoolean("hasMic", (intent.getIntExtra("microphone", 0) == 1) ? true : false);
                data.putString("deviceName", deviceName);
                eventManager.sendEvent(EVENT_WIRED_HEADSET, data);
            }
        }
    };
    context.registerReceiver(wiredHeadsetReceiver, new IntentFilter(ACTION_HEADSET_PLUG));
}
Also used : Context(android.content.Context) ReactApplicationContext(com.facebook.react.bridge.ReactApplicationContext) IntentFilter(android.content.IntentFilter) WritableMap(com.facebook.react.bridge.WritableMap) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 4 with ReactApplicationContext

use of com.facebook.react.bridge.ReactApplicationContext in project react-native-track-player by react-native-kit.

the class TrackModule method waitForConnection.

private void waitForConnection(Runnable r) {
    if (binder != null) {
        binder.post(r);
        return;
    } else {
        initCallbacks.add(r);
    }
    if (connecting)
        return;
    ReactApplicationContext context = getReactApplicationContext();
    // Binds the service to get a MediaWrapper instance
    Intent intent = new Intent(context, PlayerService.class);
    context.startService(intent);
    intent.setAction(PlayerService.ACTION_CONNECT);
    context.bindService(intent, this, 0);
    connecting = true;
}
Also used : Intent(android.content.Intent) ReactApplicationContext(com.facebook.react.bridge.ReactApplicationContext)

Example 5 with ReactApplicationContext

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

the class NavigationModule method createNavigationConstantsMap.

private WritableMap createNavigationConstantsMap() {
    ReactApplicationContext ctx = getReactApplicationContext();
    final Activity currentActivity = ctx.getCurrentActivity();
    WritableMap constants = Arguments.createMap();
    constants.putString(Constants.BACK_BUTTON_JS_KEY, Constants.BACK_BUTTON_ID);
    constants.putDouble(Constants.BOTTOM_TABS_HEIGHT_KEY, pxToDp(ctx, UiUtils.getBottomTabsHeight(ctx)));
    constants.putDouble(Constants.STATUS_BAR_HEIGHT_KEY, pxToDp(ctx, SystemUiUtils.getStatusBarHeight(currentActivity)));
    constants.putDouble(Constants.TOP_BAR_HEIGHT_KEY, pxToDp(ctx, UiUtils.getTopBarHeight(ctx)));
    return constants;
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) NavigationActivity(com.reactnativenavigation.NavigationActivity) Activity(android.app.Activity) ReactApplicationContext(com.facebook.react.bridge.ReactApplicationContext)

Aggregations

ReactApplicationContext (com.facebook.react.bridge.ReactApplicationContext)13 ReactMethod (com.facebook.react.bridge.ReactMethod)6 Intent (android.content.Intent)4 NativeViewHierarchyManager (com.facebook.react.uimanager.NativeViewHierarchyManager)4 UIBlock (com.facebook.react.uimanager.UIBlock)4 UIManagerModule (com.facebook.react.uimanager.UIManagerModule)4 WritableMap (com.facebook.react.bridge.WritableMap)3 BroadcastReceiver (android.content.BroadcastReceiver)2 Context (android.content.Context)2 IntentFilter (android.content.IntentFilter)2 Handler (android.os.Handler)2 ReactInstanceManager (com.facebook.react.ReactInstanceManager)2 ReactContext (com.facebook.react.bridge.ReactContext)2 File (java.io.File)2 Activity (android.app.Activity)1 Bitmap (android.graphics.Bitmap)1 InterstitialAd (com.facebook.ads.InterstitialAd)1 NativeAdsManager (com.facebook.ads.NativeAdsManager)1 ReactApplication (com.facebook.react.ReactApplication)1 WritableArray (com.facebook.react.bridge.WritableArray)1