Java Code Examples for com.facebook.react.bridge.Arguments#createMap()

The following examples show how to use com.facebook.react.bridge.Arguments#createMap() . 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:    From react-native-camera-android with MIT License 6 votes vote down vote up
public void handleResult(Result result) {

    // Received Barcode Result!
    WritableMap event = Arguments.createMap();
    event.putString("data", result.getText());
    event.putString("type", result.getBarcodeFormat().toString());

    ReactContext reactContext = (ReactContext)getContext();

Example 2
Source File:    From react-native-bluetooth-status with MIT License 6 votes vote down vote up
public void onReceive(Context context, Intent intent) {
    final String action = intent.getAction();
    WritableMap params = Arguments.createMap();
    if (action != null && action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
        final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
        switch (state) {
            case BluetoothAdapter.STATE_OFF:
                params.putString(BT_STATUS_PARAM, BT_STATUS_OFF);
                sendEvent(reactContext, BT_STATUS_EVENT, params);
            case BluetoothAdapter.STATE_ON:
                params.putString(BT_STATUS_PARAM, BT_STATUS_ON);
                sendEvent(reactContext, BT_STATUS_EVENT, params);
Example 3
Source File:    From react-native-barcode with MIT License 6 votes vote down vote up
public WritableMap decodeNV21Data(byte[] data, int width, int height, int rotation) {
    Image image = new Image(width, height, ImageFormat.Y800.toString());

    WritableMap result = null;
    if (mScanner.scanImage(image) != 0) {
        SymbolSet symbols = mScanner.getResults();
        Symbol symbol = symbols.iterator().next();
        result = Arguments.createMap();
        result.putInt("format", symbolToFormat(symbol.getType()));
        result.putString("content", fixEncoding(symbol.getData()));
    return result;
Example 4
Source File:    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);
        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) {
    return writableMap;
Example 5
Source File:    From react-native-google-nearby-connection with MIT License 5 votes vote down vote up
public void onReceive(Context context, Intent intent) {
	if (getReactApplicationContext().hasActiveCatalystInstance()) {
		int statusCode = intent.getIntExtra("statusCode", -1);
		String endpointName = intent.getStringExtra("endpointName");
		String serviceId = intent.getStringExtra("serviceId");

		WritableMap out = Arguments.createMap();
		out.putInt("statusCode", statusCode);
		out.putString("endpointName", endpointName);
		out.putString("serviceId", serviceId);

		sendEvent(getReactApplicationContext(), "advertising_start_failed", out);
Example 6
Source File:    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 7
Source File:    From react-native-push-notification-CE with MIT License 5 votes vote down vote up
void notifyNotification(Bundle bundle) {
    String bundleString = convertJSON(bundle);

    WritableMap params = Arguments.createMap();
    params.putString("dataJSON", bundleString);

    sendEvent("remoteNotificationReceived", params);
Example 8
Source File:    From react-native-unified-contacts with MIT License 5 votes vote down vote up
private WritableArray getPhoneNumbersFromContact(int contactId) {
    WritableArray phoneNumbers = Arguments.createArray();

    Cursor phoneNumbersCursor = contentResolver.query(
        ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId,

    while (phoneNumbersCursor.moveToNext()) {
        WritableMap phoneNumber = Arguments.createMap();

        String number           = getStringFromCursor( phoneNumbersCursor, ContactsContract.CommonDataKinds.Phone.NUMBER );
        String normalizedNumber = getStringFromCursor( phoneNumbersCursor, ContactsContract.CommonDataKinds.Phone.NORMALIZED_NUMBER );
        String label            = getStringFromCursor( phoneNumbersCursor, ContactsContract.CommonDataKinds.Phone.LABEL );

        int typeInt = getIntFromCursor( phoneNumbersCursor, ContactsContract.CommonDataKinds.Phone.TYPE );
        String type = String.valueOf(ContactsContract.CommonDataKinds.Phone.getTypeLabel(getCurrentActivity().getResources(), typeInt, ""));

        // NOTE: label is only set for custom Types, so to keep things consistent between iOS and Android
        // and to essentially give the user what they really want, which is the label, put type into label if it's null.
        if (label == null) label = type;

        phoneNumber.putString("stringValue", number);
        phoneNumber.putString("digits", normalizedNumber);
        phoneNumber.putString("label", label);
        phoneNumber.putString("type", type);

    return phoneNumbers;
Example 9
Source File:    From react-native-twilio-ip-messaging with MIT License 5 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.putMap("attributes", jsonToWritableMap(channel.getAttributes()));
    map.putString("synchronizationStatus", channel.getSynchronizationStatus().toString());
    map.putString("dateCreated", channel.getDateCreated().toString());
    map.putString("dateUpdated", channel.getDateUpdated().toString());
    return map;
Example 10
Source File:    From react-native-maps with MIT License 5 votes vote down vote up
 * Called when the My Location button is tapped. Returns YES if the listener has consumed the
 * event (i.e., the default behavior should not occur), NO otherwise (i.e., the default behavior
 * should occur). The default behavior is for the camera to move such that it is centered on the
 * user location.
 * @return
public boolean onMyLocationButtonClick() {
    WritableMap event = Arguments.createMap();

    event.putString("event", "didTapMyLocationButtonForMapView");


    return false;
Example 11
Source File:    From react-native-bottom-sheet-behavior with MIT License 5 votes vote down vote up
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
    WritableMap event = Arguments.createMap();
    event.putDouble("offset", slideOffset);
    ReactContext reactContext = (ReactContext) bottomSheet.getContext();
    reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(bottomSheet.getId(), "topSlide", event);
Example 12
Source File:    From react-native-tapjoy with MIT License 4 votes vote down vote up
private void responseNotConnected(final Promise promise) {
    WritableMap responseMap = Arguments.createMap();
    promiseReject(promise, TAPJOY_IS_NOT_CONNECTED);
Example 13
Source File:    From ReactNativeDropdownAndroid with MIT License 4 votes vote down vote up
private WritableMap serializeEventData() {
    WritableMap eventData = Arguments.createMap();
    eventData.putInt("selected", getPosition());
    eventData.putString("value", getValue());
    return eventData;
Example 14
Source File:    From react-native-twilio-programmable-voice with MIT License 4 votes vote down vote up
public void connect(ReadableMap params) {
    if (BuildConfig.DEBUG) {
        Log.d(TAG, "connect params: "+params);
    WritableMap errParams = Arguments.createMap();
    if (accessToken == null) {
        errParams.putString("err", "Invalid access token");
        eventManager.sendEvent(EVENT_DEVICE_NOT_READY, errParams);
    if (params == null) {
        errParams.putString("err", "Invalid parameters");
        eventManager.sendEvent(EVENT_CONNECTION_DID_DISCONNECT, errParams);
    } else if (!params.hasKey("To")) {
        errParams.putString("err", "Invalid To parameter");
        eventManager.sendEvent(EVENT_CONNECTION_DID_DISCONNECT, errParams);
    toNumber = params.getString("To");
    if (params.hasKey("ToName")) {
        toName = params.getString("ToName");


    ReadableMapKeySetIterator iterator = params.keySetIterator();
    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();
        ReadableType readableType = params.getType(key);
        switch (readableType) {
            case Null:
                twiMLParams.put(key, "");
            case Boolean:
                twiMLParams.put(key, String.valueOf(params.getBoolean(key)));
            case Number:
                // Can be int or double.
                twiMLParams.put(key, String.valueOf(params.getDouble(key)));
            case String:
                twiMLParams.put(key, params.getString(key));
                Log.d(TAG, "Could not convert with key: " + key + ".");

    activeCall =, accessToken, twiMLParams, callListener);
Example 15
Source File:    From react-native-GPay with MIT License 4 votes vote down vote up
private WritableMap serializeEventData() {
  WritableMap eventData = Arguments.createMap();
  eventData.putDouble("drawerState", getDrawerState());
  return eventData;
Example 16
Source File:    From react-native-stripe-terminal with MIT License 4 votes vote down vote up
public void getPaymentStatus(){
    PaymentStatus status = Terminal.getInstance().getPaymentStatus();
    WritableMap statusMap = Arguments.createMap();
Example 17
Source File:    From react-native-stripe-terminal with MIT License 4 votes vote down vote up
public void onRequestReaderDisplayMessage(@Nonnull ReaderDisplayMessage readerDisplayMessage) {
    WritableMap displayMessageMap = Arguments.createMap();
Example 18
Source File:    From react-native-firestack with MIT License 4 votes vote down vote up
public static WritableMap dataSnapshotToMap(String name, 
  String path, 
  DataSnapshot dataSnapshot) {
    WritableMap data = Arguments.createMap();

    data.putString("key", dataSnapshot.getKey());
    data.putBoolean("exists", dataSnapshot.exists());
    data.putBoolean("hasChildren", dataSnapshot.hasChildren());

    data.putDouble("childrenCount", dataSnapshot.getChildrenCount());
    if (!dataSnapshot.hasChildren()) {
      Object value = dataSnapshot.getValue();
      String type = value!=null ? value.getClass().getName() : "";
      switch (type) {
        case "java.lang.Boolean":
          data.putBoolean("value", (Boolean)value);
        case "java.lang.Long":
          Long longVal = (Long) value;
          data.putDouble("value", (double)longVal);
        case "java.lang.Double":
          data.putDouble("value", (Double) value);
        case "java.lang.String":
          data.putString("value",(String) value);
          data.putString("value", null);
    } else{
      WritableMap valueMap = FirestackUtils.castSnapshotValue(dataSnapshot);
      data.putMap("value", valueMap);

    // Child keys
    WritableArray childKeys = FirestackUtils.getChildKeys(dataSnapshot);
    data.putArray("childKeys", childKeys);

    Object priority = dataSnapshot.getPriority();
    if (priority == null) {
      data.putString("priority", null);
    } else {
      data.putString("priority", priority.toString());

    WritableMap eventMap = Arguments.createMap();
    eventMap.putString("eventName", name);
    eventMap.putMap("snapshot", data);
    eventMap.putString("path", path);
    return eventMap;
Example 19
Source File:    From react-native-firestack with MIT License 4 votes vote down vote up
public void onHostResume() {
    WritableMap params = Arguments.createMap();
    params.putBoolean("isForeground", true);
    FirestackUtils.sendEvent(mReactContext, "FirestackAppState", params);
Example 20
Source File:    From react-native-fingerprint-identify with MIT License 4 votes vote down vote up
private void sendResponse(String status, String message, Promise promise) {
     response = Arguments.createMap();
     response.putString("status", status);
     response.putString("error", message);