Java Code Examples for com.facebook.react.bridge.WritableMap#putMap()

The following examples show how to use com.facebook.react.bridge.WritableMap#putMap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TokenResponseFactory.java    From react-native-app-auth with MIT License 6 votes vote down vote up
public static final WritableMap tokenResponseToMap(TokenResponse response, AuthorizationResponse authResponse) {
    WritableMap map = Arguments.createMap();

    map.putString("accessToken", response.accessToken);
    map.putMap("authorizeAdditionalParameters", MapUtil.createAdditionalParametersMap(authResponse.additionalParameters));
    map.putMap("tokenAdditionalParameters", MapUtil.createAdditionalParametersMap(response.additionalParameters));
    map.putString("idToken", response.idToken);
    map.putString("refreshToken", response.refreshToken);
    map.putString("tokenType", response.tokenType);
    map.putArray("scopes", createScopeArray(authResponse.scope));

    if (response.accessTokenExpirationTime != null) {
        map.putString("accessTokenExpirationDate", DateUtil.formatTimestamp(response.accessTokenExpirationTime));
    }


    return map;
}
 
Example 2
Source File: RNInstabugReactnativeModule.java    From Instabug-React-Native with MIT License 6 votes vote down vote up
private 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;
}
 
Example 3
Source File: AMapViewManager.java    From react-native-amap with MIT License 6 votes vote down vote up
public WritableMap makeClickEventData(LatLng point) {
    WritableMap event = new WritableNativeMap();

    WritableMap coordinate = new WritableNativeMap();
    coordinate.putDouble("latitude", point.latitude);
    coordinate.putDouble("longitude", point.longitude);
    event.putMap("coordinate", coordinate);

    Projection projection = map.getProjection();
    Point screenPoint = projection.toScreenLocation(point);

    WritableMap position = new WritableNativeMap();
    position.putDouble("x", screenPoint.x);
    position.putDouble("y", screenPoint.y);
    event.putMap("position", position);

    return event;
}
 
Example 4
Source File: RNRtmpView.java    From react-native-rtmpview with MIT License 6 votes vote down vote up
public void onPlaybackStateChanged(RNRtmpPlaybackState playbackState, Throwable error) {
    WritableMap event = Arguments.createMap();
    event.putString("state", playbackState.getFieldDescription());
    event.putInt("playback_state", mPlayer.getPlaybackState());
    event.putBoolean("play_when_ready", mPlayer.getPlayWhenReady());

    if (error != null) {
        event.putString("error", error.toString());
    }

    event.putMap("qos", getQos());

    ReactContext reactContext = (ReactContext)getContext();
    reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(
            getId(),
            Events.EVENT_PLAYBACK_STATE.toString(),
            event);
}
 
Example 5
Source File: FabricTwitterKitUtils.java    From react-native-fabric-twitterkit with MIT License 6 votes vote down vote up
private static WritableMap jsonToWritableMap(final JSONObject jsonObject) throws JSONException {
    final WritableMap writableMap = Arguments.createMap();
    final Iterator iterator = jsonObject.keys();
    while (iterator.hasNext()) {
        final String key = (String) iterator.next();
        final Object value = jsonObject.get(key);
        if (value instanceof Float || value instanceof Double) {
            writableMap.putDouble(key, jsonObject.getDouble(key));
        } else if (value instanceof Number) {
            writableMap.putInt(key, jsonObject.getInt(key));
        } else if (value instanceof String) {
            writableMap.putString(key, jsonObject.getString(key));
        } else if (value instanceof JSONObject) {
            writableMap.putMap(key, jsonToWritableMap(jsonObject.getJSONObject(key)));
        } else if (value instanceof JSONArray) {
            writableMap.putArray(key, jsonToWritableArray(jsonObject.getJSONArray(key)));
        } else if (value instanceof Boolean) {
            writableMap.putBoolean(key, jsonObject.getBoolean(key));
        } else if (value == JSONObject.NULL) {
            writableMap.putNull(key);
        }
    }
    return writableMap;
}
 
Example 6
Source File: PPTGoogleMapManager.java    From react-native-maps with MIT License 6 votes vote down vote up
/**
 * Called repeatedly during any animations or gestures on the map (or once, if the camera is
 * explicitly set). This may not be called for all intermediate camera positions. It is always
 * called for the final position of an animation or gesture.
 *
 * @param cameraPosition
 */
@Override
public void onCameraChange(CameraPosition cameraPosition) {
    WritableMap event = Arguments.createMap();
    WritableMap data = Arguments.createMap();

    data.putDouble("latitude", cameraPosition.target.latitude);
    data.putDouble("longitude", cameraPosition.target.longitude);
    data.putDouble("zoom", cameraPosition.zoom);

    event.putString("event", "didChangeCameraPosition");
    event.putMap("data", data);

    reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(
            mapView.getId(),
            "topChange",
            event
    );
}
 
Example 7
Source File: ImageLoadEvent.java    From react-native-GPay with MIT License 6 votes vote down vote up
@Override
public void dispatch(RCTEventEmitter rctEventEmitter) {
  WritableMap eventData = null;

  if (mImageUri != null || mEventType == ON_LOAD) {
    eventData = Arguments.createMap();

    if (mImageUri != null) {
      eventData.putString("uri", mImageUri);
    }

    if (mEventType == ON_LOAD) {
      WritableMap source = Arguments.createMap();
      source.putDouble("width", mWidth);
      source.putDouble("height", mHeight);
      if (mImageUri != null) {
        source.putString("url", mImageUri);
      }
      eventData.putMap("source", source);
    }
  }

  rctEventEmitter.receiveEvent(getViewTag(), getEventName(), eventData);
}
 
Example 8
Source File: LocationModule.java    From react-native-GPay with MIT License 6 votes vote down vote up
private static WritableMap locationToMap(Location location) {
  WritableMap map = Arguments.createMap();
  WritableMap coords = Arguments.createMap();
  coords.putDouble("latitude", location.getLatitude());
  coords.putDouble("longitude", location.getLongitude());
  coords.putDouble("altitude", location.getAltitude());
  coords.putDouble("accuracy", location.getAccuracy());
  coords.putDouble("heading", location.getBearing());
  coords.putDouble("speed", location.getSpeed());
  map.putMap("coords", coords);
  map.putDouble("timestamp", location.getTime());

  if (android.os.Build.VERSION.SDK_INT >= 18) {
    map.putBoolean("mocked", location.isFromMockProvider());
  }

  return map;
}
 
Example 9
Source File: CustomTwilioVideoView.java    From react-native-twilio-video-webrtc with MIT License 6 votes vote down vote up
private void addParticipant(Room room, RemoteParticipant remoteParticipant) {

        WritableMap event = new WritableNativeMap();
        event.putString("roomName", room.getName());
        event.putString("roomSid", room.getSid());
        event.putMap("participant", buildParticipant(remoteParticipant));

        pushEvent(this, ON_PARTICIPANT_CONNECTED, event);

        /*
         * Start listening for participant media events
         */
        remoteParticipant.setListener(mediaListener());

        for (final RemoteDataTrackPublication remoteDataTrackPublication :
              remoteParticipant.getRemoteDataTracks()) {
          /*
            * Data track messages are received on the thread that calls setListener. Post the
            * invocation of setting the listener onto our dedicated data track message thread.
            */
          if (remoteDataTrackPublication.isTrackSubscribed()) {
              dataTrackMessageThreadHandler.post(() -> addRemoteDataTrack(remoteParticipant,
                      remoteDataTrackPublication.getRemoteDataTrack()));
          }
      }
    }
 
Example 10
Source File: ReactNativeJson.java    From react-native-fcm with MIT License 6 votes vote down vote up
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;
}
 
Example 11
Source File: PPTGoogleMapManager.java    From react-native-maps with MIT License 6 votes vote down vote up
/**
 * Called after a long-press gesture at a particular coordinate.
 *
 * @param latLng
 */
@Override
public void onMapLongClick(LatLng latLng) {
    WritableMap event = Arguments.createMap();
    WritableMap data = Arguments.createMap();

    data.putDouble("latitude", latLng.latitude);
    data.putDouble("longitude", latLng.longitude);

    event.putString("event", "didLongPressAtCoordinate");
    event.putMap("data", data);

    reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(
            mapView.getId(),
            "topChange",
            event
    );
}
 
Example 12
Source File: RCTConvert.java    From react-native-twilio-chat with MIT License 6 votes vote down vote up
public static WritableMap Channel(Channel channel) {
    WritableMap map = Arguments.createMap();

    map.putString("sid", channel.getSid());
    map.putString("friendlyName", channel.getFriendlyName());
    map.putString("uniqueName", channel.getUniqueName());
    map.putString("status", channel.getStatus().toString());
    map.putString("type", channel.getType().toString());
    map.putString("synchronizationStatus", channel.getSynchronizationStatus().toString());
    map.putString("dateCreated", channel.getDateCreated().toString());
    map.putString("dateUpdated", channel.getDateUpdated().toString());
    WritableMap attributes = Arguments.createMap();
    try {
        attributes = jsonToWritableMap(channel.getAttributes());
    }
    catch (JSONException e) {}
    map.putMap("attributes", attributes);
    return map;
}
 
Example 13
Source File: MapListener.java    From react-native-baidu-map with MIT License 5 votes vote down vote up
private WritableMap getEventParams(MapStatus mapStatus) {
    WritableMap writableMap = Arguments.createMap();
    WritableMap target = Arguments.createMap();
    target.putDouble("latitude", mapStatus.target.latitude);
    target.putDouble("longitude", mapStatus.target.longitude);
    writableMap.putMap("target", target);
    writableMap.putDouble("latitudeDelta", mapStatus.bound.northeast.latitude - mapStatus.bound.southwest.latitude);
    writableMap.putDouble("longitudeDelta", mapStatus.bound.northeast.longitude - mapStatus.bound.southwest.longitude);
    writableMap.putDouble("zoom", mapStatus.zoom);
    writableMap.putDouble("overlook", mapStatus.overlook);
    return writableMap;
}
 
Example 14
Source File: RCTConvert.java    From react-native-twilio-chat with MIT License 5 votes vote down vote up
public static WritableMap ChannelDescriptor(ChannelDescriptor channel) {
    WritableMap map = Arguments.createMap();

    map.putString("sid", channel.getSid());
    map.putString("friendlyName", channel.getFriendlyName());
    map.putString("uniqueName", channel.getUniqueName());
    map.putMap("attributes", jsonToWritableMap(channel.getAttributes()));
    map.putString("dateCreated", channel.getDateCreated().toString());
    map.putString("dateUpdated", channel.getDateUpdated().toString());
    map.putInt("membersCount", (int) channel.getMembersCount());
    map.putInt("messagesCount", (int) channel.getMessagesCount());
    return map;
}
 
Example 15
Source File: Utils.java    From react-native-update with MIT License 5 votes vote down vote up
public static WritableMap convertJsonObjectToWriteable(JSONObject jsonObj) {
    WritableMap map = Arguments.createMap();
    Iterator<String> it = jsonObj.keys();
    while(it.hasNext()){
        String key = it.next();
        Object obj = null;
        try {
            obj = jsonObj.get(key);
        } catch (JSONException jsonException) {
            // Should not happen.
            throw new RuntimeException("Key " + key + " should exist in " + jsonObj.toString() + ".", jsonException);
        }

        if (obj instanceof JSONObject)
            map.putMap(key, convertJsonObjectToWriteable((JSONObject) obj));
        else if (obj instanceof JSONArray)
            map.putArray(key, convertJsonArrayToWriteable((JSONArray) obj));
        else if (obj instanceof String)
            map.putString(key, (String) obj);
        else if (obj instanceof Double)
            map.putDouble(key, (Double) obj);
        else if (obj instanceof Integer)
            map.putInt(key, (Integer) obj);
        else if (obj instanceof Boolean)
            map.putBoolean(key, (Boolean) obj);
        else if (obj == null)
            map.putNull(key);
        else
            throw new RuntimeException("Unrecognized object: " + obj);
    }

    return map;
}
 
Example 16
Source File: FirestackDatabase.java    From react-native-firestack with MIT License 5 votes vote down vote up
private void handleDatabaseError(final String name, final String path, final DatabaseError error) {
  WritableMap err = Arguments.createMap();
  err.putInt("errorCode", error.getCode());
  err.putString("errorDetails", error.getDetails());
  err.putString("description", error.getMessage());

  WritableMap evt  = Arguments.createMap();
  evt.putString("eventName", name);
  evt.putString("path", path);
  evt.putMap("body", err);

  FirestackUtils.sendEvent(mReactContext, "database_error", evt);
}
 
Example 17
Source File: RegistrationResponseFactory.java    From react-native-app-auth with MIT License 5 votes vote down vote up
public static final WritableMap registrationResponseToMap(RegistrationResponse response) {
    WritableMap map = Arguments.createMap();
    
    map.putString("clientId", response.clientId);
    map.putMap("additionalParameters", MapUtil.createAdditionalParametersMap(response.additionalParameters));

    if (response.clientIdIssuedAt != null) {
        map.putString("clientIdIssuedAt", DateUtil.formatTimestamp(response.clientIdIssuedAt));
    }

    if (response.clientSecret != null) {
        map.putString("clientSecret", response.clientSecret);
    }

    if (response.clientSecretExpiresAt != null) {
        map.putString("clientSecretExpiresAt", DateUtil.formatTimestamp(response.clientSecretExpiresAt));
    }

    if (response.registrationAccessToken != null) {
        map.putString("registrationAccessToken", response.registrationAccessToken);
    }

    if (response.registrationClientUri != null) {
        map.putString("registrationClientUri", response.registrationClientUri.toString());
    }

    if (response.tokenEndpointAuthMethod != null) {
        map.putString("tokenEndpointAuthMethod", response.tokenEndpointAuthMethod);
    }

    return map;
}
 
Example 18
Source File: MerryPhotoView.java    From photo-viewer with Apache License 2.0 4 votes vote down vote up
private ImageViewer.OnImageChangeListener getImageChangeListener() {
        return new ImageViewer.OnImageChangeListener() {
            @Override
            public void onImageChange(int position) {

                final MerryPhotoData merryPhotoData = getData()[position];
                String url = merryPhotoData.source.getString("uri");
//                default use url
                overlayView.setShareContext(url);

                overlayView.setDescription(merryPhotoData.summary);
                overlayView.setTitleText(merryPhotoData.title);

                int summaryColor = Color.WHITE;
                int titleColor = Color.WHITE;
                if (getShareText() != null) {
                    overlayView.setShareText(getShareText());
                }

                // is hide sharebutton
                overlayView.setHideShareButton(isHideShareButton());
                overlayView.setHideCloseButton(isHideCloseButton());

//                if (options.titlePagerColor != null) {
//                    overlayView.setPagerTextColor(options.titlePagerColor);
//                }
//
                overlayView.setPagerText((position + 1) + " / " + getData().length);
                if (merryPhotoData.titleColor != 0) {

                    titleColor = merryPhotoData.titleColor;
                }
                overlayView.setTitleTextColor(titleColor);
                if (merryPhotoData.summaryColor != 0) {
                    summaryColor = merryPhotoData.summaryColor;
                }
                overlayView.setDescriptionTextColor(summaryColor);

                WritableMap writableMap = Arguments.createMap();
                writableMap.putString("title", merryPhotoData.title);
                writableMap.putString("summary", merryPhotoData.summary);
                writableMap.putInt("summaryColor", merryPhotoData.summaryColor);
                writableMap.putInt("titleColor", merryPhotoData.titleColor);
                writableMap.putMap("source", Utils.toWritableMap(merryPhotoData.source));

                // onChange event from js side
                WritableMap map = Arguments.createMap();
                map.putMap("photo", writableMap);
                map.putInt("index", position);

                onNavigateToPhoto(map);

            }
        };
    }
 
Example 19
Source File: ShowOptionsTest.java    From react-native-lock with MIT License 4 votes vote down vote up
@Test
public void testAllNative() throws Exception {
    WritableMap options = new SimpleMap();
    options.putBoolean("closable", true);
    options.putBoolean("disableSignUp", true);
    options.putBoolean("disableResetPassword", true);
    options.putBoolean("magicLink", true);

    SimpleArray connections = new SimpleArray();
    connections.pushString("facebook");
    connections.pushString("twitter");
    options.putArray("connections", connections);

    SimpleMap authParams = new SimpleMap();
    authParams.putString("string", "string-value");
    authParams.putInt("int", 345);
    authParams.putBoolean("boolean-true", true);
    authParams.putBoolean("boolean-false", false);
    options.putMap("authParams", authParams);

    ShowOptions showOptions = new ShowOptions(options);
    assertThat(showOptions.isClosable(), is(true));
    assertThat(showOptions.isDisableSignUp(), is(true));
    assertThat(showOptions.isDisableResetPassword(), is(true));
    assertThat(showOptions.useMagicLink(), is(true));
    assertThat(showOptions.getConnectionType(), is(equalTo(LockReactModule.CONNECTION_NATIVE)));
    assertThat(Arrays.asList(showOptions.getConnections()), containsInAnyOrder("twitter", "facebook"));

    Map<String, Object> authParams2 = showOptions.getAuthParams();
    String stringValue = (String) authParams2.get("string");
    assertThat(stringValue, is(equalTo("string-value")));

    int intValue = (int) authParams2.get("int");
    assertThat(intValue, is(equalTo(345)));

    boolean booleanFalse = (boolean) authParams2.get("boolean-false");
    assertThat(booleanFalse, is(false));

    boolean booleanTrue = (boolean) authParams2.get("boolean-true");
    assertThat(booleanTrue, is(true));
}
 
Example 20
Source File: Utils.java    From photo-viewer with Apache License 2.0 4 votes vote down vote up
@Nullable
public static WritableMap jsonToWritableMap(JSONObject jsonObject) {
    WritableMap writableMap = new WritableNativeMap();

    if (jsonObject == null) {
        return null;
    }


    Iterator<String> iterator = jsonObject.keys();
    if (!iterator.hasNext()) {
        return null;
    }

    while (iterator.hasNext()) {
        String key = iterator.next();

        try {
            Object value = jsonObject.get(key);

            if (value == null) {
                writableMap.putNull(key);
            } else if (value instanceof Boolean) {
                writableMap.putBoolean(key, (Boolean) value);
            } else if (value instanceof Integer) {
                writableMap.putInt(key, (Integer) value);
            } else if (value instanceof Double) {
                writableMap.putDouble(key, (Double) value);
            } else if (value instanceof String) {
                writableMap.putString(key, (String) value);
            } else if (value instanceof JSONObject) {
                writableMap.putMap(key, jsonToWritableMap((JSONObject) value));
            } else if (value instanceof JSONArray) {
                writableMap.putArray(key, jsonArrayToWritableArray((JSONArray) value));
            }
        } catch (JSONException ex) {
            // Do nothing and fail silently
        }
    }

    return writableMap;
}