Search in sources :

Example 6 with ReactContext

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

the class CollapsingTopBarReactHeader method dispatchTouchEventToJs.

private void dispatchTouchEventToJs(MotionEvent event) {
    ReactContext reactContext = NavigationApplication.instance.getReactGateway().getReactInstanceManager().getCurrentReactContext();
    EventDispatcher eventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
    mJSTouchDispatcher.handleTouchEvent(event, eventDispatcher);
}
Also used : EventDispatcher(com.facebook.react.uimanager.events.EventDispatcher) ReactContext(com.facebook.react.bridge.ReactContext) UIManagerModule(com.facebook.react.uimanager.UIManagerModule)

Example 7 with ReactContext

use of com.facebook.react.bridge.ReactContext in project react-native-push-notification by zo0r.

the class RNPushNotificationListenerService method onMessageReceived.

@Override
public void onMessageReceived(String from, final Bundle bundle) {
    JSONObject data = getPushData(bundle.getString("data"));
    if (data != null) {
        if (!bundle.containsKey("message")) {
            bundle.putString("message", data.optString("alert", "Notification received"));
        }
        if (!bundle.containsKey("title")) {
            bundle.putString("title", data.optString("title", null));
        }
        if (!bundle.containsKey("sound")) {
            bundle.putString("soundName", data.optString("sound", null));
        }
        if (!bundle.containsKey("color")) {
            bundle.putString("color", data.optString("color", null));
        }
        final int badge = data.optInt("badge", -1);
        if (badge >= 0) {
            ApplicationBadgeHelper.INSTANCE.setApplicationIconBadgeNumber(this, badge);
        }
    }
    Log.v(LOG_TAG, "onMessageReceived: " + bundle);
    // We need to run this on the main thread, as the React code assumes that is true.
    // Namely, DevServerHelper constructs a Handler() without a Looper, which triggers:
    // "Can't create handler inside thread that has not called Looper.prepare()"
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {

        public void run() {
            // Construct and load our normal React JS code bundle
            ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost().getReactInstanceManager();
            ReactContext context = mReactInstanceManager.getCurrentReactContext();
            // If it's constructed, send a notification
            if (context != null) {
                handleRemotePushNotification((ReactApplicationContext) context, bundle);
            } else {
                // Otherwise wait for construction, then send the notification
                mReactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {

                    public void onReactContextInitialized(ReactContext context) {
                        handleRemotePushNotification((ReactApplicationContext) context, bundle);
                    }
                });
                if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {
                    // Construct it in the background
                    mReactInstanceManager.createReactContextInBackground();
                }
            }
        }
    });
}
Also used : JSONObject(org.json.JSONObject) ReactInstanceManager(com.facebook.react.ReactInstanceManager) ReactContext(com.facebook.react.bridge.ReactContext) Handler(android.os.Handler) ReactApplication(com.facebook.react.ReactApplication) ReactApplicationContext(com.facebook.react.bridge.ReactApplicationContext)

Example 8 with ReactContext

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

the class NavigationReactGateway method onActivityResult.

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    ReactContext reactContext = getReactInstanceManager().getCurrentReactContext();
    if (reactContext != null) {
        Activity currentActivity = reactContext.getCurrentActivity();
        getReactInstanceManager().onActivityResult(currentActivity, requestCode, resultCode, data);
    }
}
Also used : ReactContext(com.facebook.react.bridge.ReactContext) Activity(android.app.Activity)

Example 9 with ReactContext

use of com.facebook.react.bridge.ReactContext in project react-native-fcm by evollu.

the class InstanceIdService method onTokenRefresh.

/**
 * Called if InstanceID token is updated. This may occur if the security of
 * the previous token had been compromised. This call is initiated by the
 * InstanceID provider.
 */
// [START refresh_token]
@Override
public void onTokenRefresh() {
    // Get updated InstanceID token.
    String refreshedToken = FirebaseInstanceId.getInstance().getToken();
    Log.d(TAG, "Refreshed token: " + refreshedToken);
    // Broadcast refreshed token
    Intent i = new Intent("com.evollu.react.fcm.FCMRefreshToken");
    Bundle bundle = new Bundle();
    bundle.putString("token", refreshedToken);
    i.putExtras(bundle);
    final Intent message = i;
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {

        public void run() {
            // Construct and load our normal React JS code bundle
            ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost().getReactInstanceManager();
            ReactContext context = mReactInstanceManager.getCurrentReactContext();
            // If it's constructed, send a notification
            if (context != null) {
                LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(message);
            } else {
                // Otherwise wait for construction, then send the notification
                mReactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {

                    public void onReactContextInitialized(ReactContext context) {
                        LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(message);
                    }
                });
                if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {
                    // Construct it in the background
                    mReactInstanceManager.createReactContextInBackground();
                }
            }
        }
    });
}
Also used : ReactInstanceManager(com.facebook.react.ReactInstanceManager) ReactContext(com.facebook.react.bridge.ReactContext) Bundle(android.os.Bundle) Handler(android.os.Handler) Intent(android.content.Intent) ReactApplication(com.facebook.react.ReactApplication)

Example 10 with ReactContext

use of com.facebook.react.bridge.ReactContext in project react-native-fcm by evollu.

the class MessagingService method onMessageReceived.

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    Log.d(TAG, "Remote message received");
    Intent i = new Intent("com.evollu.react.fcm.ReceiveNotification");
    i.putExtra("data", remoteMessage);
    handleBadge(remoteMessage);
    buildLocalNotification(remoteMessage);
    final Intent message = i;
    // We need to run this on the main thread, as the React code assumes that is true.
    // Namely, DevServerHelper constructs a Handler() without a Looper, which triggers:
    // "Can't create handler inside thread that has not called Looper.prepare()"
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {

        public void run() {
            // Construct and load our normal React JS code bundle
            ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost().getReactInstanceManager();
            ReactContext context = mReactInstanceManager.getCurrentReactContext();
            // If it's constructed, send a notification
            if (context != null) {
                LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(message);
            } else {
                // Otherwise wait for construction, then send the notification
                mReactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {

                    public void onReactContextInitialized(ReactContext context) {
                        LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(message);
                    }
                });
                if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {
                    // Construct it in the background
                    mReactInstanceManager.createReactContextInBackground();
                }
            }
        }
    });
}
Also used : ReactInstanceManager(com.facebook.react.ReactInstanceManager) ReactContext(com.facebook.react.bridge.ReactContext) Handler(android.os.Handler) Intent(android.content.Intent) ReactApplication(com.facebook.react.ReactApplication)

Aggregations

ReactContext (com.facebook.react.bridge.ReactContext)10 WritableMap (com.facebook.react.bridge.WritableMap)4 ThemedReactContext (com.facebook.react.uimanager.ThemedReactContext)4 Intent (android.content.Intent)3 Handler (android.os.Handler)3 ReactApplication (com.facebook.react.ReactApplication)3 ReactInstanceManager (com.facebook.react.ReactInstanceManager)3 RCTEventEmitter (com.facebook.react.uimanager.events.RCTEventEmitter)3 Activity (android.app.Activity)1 Bitmap (android.graphics.Bitmap)1 GLException (android.opengl.GLException)1 Bundle (android.os.Bundle)1 AccessToken (com.facebook.AccessToken)1 AccessTokenTracker (com.facebook.AccessTokenTracker)1 FacebookException (com.facebook.FacebookException)1 LoginResult (com.facebook.login.LoginResult)1 ReactApplicationContext (com.facebook.react.bridge.ReactApplicationContext)1 ReactMethod (com.facebook.react.bridge.ReactMethod)1 UIManagerModule (com.facebook.react.uimanager.UIManagerModule)1 EventDispatcher (com.facebook.react.uimanager.events.EventDispatcher)1