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");
}
}
});
}
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();
}
});
}
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));
}
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;
}
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;
}
Aggregations