Java Code Examples for com.facebook.react.bridge.WritableArray#pushString()
The following examples show how to use
com.facebook.react.bridge.WritableArray#pushString() .
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: RNI18nModule.java From imsdk-android with MIT License | 6 votes |
private WritableArray getLocaleList() { WritableArray array = Arguments.createArray(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { LocaleList locales = getReactApplicationContext() .getResources().getConfiguration().getLocales(); for (int i = 0; i < locales.size(); i++) { array.pushString(this.toLanguageTag(locales.get(i))); } } else { array.pushString(this.toLanguageTag(getReactApplicationContext() .getResources().getConfiguration().locale)); } return array; }
Example 2
Source File: SocketsModule.java From react-native-sockets with MIT License | 6 votes |
@ReactMethod public void getIpAddress(Callback successCallback, Callback errorCallback) { WritableArray ipList = Arguments.createArray(); try { Enumeration<NetworkInterface> enumNetworkInterfaces = NetworkInterface.getNetworkInterfaces(); while (enumNetworkInterfaces.hasMoreElements()) { NetworkInterface networkInterface = enumNetworkInterfaces.nextElement(); Enumeration<InetAddress> enumInetAddress = networkInterface.getInetAddresses(); while (enumInetAddress.hasMoreElements()) { InetAddress inetAddress = enumInetAddress.nextElement(); if (inetAddress.isSiteLocalAddress()) { ipList.pushString(inetAddress.getHostAddress()); } } } } catch (SocketException e) { Log.e(eTag, "getIpAddress SocketException", e); errorCallback.invoke(e.getMessage()); } successCallback.invoke(ipList); }
Example 3
Source File: ReactNativeJson.java From react-native-couchbase-lite with MIT License | 6 votes |
public static WritableArray convertJsonToArray(JSONArray jsonArray) throws JSONException { WritableArray array = new WritableNativeArray(); for (int i = 0; i < jsonArray.length(); i++) { Object value = jsonArray.get(i); if (value instanceof JSONObject) { array.pushMap(convertJsonToMap((JSONObject) value)); } else if (value instanceof JSONArray) { array.pushArray(convertJsonToArray((JSONArray) value)); } else if (value instanceof Boolean) { array.pushBoolean((Boolean) value); } else if (value instanceof Integer) { array.pushInt((Integer) value); } else if (value instanceof Double) { array.pushDouble((Double) value); } else if (value instanceof String) { array.pushString((String) value); } else { array.pushString(value.toString()); } } return array; }
Example 4
Source File: Utils.java From google-signin with MIT License | 6 votes |
static WritableMap getUserProperties(@NonNull GoogleSignInAccount acct) { Uri photoUrl = acct.getPhotoUrl(); WritableMap user = Arguments.createMap(); user.putString("id", acct.getId()); user.putString("name", acct.getDisplayName()); user.putString("givenName", acct.getGivenName()); user.putString("familyName", acct.getFamilyName()); user.putString("email", acct.getEmail()); user.putString("photo", photoUrl != null ? photoUrl.toString() : null); WritableMap params = Arguments.createMap(); params.putMap("user", user); params.putString("idToken", acct.getIdToken()); params.putString("serverAuthCode", acct.getServerAuthCode()); WritableArray scopes = Arguments.createArray(); for (Scope scope : acct.getGrantedScopes()) { String scopeString = scope.toString(); if (scopeString.startsWith("http")) { scopes.pushString(scopeString); } } params.putArray("scopes", scopes); return params; }
Example 5
Source File: FabricTwitterKitUtils.java From react-native-fabric-twitterkit with MIT License | 6 votes |
private static WritableArray jsonToWritableArray(final JSONArray jsonArray) throws JSONException { final WritableArray writableArray = Arguments.createArray(); for (int i = 0; i < jsonArray.length(); i++) { final Object value = jsonArray.get(i); if (value instanceof Float || value instanceof Double) { writableArray.pushDouble(jsonArray.getDouble(i)); } else if (value instanceof Number) { writableArray.pushInt(jsonArray.getInt(i)); } else if (value instanceof String) { writableArray.pushString(jsonArray.getString(i)); } else if (value instanceof Boolean) { writableArray.pushBoolean(jsonArray.getBoolean(i)); } else if (value instanceof JSONObject) { writableArray.pushMap(jsonToWritableMap(jsonArray.getJSONObject(i))); } else if (value instanceof JSONArray) { writableArray.pushArray(jsonToWritableArray(jsonArray.getJSONArray(i))); } else if (value == JSONObject.NULL) { writableArray.pushNull(); } } return writableArray; }
Example 6
Source File: JsonConvert.java From react-native-cordova with MIT License | 6 votes |
public static WritableArray jsonToReact(JSONArray jsonArray) throws JSONException { WritableArray writableArray = Arguments.createArray(); for(int i=0; i < jsonArray.length(); i++) { Object value = jsonArray.get(i); if (value instanceof Float || value instanceof Double) { writableArray.pushDouble(jsonArray.getDouble(i)); } else if (value instanceof Number) { writableArray.pushInt(jsonArray.getInt(i)); } else if (value instanceof String) { writableArray.pushString(jsonArray.getString(i)); } else if (value instanceof JSONObject) { writableArray.pushMap(jsonToReact(jsonArray.getJSONObject(i))); } else if (value instanceof JSONArray){ writableArray.pushArray(jsonToReact(jsonArray.getJSONArray(i))); } else if (value == JSONObject.NULL){ writableArray.pushNull(); } } return writableArray; }
Example 7
Source File: ReactNativeJson.java From react-native-fcm with MIT License | 6 votes |
public static WritableArray convertJsonToArray(JSONArray jsonArray) throws JSONException { WritableArray array = new WritableNativeArray(); for (int i = 0; i < jsonArray.length(); i++) { Object value = jsonArray.get(i); if (value instanceof JSONObject) { array.pushMap(convertJsonToMap((JSONObject) value)); } else if (value instanceof JSONArray) { array.pushArray(convertJsonToArray((JSONArray) value)); } else if (value instanceof Boolean) { array.pushBoolean((Boolean) value); } else if (value instanceof Integer) { array.pushInt((Integer) value); } else if (value instanceof Double) { array.pushDouble((Double) value); } else if (value instanceof String) { array.pushString((String) value); } else { array.pushString(value.toString()); } } return array; }
Example 8
Source File: RNInstabugReactnativeModuleTest.java From Instabug-React-Native with MIT License | 6 votes |
@Test public void givenCallback$getTags_whenQuery_thenShouldCallNativeApiAndInvokeCallback() { // given PowerMockito.mockStatic(Instabug.class); PowerMockito.mockStatic(Arguments.class); Callback callback = mock(Callback.class); // when ArrayList<String> tags = new ArrayList<>(); tags.add("tag1"); tags.add("tag2"); PowerMockito.when(Instabug.getTags()).thenReturn(tags); PowerMockito.when(Arguments.createArray()).thenReturn(new JavaOnlyArray()); rnModule.getTags(callback); // then PowerMockito.verifyStatic(VerificationModeFactory.times(1)); Instabug.getTags(); WritableArray expectedArray = new JavaOnlyArray(); expectedArray.pushString("tag1"); expectedArray.pushString("tag2"); verify(callback).invoke(expectedArray); }
Example 9
Source File: InAppBillingBridge.java From react-native-billing with MIT License | 5 votes |
@ReactMethod public void listOwnedProducts(final Promise promise){ if (bp != null) { List<String> purchasedProductIds = bp.listOwnedProducts(); WritableArray arr = Arguments.createArray(); for (int i = 0; i < purchasedProductIds.size(); i++) { arr.pushString(purchasedProductIds.get(i)); } promise.resolve(arr); } else { promise.reject("EUNSPECIFIED", "Channel is not opened. Call open() on InAppBilling."); } }
Example 10
Source File: ResponseUtil.java From react-native-GPay with MIT License | 5 votes |
public static void onDataReceived( RCTDeviceEventEmitter eventEmitter, int requestId, String data) { WritableArray args = Arguments.createArray(); args.pushInt(requestId); args.pushString(data); eventEmitter.emit("didReceiveNetworkData", args); }
Example 11
Source File: Utils.java From magnet-client with Mozilla Public License 2.0 | 5 votes |
@Nullable public static WritableArray jsonArrayToWritableArray(JSONArray jsonArray) { WritableArray writableArray = new WritableNativeArray(); if (jsonArray == null) { return null; } if (jsonArray.length() <= 0) { return null; } for (int i = 0 ; i < jsonArray.length(); i++) { try { Object value = jsonArray.get(i); if (value == null) { writableArray.pushNull(); } else if (value instanceof Boolean) { writableArray.pushBoolean((Boolean) value); } else if (value instanceof Integer) { writableArray.pushInt((Integer) value); } else if (value instanceof Double) { writableArray.pushDouble((Double) value); } else if (value instanceof String) { writableArray.pushString((String) value); } else if (value instanceof JSONObject) { writableArray.pushMap(jsonToWritableMap((JSONObject) value)); } else if (value instanceof JSONArray) { writableArray.pushArray(jsonArrayToWritableArray((JSONArray) value)); } } catch (JSONException e) { // Do nothing and fail silently } } return writableArray; }
Example 12
Source File: ArrayUtil.java From react-native-background-geolocation with Apache License 2.0 | 5 votes |
public static WritableArray toWritableArray(Object[] array) { WritableArray writableArray = Arguments.createArray(); for (int i = 0; i < array.length; i++) { Object value = array[i]; if (value == null) { writableArray.pushNull(); } if (value instanceof Boolean) { writableArray.pushBoolean((Boolean) value); } if (value instanceof Double) { writableArray.pushDouble((Double) value); } if (value instanceof Integer) { writableArray.pushInt((Integer) value); } if (value instanceof String) { writableArray.pushString((String) value); } if (value instanceof Map) { writableArray.pushMap(MapUtil.toWritableMap((Map<String, Object>) value)); } if (value.getClass().isArray()) { writableArray.pushArray(ArrayUtil.toWritableArray((Object[]) value)); } } return writableArray; }
Example 13
Source File: ArrayUtil.java From Instabug-React-Native with MIT License | 5 votes |
public static WritableArray toWritableArray(Object[] array) { WritableArray writableArray = Arguments.createArray(); for (int i = 0; i < array.length; i++) { Object value = array[i]; if (value == null) { writableArray.pushNull(); } if (value instanceof Boolean) { writableArray.pushBoolean((Boolean) value); } if (value instanceof Double) { writableArray.pushDouble((Double) value); } if (value instanceof Integer) { writableArray.pushInt((Integer) value); } if (value instanceof String) { writableArray.pushString((String) value); } if (value instanceof Map) { writableArray.pushMap(MapUtil.toWritableMap((Map<String, Object>) value)); } if (value.getClass().isArray()) { writableArray.pushArray(ArrayUtil.toWritableArray((Object[]) value)); } } return writableArray; }
Example 14
Source File: RNDefaultPreferenceModule.java From react-native-default-preference with MIT License | 5 votes |
@ReactMethod public void getMultiple(ReadableArray keys, Promise promise) { WritableArray result = Arguments.createArray(); for(int i = 0; i < keys.size(); i++) { result.pushString(getPreferences().getString(keys.getString(i), null)); } promise.resolve(result); }
Example 15
Source File: NetworkRecordingModuleMock.java From react-native-GPay with MIT License | 5 votes |
private void onDataReceived(int requestId, String data) { WritableArray args = Arguments.createArray(); args.pushInt(requestId); args.pushString(data); getEventEmitter().emit("didReceiveNetworkData", args); }
Example 16
Source File: RNOtpVerifyModule.java From react-native-otp-verify with MIT License | 5 votes |
@ReactMethod public void getHash(Promise promise) { try { AppSignatureHelper helper = new AppSignatureHelper(reactContext); ArrayList<String> signatures = helper.getAppSignatures(); WritableArray arr = Arguments.createArray(); for (String s : signatures) { arr.pushString(s); } promise.resolve(arr); } catch (Exception e) { promise.reject(e); } }
Example 17
Source File: Utils.java From photo-viewer with Apache License 2.0 | 5 votes |
@Nullable public static WritableArray jsonArrayToWritableArray(JSONArray jsonArray) { WritableArray writableArray = new WritableNativeArray(); if (jsonArray == null) { return null; } if (jsonArray.length() <= 0) { return null; } for (int i = 0; i < jsonArray.length(); i++) { try { Object value = jsonArray.get(i); if (value == null) { writableArray.pushNull(); } else if (value instanceof Boolean) { writableArray.pushBoolean((Boolean) value); } else if (value instanceof Integer) { writableArray.pushInt((Integer) value); } else if (value instanceof Double) { writableArray.pushDouble((Double) value); } else if (value instanceof String) { writableArray.pushString((String) value); } else if (value instanceof JSONObject) { writableArray.pushMap(jsonToWritableMap((JSONObject) value)); } else if (value instanceof JSONArray) { writableArray.pushArray(jsonArrayToWritableArray((JSONArray) value)); } } catch (JSONException e) { // Do nothing and fail silently } } return writableArray; }
Example 18
Source File: RNTextSizeModule.java From react-native-text-size with BSD 2-Clause "Simplified" License | 5 votes |
@SuppressWarnings("unused") @ReactMethod public void fontFamilyNames(final Promise promise) { final boolean lollipop = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; final WritableArray names = Arguments.createArray(); names.pushString("sans-serif"); names.pushString("sans-serif-condensed"); if (lollipop) { names.pushString("sans-serif-thin"); names.pushString("sans-serif-light"); names.pushString("sans-serif-medium"); names.pushString("sans-serif-black"); names.pushString("sans-serif-smallcaps"); names.pushString("sans-serif-condensed-light"); } else { // SDK 16 names.pushString("sans-serif-light"); } names.pushString("serif"); names.pushString("monospace"); if (lollipop) { names.pushString("serif-monospace"); names.pushString("casual"); names.pushString("cursive"); } getFontsInAssets(names); promise.resolve(names); }
Example 19
Source File: ReportUtil.java From Instabug-React-Native with MIT License | 5 votes |
public static WritableArray parseConsoleLogs(ArrayList<a> consoleLogs) { WritableArray writableArray = new WritableNativeArray(); for(int i = 0; i < consoleLogs.size(); i++) { try { writableArray.pushString(consoleLogs.get(i).toJson()); } catch (JSONException e) { e.printStackTrace(); } } return writableArray; }
Example 20
Source File: InAppBillingBridge.java From react-native-billing with MIT License | 5 votes |
@ReactMethod public void listOwnedSubscriptions(final Promise promise){ if (bp != null) { List<String> ownedSubscriptionsIds = bp.listOwnedSubscriptions(); WritableArray arr = Arguments.createArray(); for (int i = 0; i < ownedSubscriptionsIds.size(); i++) { arr.pushString(ownedSubscriptionsIds.get(i)); } promise.resolve(arr); } else { promise.reject("EUNSPECIFIED", "Channel is not opened. Call open() on InAppBilling."); } }