Search in sources :

Example 31 with WritableMap

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

the class BottomTabsLayout method sendTabSelectedEventToJs.

private void sendTabSelectedEventToJs(int selectedTabIndex, int unselectedTabIndex) {
    String navigatorEventId = screenStacks[selectedTabIndex].peek().getNavigatorEventId();
    WritableMap data = createTabSelectedEventData(selectedTabIndex, unselectedTabIndex);
    NavigationApplication.instance.getEventEmitter().sendNavigatorEvent("bottomTabSelected", navigatorEventId, data);
    data = createTabSelectedEventData(selectedTabIndex, unselectedTabIndex);
    NavigationApplication.instance.getEventEmitter().sendNavigatorEvent("bottomTabSelected", data);
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap)

Example 32 with WritableMap

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

the class FIRMessagingModule method parseIntent.

private WritableMap parseIntent(Intent intent) {
    WritableMap params;
    Bundle extras = intent.getExtras();
    if (extras != null) {
        try {
            params = Arguments.fromBundle(extras);
        } catch (Exception e) {
            Log.e(TAG, e.getMessage());
            params = Arguments.createMap();
        }
    } else {
        params = Arguments.createMap();
    }
    WritableMap fcm = Arguments.createMap();
    fcm.putString("action", intent.getAction());
    params.putMap("fcm", fcm);
    params.putInt("opened_from_tray", 1);
    return params;
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) Bundle(android.os.Bundle) IOException(java.io.IOException)

Example 33 with WritableMap

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

the class ReactNativeJson method convertJsonToMap.

public static WritableMap convertJsonToMap(JSONObject jsonObject) throws JSONException {
    WritableMap map = new WritableNativeMap();
    Iterator<String> iterator = jsonObject.keys();
    while (iterator.hasNext()) {
        String key = iterator.next();
        Object value = jsonObject.get(key);
        if (value instanceof JSONObject) {
            map.putMap(key, convertJsonToMap((JSONObject) value));
        } else if (value instanceof JSONArray) {
            map.putArray(key, convertJsonToArray((JSONArray) value));
        } else if (value instanceof Boolean) {
            map.putBoolean(key, (Boolean) value);
        } else if (value instanceof Integer) {
            map.putInt(key, (Integer) value);
        } else if (value instanceof Double) {
            map.putDouble(key, (Double) value);
        } else if (value instanceof String) {
            map.putString(key, (String) value);
        } else {
            map.putString(key, value.toString());
        }
    }
    return map;
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) JSONObject(org.json.JSONObject) WritableNativeMap(com.facebook.react.bridge.WritableNativeMap) JSONArray(org.json.JSONArray) JSONObject(org.json.JSONObject)

Example 34 with WritableMap

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

the class RCTLoginButton method init.

public void init() {
    mAccessTokenTracker = new AccessTokenTracker() {

        @Override
        protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {
            if (currentAccessToken == null) {
                WritableMap event = Arguments.createMap();
                event.putString("type", "logoutFinished");
                ReactContext context = (ReactContext) getContext();
                context.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "topChange", event);
            }
        }
    };
    this.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {
            WritableMap event = Arguments.createMap();
            event.putString("type", "loginFinished");
            event.putString("error", null);
            WritableMap result = Arguments.createMap();
            result.putBoolean("isCancelled", false);
            result.putArray("grantedPermissions", Arguments.fromJavaArgs(setToStringArray(loginResult.getRecentlyGrantedPermissions())));
            result.putArray("declinedPermissions", Arguments.fromJavaArgs(setToStringArray(loginResult.getRecentlyDeniedPermissions())));
            event.putMap("result", result);
            ReactContext context = (ReactContext) getContext();
            context.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "topChange", event);
        }

        @Override
        public void onError(FacebookException error) {
            WritableMap event = Arguments.createMap();
            event.putString("type", "loginFinished");
            event.putString("error", error.toString());
            WritableMap result = Arguments.createMap();
            result.putBoolean("isCancelled", false);
            event.putMap("result", result);
            ReactContext context = (ReactContext) getContext();
            context.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "topChange", event);
        }

        @Override
        public void onCancel() {
            WritableMap event = Arguments.createMap();
            event.putString("type", "loginFinished");
            event.putString("error", null);
            WritableMap result = Arguments.createMap();
            result.putBoolean("isCancelled", true);
            event.putMap("result", result);
            ReactContext context = (ReactContext) getContext();
            context.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "topChange", event);
        }
    });
}
Also used : AccessTokenTracker(com.facebook.AccessTokenTracker) WritableMap(com.facebook.react.bridge.WritableMap) ThemedReactContext(com.facebook.react.uimanager.ThemedReactContext) ReactContext(com.facebook.react.bridge.ReactContext) AccessToken(com.facebook.AccessToken) FacebookException(com.facebook.FacebookException) LoginResult(com.facebook.login.LoginResult)

Example 35 with WritableMap

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

the class FBGraphRequestModule method convertJSONObject.

private WritableMap convertJSONObject(JSONObject object) {
    WritableMap result = Arguments.createMap();
    Iterator<String> keyIterator = object.keys();
    while (keyIterator.hasNext()) {
        String key = keyIterator.next();
        Object value;
        try {
            value = object.get(key);
        } catch (JSONException e) {
            return result;
        }
        if (value instanceof JSONObject) {
            result.putMap(key, convertJSONObject((JSONObject) value));
        } else if (value instanceof JSONArray) {
            result.putArray(key, convertJSONArray((JSONArray) value));
        } else if (value instanceof String) {
            result.putString(key, (String) value);
        } else if (value instanceof Integer) {
            result.putInt(key, (int) value);
        } else if (value instanceof Boolean) {
            result.putBoolean(key, (Boolean) value);
        } else if (value instanceof Double) {
            result.putDouble(key, (Double) value);
        }
    }
    return result;
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject)

Aggregations

WritableMap (com.facebook.react.bridge.WritableMap)54 ReactContext (com.facebook.react.bridge.ReactContext)5 ThemedReactContext (com.facebook.react.uimanager.ThemedReactContext)4 Intent (android.content.Intent)3 WritableNativeMap (com.facebook.react.bridge.WritableNativeMap)3 RCTEventEmitter (com.facebook.react.uimanager.events.RCTEventEmitter)3 IOException (java.io.IOException)3 BroadcastReceiver (android.content.BroadcastReceiver)2 Context (android.content.Context)2 IntentFilter (android.content.IntentFilter)2 MediaMetadataRetriever (android.media.MediaMetadataRetriever)2 Bundle (android.os.Bundle)2 View (android.view.View)2 Callback (com.facebook.react.bridge.Callback)2 ReactApplicationContext (com.facebook.react.bridge.ReactApplicationContext)2 ReadableMap (com.facebook.react.bridge.ReadableMap)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2