Java Code Examples for com.facebook.react.bridge.WritableMap#putString()
The following examples show how to use
com.facebook.react.bridge.WritableMap#putString() .
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: RNMEvaluator.java From react-native-eval with MIT License | 6 votes |
/** * Marshalls a function call to the javascript layer, via our NativeModule. * * @param context The context needed to execute this in. * @param name The function to execute. e.g. "Math.Pow" * @param args The arguments to pass to the function, or null. * @param cb The completion callback for the result, or null. * @param event The name of the event that our NativeModule is listening for. */ private static void callFunction(ReactContext context, String name, @Nullable Object[] args, @Nullable EvaluatorCallback cb, String event) { String callId = UUID.randomUUID().toString(); if (null != cb) { callbacks.put(callId, cb); } WritableArray arguments = args != null ? Arguments.fromJavaArgs(args) : Arguments.createArray(); if (arguments.size() == 0) { arguments.pushNull(); } WritableMap eventParams = Arguments.createMap(); eventParams.putString("name", name); eventParams.putArray("args", arguments); eventParams.putString("callId", callId); // TODO: move to AppEventEmitter once App events are supported on android. context.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) .emit(event, eventParams); }
Example 2
Source File: ReactExoplayerView.java From react-native-video with MIT License | 6 votes |
private WritableArray getTextTrackInfo() { WritableArray textTracks = Arguments.createArray(); MappingTrackSelector.MappedTrackInfo info = trackSelector.getCurrentMappedTrackInfo(); int index = getTrackRendererIndex(C.TRACK_TYPE_TEXT); if (info == null || index == C.INDEX_UNSET) { return textTracks; } TrackGroupArray groups = info.getTrackGroups(index); for (int i = 0; i < groups.length; ++i) { Format format = groups.get(i).getFormat(0); WritableMap textTrack = Arguments.createMap(); textTrack.putInt("index", i); textTrack.putString("title", format.id != null ? format.id : ""); textTrack.putString("type", format.sampleMimeType); textTrack.putString("language", format.language != null ? format.language : ""); textTracks.pushMap(textTrack); } return textTracks; }
Example 3
Source File: ReactNativeJson.java From react-native-fcm with MIT License | 6 votes |
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 4
Source File: QTalkLoaclSearch.java From imsdk-android with MIT License | 6 votes |
@ReactMethod public void search( String key, int length, int start, String groupId, Promise promise) { WritableMap map = Arguments.createMap(); map.putBoolean("is_ok", true); try { List ret = NativeApi.localSearch(key, start, length, groupId); String jsonStr = JsonUtils.getGson().toJson(ret); Logger.i("QTalkLoaclSearch->"+jsonStr); map.putString("data", jsonStr); promise.resolve(map); } catch (Exception e) { Logger.i("QTalkLoaclSearch-search>"+e.getLocalizedMessage()); //map.putBoolean("is_ok", false); //map.putString("errorMsg", e.toString()); promise.reject("500", e.toString(), e); } }
Example 5
Source File: TelephonyModule.java From react-native-telephony with MIT License | 6 votes |
@Override public void phoneSignalStrengthsUpdated(SignalStrength signalStrength) { WritableMap map = Arguments.createMap(); map.putInt("cdmaDbm", signalStrength.getCdmaDbm()); map.putInt("cdmaEcio()", signalStrength.getCdmaEcio()); map.putInt("evdoDbm", signalStrength.getEvdoDbm()); map.putInt("evdoEcio", signalStrength.getEvdoEcio()); map.putInt("evdoSnr", signalStrength.getEvdoSnr()); map.putInt("gsmBitErrorRate", signalStrength.getGsmBitErrorRate()); map.putInt("gsmSignalStrength", signalStrength.getGsmSignalStrength()); map.putBoolean("gsm", signalStrength.isGsm()); WritableMap result = Arguments.createMap(); result.putString("type", "LISTEN_SIGNAL_STRENGTHS"); result.putMap("data", map); sendEvent(PHONE_STATE_LISTENER, result); }
Example 6
Source File: ZXingDecoder.java From react-native-barcode with MIT License | 6 votes |
@Override public ReadableMap decodeRGBBitmap(Bitmap bitmap) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); int[] pixels = new int[width * height]; bitmap.getPixels(pixels, 0, width, 0, 0, width, height); bitmap.recycle(); RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels); BinaryBitmap bBitmap = new BinaryBitmap(new HybridBinarizer(source)); WritableMap result = null; try { Result decodeResult = mReader.decode(bBitmap, mHints); result = Arguments.createMap(); result.putInt("format", symbolToFormat(decodeResult.getBarcodeFormat())); result.putString("content", decodeResult.getText()); } catch (NotFoundException ignored) { } return result; }
Example 7
Source File: ShareTestCase.java From react-native-GPay with MIT License | 6 votes |
public void testShowBasicShareDialog() { final WritableMap content = new WritableNativeMap(); content.putString("message", "Hello, ReactNative!"); final WritableMap options = new WritableNativeMap(); IntentFilter intentFilter = new IntentFilter(Intent.ACTION_CHOOSER); intentFilter.addCategory(Intent.CATEGORY_DEFAULT); ActivityMonitor monitor = getInstrumentation().addMonitor(intentFilter, null, true); getTestModule().showShareDialog(content, options); waitForBridgeAndUIIdle(); getInstrumentation().waitForIdleSync(); assertEquals(1, monitor.getHits()); assertEquals(1, mRecordingModule.getOpened()); assertEquals(0, mRecordingModule.getErrors()); }
Example 8
Source File: TcpSocketModule.java From react-native-tcp-socket with MIT License | 5 votes |
@Override public void onData(Integer id, byte[] data) { WritableMap eventParams = Arguments.createMap(); eventParams.putInt("id", id); eventParams.putString("data", Base64.encodeToString(data, Base64.NO_WRAP)); sendEvent("data", eventParams); }
Example 9
Source File: ReactUsbSerialModule.java From react-native-usbserial with MIT License | 5 votes |
@ReactMethod public void getDeviceListAsync(Promise p) { try { UsbManager usbManager = getUsbManager(); HashMap<String, UsbDevice> usbDevices = usbManager.getDeviceList(); WritableArray deviceArray = Arguments.createArray(); for (String key: usbDevices.keySet()) { UsbDevice device = usbDevices.get(key); WritableMap map = Arguments.createMap(); map.putString("name", device.getDeviceName()); map.putInt("deviceId", device.getDeviceId()); map.putInt("productId", device.getProductId()); map.putInt("vendorId", device.getVendorId()); map.putString("deviceName", device.getDeviceName()); deviceArray.pushMap(map); } p.resolve(deviceArray); } catch (Exception e) { p.reject(e); } }
Example 10
Source File: Manager.java From react-native-fitness with MIT License | 5 votes |
private void processCalories(DataSet dataSet, WritableArray map) { WritableMap caloryMap = Arguments.createMap(); for (DataPoint dp : dataSet.getDataPoints()) { for(Field field : dp.getDataType().getFields()) { caloryMap.putString("startDate", dateFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS))); caloryMap.putString("endDate", dateFormat.format(dp.getEndTime(TimeUnit.MILLISECONDS))); caloryMap.putDouble("quantity", dp.getValue(field).asFloat()); map.pushMap(caloryMap); } } }
Example 11
Source File: ArgumentUtils.java From react-native-sip with GNU General Public License v3.0 | 5 votes |
private static WritableMap fromJsonObject(JsonObject object) { WritableMap result = new WritableNativeMap(); for (Map.Entry<String, JsonElement> entry : object.entrySet()) { Object value = fromJson(entry.getValue()); if (value instanceof WritableMap) { result.putMap(entry.getKey(), (WritableMap) value); } else if (value instanceof WritableArray) { result.putArray(entry.getKey(), (WritableArray) value); } else if (value instanceof String) { result.putString(entry.getKey(), (String) value); } else if (value instanceof LazilyParsedNumber) { result.putInt(entry.getKey(), ((LazilyParsedNumber) value).intValue()); } else if (value instanceof Integer) { result.putInt(entry.getKey(), (Integer) value); } else if (value instanceof Double) { result.putDouble(entry.getKey(), (Double) value); } else if (value instanceof Boolean) { result.putBoolean(entry.getKey(), (Boolean) value); } else { Log.d("ArgumentUtils", "Unknown type: " + value.getClass().getName()); result.putNull(entry.getKey()); } } return result; }
Example 12
Source File: FirestackAuth.java From react-native-firestack with MIT License | 5 votes |
@ReactMethod public void deleteUser(final Callback callback) { FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); if (user != null) { user.delete() .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { Log.d(TAG, "User account deleted"); WritableMap resp = Arguments.createMap(); resp.putString("status", "complete"); resp.putString("msg", "User account deleted"); callback.invoke(null, resp); } else { // userErrorCallback(task, callback); } } }).addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception ex) { userExceptionCallback(ex, callback); } }); } else { WritableMap err = Arguments.createMap(); err.putInt("errorCode", NO_CURRENT_USER); err.putString("errorMessage", "No current user"); callback.invoke(err); } }
Example 13
Source File: RCTTwilioIPMessagingClient.java From react-native-twilio-ip-messaging with MIT License | 5 votes |
@Override public void onError(ErrorInfo errorInfo) { WritableMap map = Arguments.createMap(); map.putString("error",errorInfo.getErrorText()); map.putString("userInfo", errorInfo.toString()); sendEvent("ipMessagingClient:errorReceived", map); }
Example 14
Source File: RCTConvert.java From react-native-twilio-ip-messaging with MIT License | 5 votes |
public static WritableMap Message(Message message) { WritableMap map = Arguments.createMap(); map.putString("sid", message.getSid()); map.putInt("index", (int) message.getMessageIndex()); map.putString("author", message.getAuthor()); map.putString("body", message.getMessageBody()); map.putString("timestamp", message.getTimeStamp()); map.putMap("attributes", jsonToWritableMap(message.getAttributes())); return map; }
Example 15
Source File: EventUtils.java From opentok-react-native with MIT License | 5 votes |
public static WritableMap prepareStreamPropertyChangedEventData(String changedProperty, Boolean oldValue, Boolean newValue, Stream stream, Session session) { WritableMap streamPropertyEventData = Arguments.createMap(); streamPropertyEventData.putString("changedProperty", changedProperty); streamPropertyEventData.putBoolean("oldValue", oldValue); streamPropertyEventData.putBoolean("newValue", newValue); streamPropertyEventData.putMap("stream", prepareJSStreamMap(stream, session)); return streamPropertyEventData; }
Example 16
Source File: FlurryModule.java From react-native-flurry-sdk with Apache License 2.0 | 5 votes |
private void sendEvent(EventType type, String key, boolean value) { WritableMap params = Arguments.createMap(); params.putString("Type", type.getName()); if (key != null) { params.putBoolean(key, value); } sReactApplicationContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) .emit(FLURRY_CONFIG_EVENT, params); }
Example 17
Source File: TelephonyModule.java From react-native-telephony with MIT License | 5 votes |
@Override public void phoneCallForwardingIndicatorUpdated(boolean cfi) { WritableMap map = Arguments.createMap(); map.putBoolean("cfi", cfi); WritableMap result = Arguments.createMap(); result.putString("type", "LISTEN_CALL_FORWARDING_INDICATOR"); result.putMap("data", map); sendEvent(PHONE_STATE_LISTENER, result); }
Example 18
Source File: ShortcutItem.java From react-native-quick-actions with MIT License | 5 votes |
WritableMap toWritableMap() { WritableMap map = Arguments.createMap(); map.putString("type", type); map.putString("title", title); map.putString("icon", icon); map.putMap("userInfo", userInfo.toWritableMap()); return map; }
Example 19
Source File: NearbyConnectionModule.java From react-native-google-nearby-connection with MIT License | 5 votes |
@Override public void onReceive(Context context, Intent intent) { if (getReactApplicationContext().hasActiveCatalystInstance()) { String endpointId = intent.getStringExtra("endpointId"); String endpointName = intent.getStringExtra("endpointName"); String serviceId = intent.getStringExtra("serviceId"); WritableMap out = Arguments.createMap(); out.putString("endpointId", endpointId); out.putString("endpointName", endpointName); out.putString("serviceId", serviceId); sendEvent(getReactApplicationContext(), "connected_to_endpoint", out); } }
Example 20
Source File: DropdownEvent.java From ReactNativeDropdownAndroid with MIT License | 4 votes |
private WritableMap serializeEventData() { WritableMap eventData = Arguments.createMap(); eventData.putInt("selected", getPosition()); eventData.putString("value", getValue()); return eventData; }