Java Code Examples for com.facebook.react.bridge.ReadableType#String
The following examples show how to use
com.facebook.react.bridge.ReadableType#String .
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: ReactDrawerLayoutManager_1d0b39_t.java From coming with MIT License | 6 votes |
@ReactProp(name = "drawerPosition") public void setDrawerPosition(ReactDrawerLayout view, Dynamic drawerPosition) { if (drawerPosition.isNull()) { view.setDrawerPosition(Gravity.START); } else if (drawerPosition.getType() == ReadableType.Number) { final int drawerPositionNum = drawerPosition.asInt(); if (Gravity.START == drawerPositionNum || Gravity.END == drawerPositionNum) { view.setDrawerPosition(drawerPositionNum); } else { throw new JSApplicationIllegalArgumentException("Unknown drawerPosition " + drawerPositionNum); } } else if (drawerPosition.getType() == ReadableType.String) { final String drawerPositionStr = drawerPosition.asString(); if (drawerPositionStr.equals("left")) { view.setDrawerPosition(Gravity.START); } else if (drawerPositionStr.equals("right")) { view.setDrawerPosition(Gravity.END); } else { throw new JSApplicationIllegalArgumentException("drawerPosition must be 'left' or 'right', received" + drawerPositionStr); } } else { throw new JSApplicationIllegalArgumentException("drawerPosition must be a string or int"); } }
Example 2
Source File: StackTraceHelper.java From react-native-GPay with MIT License | 6 votes |
/** * Convert a JavaScript stack trace (see {@code parseErrorStack} JS module) to an array of * {@link StackFrame}s. */ public static StackFrame[] convertJsStackTrace(@Nullable ReadableArray stack) { int size = stack != null ? stack.size() : 0; StackFrame[] result = new StackFrame[size]; for (int i = 0; i < size; i++) { ReadableType type = stack.getType(i); if (type == ReadableType.Map) { ReadableMap frame = stack.getMap(i); String methodName = frame.getString("methodName"); String fileName = frame.getString("file"); int lineNumber = -1; if (frame.hasKey(LINE_NUMBER_KEY) && !frame.isNull(LINE_NUMBER_KEY)) { lineNumber = frame.getInt(LINE_NUMBER_KEY); } int columnNumber = -1; if (frame.hasKey(COLUMN_KEY) && !frame.isNull(COLUMN_KEY)) { columnNumber = frame.getInt(COLUMN_KEY); } result[i] = new StackFrameImpl(fileName, methodName, lineNumber, columnNumber); } else if (type == ReadableType.String) { result[i] = new StackFrameImpl(null, stack.getString(i), -1, -1); } } return result; }
Example 3
Source File: LayoutShadowNode.java From react-native-GPay with MIT License | 6 votes |
void setFromDynamic(Dynamic dynamic) { if (dynamic.isNull()) { unit = YogaUnit.UNDEFINED; value = YogaConstants.UNDEFINED; } else if (dynamic.getType() == ReadableType.String) { final String s = dynamic.asString(); if (s.equals("auto")) { unit = YogaUnit.AUTO; value = YogaConstants.UNDEFINED; } else if (s.endsWith("%")) { unit = YogaUnit.PERCENT; value = Float.parseFloat(s.substring(0, s.length() - 1)); } else { throw new IllegalArgumentException("Unknown value: " + s); } } else { unit = YogaUnit.POINT; value = PixelUtil.toPixelFromDIP(dynamic.asDouble()); } }
Example 4
Source File: TransformHelper.java From react-native-GPay with MIT License | 6 votes |
private static double convertToRadians(ReadableMap transformMap, String key) { double value; boolean inRadians = true; if (transformMap.getType(key) == ReadableType.String) { String stringValue = transformMap.getString(key); if (stringValue.endsWith("rad")) { stringValue = stringValue.substring(0, stringValue.length() - 3); } else if (stringValue.endsWith("deg")) { inRadians = false; stringValue = stringValue.substring(0, stringValue.length() - 3); } value = Float.parseFloat(stringValue); } else { value = transformMap.getDouble(key); } return inRadians ? value : MatrixMathHelper.degreesToRadians(value); }
Example 5
Source File: ReactNativeSmooch.java From react-native-smooch with MIT License | 6 votes |
private Map<String, Object> getUserProperties(ReadableMap properties) { ReadableMapKeySetIterator iterator = properties.keySetIterator(); Map<String, Object> userProperties = new HashMap<>(); while (iterator.hasNextKey()) { String key = iterator.nextKey(); ReadableType type = properties.getType(key); if (type == ReadableType.Boolean) { userProperties.put(key, properties.getBoolean(key)); } else if (type == ReadableType.Number) { userProperties.put(key, properties.getDouble(key)); } else if (type == ReadableType.String) { userProperties.put(key, properties.getString(key)); } } return userProperties; }
Example 6
Source File: RNMailComposeModule.java From react-native-mail-compose with MIT License | 6 votes |
private String[] getStringArray(ReadableMap map, String key) { ReadableArray array = getArray(map, key); if (array == null) return null; ArrayList<String> list = new ArrayList<>(); for (int i = 0; i < array.size(); i++) { if (array.getType(i) == ReadableType.String) { String str = array.getString(i); if (!isEmpty(str)) { list.add(str); } } } String[] arr = new String[list.size()]; return list.toArray(arr); }
Example 7
Source File: RNMessageComposeModule.java From react-native-message-compose with MIT License | 5 votes |
private byte[] getBlobFromUri(ReadableMap map, String key) { if (map.hasKey(key) && map.getType(key) == ReadableType.String) { String uri = map.getString(key); if (uri != null && !uri.isEmpty()) { return byteArrayFromUrl(uri); } } return null; }
Example 8
Source File: FirestackCloudMessaging.java From react-native-firestack with MIT License | 5 votes |
@ReactMethod public void send(String senderId, String messageId, String messageType, ReadableMap params, final Callback callback) { FirebaseMessaging fm = FirebaseMessaging.getInstance(); RemoteMessage.Builder remoteMessage = new RemoteMessage.Builder(senderId); remoteMessage.setMessageId(messageId); remoteMessage.setMessageType(messageType); ReadableMapKeySetIterator iterator = params.keySetIterator(); while (iterator.hasNextKey()) { String key = iterator.nextKey(); ReadableType type = params.getType(key); if (type == ReadableType.String) { remoteMessage.addData(key, params.getString(key)); Log.d(TAG, "Firebase send: " + key); Log.d(TAG, "Firebase send: " + params.getString(key)); } } try { fm.send(remoteMessage.build()); WritableMap res = Arguments.createMap(); res.putString("status", "success"); callback.invoke(null, res); } catch(Exception e) { Log.e(TAG, "Error sending message", e); WritableMap error = Arguments.createMap(); error.putString("code", e.toString()); error.putString("message", e.toString()); callback.invoke(error); } }
Example 9
Source File: ArrayUtil.java From Instabug-React-Native with MIT License | 5 votes |
public static ArrayList<String> parseReadableArrayOfStrings(ReadableArray readableArray) { ArrayList<String> array = new ArrayList<>(); for (int i = 0; i < readableArray.size(); i++) { ReadableType type = readableArray.getType(i); if (type == ReadableType.String) { array.add(readableArray.getString(i)); } } return array; }
Example 10
Source File: RNMailComposeModule.java From react-native-mail-compose with MIT License | 5 votes |
private byte[] getBlobFromUri(ReadableMap map, String key) { if (map.hasKey(key) && map.getType(key) == ReadableType.String) { String uri = map.getString(key); if (uri != null && !uri.isEmpty()) { return byteArrayFromUrl(uri); } } return null; }
Example 11
Source File: RNMailComposeModule.java From react-native-mail-compose with MIT License | 5 votes |
private byte[] getBlob(ReadableMap map, String key) { if (map.hasKey(key) && map.getType(key) == ReadableType.String) { String base64 = map.getString(key); if (base64 != null && !base64.isEmpty()) { return Base64.decode(base64, 0); } } return null; }
Example 12
Source File: FlurryModule.java From react-native-flurry-sdk with Apache License 2.0 | 5 votes |
private static List<String> toList(final ReadableArray readableArray) { if ((readableArray == null) || (readableArray.size() == 0)) { return null; } List<String> result = new ArrayList<>(); for (int i = 0; i < readableArray.size(); i++) { if (readableArray.getType(i) == ReadableType.String) { result.add(readableArray.getString(i)); } } return result; }
Example 13
Source File: RNMessageComposeModule.java From react-native-message-compose with MIT License | 5 votes |
private byte[] getBlob(ReadableMap map, String key) { if (map.hasKey(key) && map.getType(key) == ReadableType.String) { String base64 = map.getString(key); if (base64 != null && !base64.isEmpty()) { return Base64.decode(base64, 0); } } return null; }
Example 14
Source File: JSStackTrace.java From react-native-GPay with MIT License | 5 votes |
private static String stackFrameToModuleId(ReadableMap frame) { if (frame.hasKey("file") && !frame.isNull("file") && frame.getType("file") == ReadableType.String) { final Matcher matcher = mJsModuleIdPattern.matcher(frame.getString("file")); if (matcher.find()) { return matcher.group(1) + ":"; } } return ""; }
Example 15
Source File: RNMailComposeModule.java From react-native-mail-compose with MIT License | 4 votes |
private String getString(ReadableMap map, String key) { if (map.hasKey(key) && map.getType(key) == ReadableType.String) { return map.getString(key); } return null; }
Example 16
Source File: RNMessageComposeModule.java From react-native-message-compose with MIT License | 4 votes |
private String getString(ReadableMap map, String key) { if (map.hasKey(key) && map.getType(key) == ReadableType.String) { return map.getString(key); } return null; }
Example 17
Source File: CheckoutModule.java From react-native-square-reader-sdk with Apache License 2.0 | 4 votes |
static private boolean validateJSCheckoutParams(ReadableMap jsCheckoutParams, StringBuilder paramError) { // check types of all parameters if (!jsCheckoutParams.hasKey("amountMoney") || jsCheckoutParams.getType("amountMoney") != ReadableType.Map) { paramError.append("'amountMoney' is missing or not an object"); return false; } else if (jsCheckoutParams.hasKey("skipReceipt") && jsCheckoutParams.getType("skipReceipt") != ReadableType.Boolean) { paramError.append("'skipReceipt' is not a boolean"); return false; } else if (jsCheckoutParams.hasKey("collectSignature") && jsCheckoutParams.getType("collectSignature") != ReadableType.Boolean) { paramError.append("'collectSignature' is not a boolean"); return false; } else if (jsCheckoutParams.hasKey("allowSplitTender") && jsCheckoutParams.getType("allowSplitTender") != ReadableType.Boolean) { paramError.append("'allowSplitTender' is not a boolean"); return false; } else if (jsCheckoutParams.hasKey("delayCapture") && jsCheckoutParams.getType("delayCapture") != ReadableType.Boolean) { paramError.append("'delayCapture' is not a boolean"); return false; } else if (jsCheckoutParams.hasKey("note") && jsCheckoutParams.getType("note") != ReadableType.String) { paramError.append("'note' is not a string"); return false; } else if (jsCheckoutParams.hasKey("tipSettings") && jsCheckoutParams.getType("tipSettings") != ReadableType.Map) { paramError.append("'tipSettings' is not an object"); return false; } else if (jsCheckoutParams.hasKey("additionalPaymentTypes") && jsCheckoutParams.getType("additionalPaymentTypes") != ReadableType.Array) { paramError.append("'additionalPaymentTypes' is not an array"); return false; } // check amountMoney ReadableMap amountMoney = jsCheckoutParams.getMap("amountMoney"); if (!amountMoney.hasKey("amount") || amountMoney.getType("amount") != ReadableType.Number) { paramError.append("'amount' is not an integer"); return false; } if (amountMoney.hasKey("currencyCode") && amountMoney.getType("currencyCode") != ReadableType.String) { paramError.append("'currencyCode' is not a String"); return false; } if (amountMoney.hasKey("currencyCode")) { try { CurrencyCode.valueOf(amountMoney.getString("currencyCode")); } catch (IllegalArgumentException ex) { paramError.append("failed to parse 'currencyCode'"); return false; } } if (jsCheckoutParams.hasKey("tipSettings")) { // check tipSettings ReadableMap tipSettings = jsCheckoutParams.getMap("tipSettings"); if (tipSettings.hasKey("showCustomTipField") && tipSettings.getType("showCustomTipField") != ReadableType.Boolean) { paramError.append("'showCustomTipField' is not a boolean"); return false; } else if (tipSettings.hasKey("showSeparateTipScreen") && tipSettings.getType("showSeparateTipScreen") != ReadableType.Boolean) { paramError.append("'showSeparateTipScreen' is not a boolean"); return false; } else if (tipSettings.hasKey("tipPercentages") && tipSettings.getType("tipPercentages") != ReadableType.Array) { paramError.append("'tipPercentages' is not an array"); return false; } } return true; }