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: 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 2
Source File: ZBarDecoder.java    From react-native-barcode with MIT License 6 votes vote down vote up
@Override
public WritableMap decodeNV21Data(byte[] data, int width, int height, int rotation) {
    Image image = new Image(width, height, ImageFormat.Y800.toString());
    image.setData(data);

    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()));
    }
    image.destroy();
    return result;
}
 
Example 3
Source File: RNCameraView.java    From react-native-camera-android with MIT License 6 votes vote down vote up
@Override
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();
    reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(
            getId(),
            "topChange",
            event);

    startCamera(mCameraId);
    setFlash(torchModeIsEnabled());
}
 
Example 4
Source File: RNBluetoothManagerModule.java    From react-native-bluetooth-status with MIT License 6 votes vote down vote up
@Override
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,
                BluetoothAdapter.ERROR);
        switch (state) {
            case BluetoothAdapter.STATE_OFF:
                params.putString(BT_STATUS_PARAM, BT_STATUS_OFF);
                sendEvent(reactContext, BT_STATUS_EVENT, params);
                break;
            case BluetoothAdapter.STATE_ON:
                params.putString(BT_STATUS_PARAM, BT_STATUS_ON);
                sendEvent(reactContext, BT_STATUS_EVENT, params);
                break;
        }
    }
}
 
Example 5
Source File: NearbyConnectionModule.java    From react-native-google-nearby-connection with MIT License 5 votes vote down vote up
@Override
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: BottomSheetBehaviorManager.java    From react-native-bottom-sheet-behavior with MIT License 5 votes vote down vote up
@Override
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 7
Source File: PPTGoogleMapManager.java    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
 */
@Override
public boolean onMyLocationButtonClick() {
    WritableMap event = Arguments.createMap();

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

    reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(
            mapView.getId(),
            "topChange",
            event
    );

    return false;
}
 
Example 8
Source File: RCTConvert.java    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 9
Source File: RNUnifiedContactsModule.java    From react-native-unified-contacts with MIT License 5 votes vote down vote up
@NonNull
private WritableArray getPhoneNumbersFromContact(int contactId) {
    WritableArray phoneNumbers = Arguments.createArray();

    Cursor phoneNumbersCursor = contentResolver.query(
        ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
        null,
        ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId,
        null,
        null);

    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);

        phoneNumbers.pushMap(phoneNumber);
    }
    phoneNumbersCursor.close();
    return phoneNumbers;
}
 
Example 10
Source File: RNPushNotificationJsDelivery.java    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 11
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 12
Source File: RNStripeTerminalModule.java    From react-native-stripe-terminal with MIT License 4 votes vote down vote up
@ReactMethod
public void getPaymentStatus(){
    PaymentStatus status = Terminal.getInstance().getPaymentStatus();
    WritableMap statusMap = Arguments.createMap();
    statusMap.putInt(EVENT_PAYMENT_STATUS,status.ordinal());
}
 
Example 13
Source File: DrawerStateChangedEvent.java    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 14
Source File: RNStripeTerminalModule.java    From react-native-stripe-terminal with MIT License 4 votes vote down vote up
@Override
public void onRequestReaderDisplayMessage(@Nonnull ReaderDisplayMessage readerDisplayMessage) {
    WritableMap displayMessageMap = Arguments.createMap();
    displayMessageMap.putString(TEXT,readerDisplayMessage.toString());
    sendEventWithName(EVENT_DID_REQUEST_READER_DISPLAY_MESSAGE,displayMessageMap);
}
 
Example 15
Source File: FirestackUtils.java    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);
          break;
        case "java.lang.Long":
          Long longVal = (Long) value;
          data.putDouble("value", (double)longVal);
          break;
        case "java.lang.Double":
          data.putDouble("value", (Double) value);
          break;
        case "java.lang.String":
          data.putString("value",(String) value);
          break;
        default:
          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 16
Source File: TwilioVoiceModule.java    From react-native-twilio-programmable-voice with MIT License 4 votes vote down vote up
@ReactMethod
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);
        return;
    }
    if (params == null) {
        errParams.putString("err", "Invalid parameters");
        eventManager.sendEvent(EVENT_CONNECTION_DID_DISCONNECT, errParams);
        return;
    } else if (!params.hasKey("To")) {
        errParams.putString("err", "Invalid To parameter");
        eventManager.sendEvent(EVENT_CONNECTION_DID_DISCONNECT, errParams);
        return;
    }
    toNumber = params.getString("To");
    if (params.hasKey("ToName")) {
        toName = params.getString("ToName");
    }

    twiMLParams.clear();

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

    activeCall = Voice.call(getReactApplicationContext(), accessToken, twiMLParams, callListener);
}
 
Example 17
Source File: DropdownEvent.java    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 18
Source File: TapjoyModule.java    From react-native-tapjoy with MIT License 4 votes vote down vote up
private void responseNotConnected(final Promise promise) {
    WritableMap responseMap = Arguments.createMap();
    responseMap.putString(E_LAYOUT_ERROR, TAPJOY_IS_NOT_CONNECTED);
    promiseReject(promise, TAPJOY_IS_NOT_CONNECTED);
}
 
Example 19
Source File: FirestackModule.java    From react-native-firestack with MIT License 4 votes vote down vote up
@Override
public void onHostResume() {
    WritableMap params = Arguments.createMap();
    params.putBoolean("isForeground", true);
    FirestackUtils.sendEvent(mReactContext, "FirestackAppState", params);
}
 
Example 20
Source File: RNFingerprintIdentifyModule.java    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);
     promise.resolve(response);
}