com.facebook.react.bridge.WritableArray Java Examples
The following examples show how to use
com.facebook.react.bridge.WritableArray.
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: 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 #2
Source File: CatalystNativeJavaToJSArgumentsTestCase.java From react-native-GPay with MIT License | 6 votes |
public void testStringWithMultibyteUTF8Characters() { TestJavaToJSArgumentsModule jsModule = mInstance.getJSModule(TestJavaToJSArgumentsModule.class); WritableNativeMap map = new WritableNativeMap(); map.putString("two-bytes", "\u00A2"); map.putString("three-bytes", "\u20AC"); map.putString("four-bytes", "\uD83D\uDE1C"); map.putString( "mixed", "\u017C\u00F3\u0142\u0107 g\u0119\u015Bl\u0105 \u6211 \uD83D\uDE0E ja\u017A\u0107"); jsModule.receiveMapWithMultibyteUTF8CharacterString(map); waitForBridgeAndUIIdle(); mAssertModule.verifyAssertsAndReset(); WritableArray array = new WritableNativeArray(); array.pushString("\u00A2"); array.pushString("\u20AC"); array.pushString("\uD83D\uDE1C"); array.pushString( "\u017C\u00F3\u0142\u0107 g\u0119\u015Bl\u0105 \u6211 \uD83D\uDE0E ja\u017A\u0107"); jsModule.receiveArrayWithMultibyteUTF8CharacterString(array); waitForBridgeAndUIIdle(); mAssertModule.verifyAssertsAndReset(); }
Example #3
Source File: RNTextDetectorModule.java From react-native-text-detector with MIT License | 6 votes |
/** * Converts firebaseVisionText into a map * * @param firebaseVisionText * @return */ private WritableArray getDataAsArray(FirebaseVisionText firebaseVisionText) { WritableArray data = Arguments.createArray(); WritableMap info = Arguments.createMap(); WritableMap coordinates = Arguments.createMap(); for (FirebaseVisionText.TextBlock block: firebaseVisionText.getTextBlocks()) { info = Arguments.createMap(); coordinates = Arguments.createMap(); Rect boundingBox = block.getBoundingBox(); coordinates.putInt("top", boundingBox.top); coordinates.putInt("left", boundingBox.left); coordinates.putInt("width", boundingBox.width()); coordinates.putInt("height", boundingBox.height()); info.putMap("bounding", coordinates); info.putString("text", block.getText()); data.pushMap(info); } return data; }
Example #4
Source File: BleManager.java From react-native-ble-manager with Apache License 2.0 | 6 votes |
@ReactMethod public void getConnectedPeripherals(ReadableArray serviceUUIDs, Callback callback) { Log.d(LOG_TAG, "Get connected peripherals"); WritableArray map = Arguments.createArray(); if (getBluetoothAdapter() == null) { Log.d(LOG_TAG, "No bluetooth support"); callback.invoke("No bluetooth support"); return; } List<BluetoothDevice> periperals = getBluetoothManager().getConnectedDevices(GATT); for (BluetoothDevice entry : periperals) { Peripheral peripheral = savePeripheral(entry); WritableMap jsonBundle = peripheral.asWritableMap(); map.pushMap(jsonBundle); } callback.invoke(null, map); }
Example #5
Source File: ReactExoplayerView.java From react-native-video with MIT License | 6 votes |
private WritableArray getAudioTrackInfo() { WritableArray audioTracks = Arguments.createArray(); MappingTrackSelector.MappedTrackInfo info = trackSelector.getCurrentMappedTrackInfo(); int index = getTrackRendererIndex(C.TRACK_TYPE_AUDIO); if (info == null || index == C.INDEX_UNSET) { return audioTracks; } TrackGroupArray groups = info.getTrackGroups(index); for (int i = 0; i < groups.length; ++i) { Format format = groups.get(i).getFormat(0); WritableMap audioTrack = Arguments.createMap(); audioTrack.putInt("index", i); audioTrack.putString("title", format.id != null ? format.id : ""); audioTrack.putString("type", format.sampleMimeType); audioTrack.putString("language", format.language != null ? format.language : ""); audioTrack.putString("bitrate", format.bitrate == Format.NO_VALUE ? "" : String.format(Locale.US, "%.2fMbps", format.bitrate / 1000000f)); audioTracks.pushMap(audioTrack); } return audioTracks; }
Example #6
Source File: RNSecureStorageModule.java From react-native-secure-storage with MIT License | 6 votes |
@ReactMethod public void getAllKeys(String service, Promise promise) { try { service = getDefaultServiceIfNull(service); final PrefsStorage prefsStorage = new PrefsStorage(getReactApplicationContext(), service); String[] allKeys = prefsStorage.getAllKeys(); WritableArray keyArray = new WritableNativeArray(); for (String key : allKeys) { keyArray.pushString(key); } promise.resolve(keyArray); return; } catch (Exception e) { Log.e(SECURE_STORAGE_MODULE, e.getMessage()); promise.reject(E_KEYSTORE_ACCESS_ERROR, e); } }
Example #7
Source File: ContactsManager.java From react-native-contacts with MIT License | 6 votes |
/** * Retrieves contacts matching a phone number. * Uses raw URI when <code>rawUri</code> is <code>true</code>, makes assets copy otherwise. * * @param phoneNumber phone number to match * @param callback user provided callback to run at completion */ @ReactMethod public void getContactsByPhoneNumber(final String phoneNumber, final Callback callback) { AsyncTask<Void,Void,Void> myAsyncTask = new AsyncTask<Void,Void,Void>() { @Override protected Void doInBackground(final Void ... params) { Context context = getReactApplicationContext(); ContentResolver cr = context.getContentResolver(); ContactsProvider contactsProvider = new ContactsProvider(cr); WritableArray contacts = contactsProvider.getContactsByPhoneNumber(phoneNumber); callback.invoke(null, contacts); return null; } }; myAsyncTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); }
Example #8
Source File: BeaconsAndroidModule.java From react-native-beacons-android with MIT License | 6 votes |
private WritableMap createRangingResponse(Collection<Beacon> beacons, Region region) { WritableMap map = new WritableNativeMap(); map.putString("identifier", region.getUniqueId()); map.putString("uuid", region.getId1() != null ? region.getId1().toString() : ""); WritableArray a = new WritableNativeArray(); for (Beacon beacon : beacons) { WritableMap b = new WritableNativeMap(); b.putString("uuid", beacon.getId1().toString()); b.putInt("major", beacon.getId2().toInt()); b.putInt("minor", beacon.getId3().toInt()); b.putInt("rssi", beacon.getRssi()); b.putDouble("distance", beacon.getDistance()); b.putString("proximity", getProximity(beacon.getDistance())); a.pushMap(b); } map.putArray("beacons", a); return map; }
Example #9
Source File: ReactVideoView.java From react-native-video with MIT License | 6 votes |
public void onTimedMetaDataAvailable(MediaPlayer mp, TimedMetaData data) { WritableMap event = Arguments.createMap(); try { String rawMeta = new String(data.getMetaData(), "UTF-8"); WritableMap id3 = Arguments.createMap(); id3.putString(EVENT_PROP_METADATA_VALUE, rawMeta.substring(rawMeta.lastIndexOf("\u0003") + 1)); id3.putString(EVENT_PROP_METADATA_IDENTIFIER, "id3/TDEN"); WritableArray metadata = new WritableNativeArray(); metadata.pushMap(id3); event.putArray(EVENT_PROP_METADATA, metadata); event.putDouble(EVENT_PROP_TARGET, getId()); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } mEventEmitter.receiveEvent(getId(), Events.EVENT_TIMED_METADATA.toString(), event); }
Example #10
Source File: RNInstabugFeatureRequestsModuleTest.java From Instabug-React-Native with MIT License | 6 votes |
/********Feature Requests*********/ @Test public void givenArgs$setEmailFieldRequiredForFeatureRequests_whenQuery_thenShouldCallNativeApi() { // given PowerMockito.mockStatic(FeatureRequests.class); PowerMockito.mockStatic(Arguments.class); // when PowerMockito.when(Arguments.createArray()).thenReturn(new JavaOnlyArray()); ReadableArray actionTypes = Arguments.createArray(); ((WritableArray) actionTypes).pushString("requestNewFeature"); ((WritableArray) actionTypes).pushString("addCommentToFeature"); featureRequestsModule.setEmailFieldRequiredForFeatureRequests(true, actionTypes ); int[] parsedActionTypes = new int[2]; parsedActionTypes[0] = ActionType.REQUEST_NEW_FEATURE; parsedActionTypes[1] = ActionType.ADD_COMMENT_TO_FEATURE; // then PowerMockito.verifyStatic(VerificationModeFactory.times(1)); FeatureRequests.setEmailFieldRequired(true, parsedActionTypes); }
Example #11
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 #12
Source File: RNUtils.java From react-native-batch-push with MIT License | 6 votes |
public static WritableArray convertArrayToWritableArray(Object[] input) { WritableArray output = new WritableNativeArray(); for (int i = 0; i < input.length; i++) { Object value = input[i]; if (value instanceof Map) { output.pushMap(convertMapToWritableMap((Map<String, Object>) value)); } else if (value instanceof JSONArray) { output.pushArray(convertArrayToWritableArray((Object[]) value)); } else if (value instanceof Boolean) { output.pushBoolean((Boolean) value); } else if (value instanceof Integer) { output.pushInt((Integer) value); } else if (value instanceof Double) { output.pushDouble((Double) value); } else if (value instanceof String) { output.pushString((String) value); } else { output.pushString(value.toString()); } } return output; }
Example #13
Source File: ReactNativeOBD2Module.java From react-native-obd2 with MIT License | 6 votes |
@ReactMethod public void getBluetoothDeviceName(Promise aPromise) { if (mOBD2Handler == null) { mOBD2Handler = new OBD2Handler(mReactContext); } try { Set<BluetoothDevice> pairedDevices = mOBD2Handler.getBondedDevices(); WritableArray deviceList = mArguments.createArray(); if (pairedDevices.size() > 0) { for (BluetoothDevice device : pairedDevices) { WritableMap map = mArguments.createMap(); map.putString("name", device.getName()); map.putString("address", device.getAddress()); deviceList.pushMap(map); } } aPromise.resolve(deviceList); } catch (IOException e) { e.printStackTrace(); aPromise.reject(TAG, e); } }
Example #14
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 #15
Source File: ContactsProvider.java From react-native-contacts with MIT License | 6 votes |
public WritableArray getContactsByEmailAddress(String emailAddress) { Map<String, Contact> matchingContacts; { Cursor cursor = contentResolver.query( ContactsContract.Data.CONTENT_URI, FULL_PROJECTION.toArray(new String[FULL_PROJECTION.size()]), ContactsContract.CommonDataKinds.Email.ADDRESS + " LIKE ?", new String[]{"%" + emailAddress + "%"}, null ); try { matchingContacts = loadContactsFrom(cursor); } finally { if (cursor != null) { cursor.close(); } } } WritableArray contacts = Arguments.createArray(); for (Contact contact : matchingContacts.values()) { contacts.pushMap(contact.toMap()); } return contacts; }
Example #16
Source File: StepHistory.java From react-native-google-fit with MIT License | 6 votes |
private void processDataSet(DataSet dataSet, WritableArray map) { //Log.i(TAG, "Data returned for Data type: " + dataSet.getDataType().getName()); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); dateFormat.setTimeZone(TimeZone.getDefault()); WritableMap stepMap = Arguments.createMap(); for (DataPoint dp : dataSet.getDataPoints()) { Log.i(TAG, "\tData point:"); Log.i(TAG, "\t\tType : " + dp.getDataType().getName()); Log.i(TAG, "\t\tStart: " + dateFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS))); Log.i(TAG, "\t\tEnd : " + dateFormat.format(dp.getEndTime(TimeUnit.MILLISECONDS))); for(Field field : dp.getDataType().getFields()) { Log.i(TAG, "\t\tField: " + field.getName() + " Value: " + dp.getValue(field)); stepMap.putDouble("startDate", dp.getStartTime(TimeUnit.MILLISECONDS)); stepMap.putDouble("endDate", dp.getEndTime(TimeUnit.MILLISECONDS)); stepMap.putDouble("steps", dp.getValue(field).asInt()); map.pushMap(stepMap); } } }
Example #17
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 #18
Source File: speechModule.java From react-native-speech with MIT License | 6 votes |
/*** * This method will expose all the available languages in TTS engine * * @param callback */ @ReactMethod public void getLocale(final Callback callback) { new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) { @Override protected void doInBackgroundGuarded(Void... params) { try { if (tts == null) { init(); } Locale[] locales = Locale.getAvailableLocales(); WritableArray data = Arguments.createArray(); for (Locale locale : locales) { int res = tts.isLanguageAvailable(locale); if (res == TextToSpeech.LANG_COUNTRY_AVAILABLE) { data.pushString(locale.getLanguage()); } } callback.invoke(null, data); } catch (Exception e) { callback.invoke(e.getMessage()); } } }.execute(); }
Example #19
Source File: ContactsManager.java From react-native-contacts with MIT License | 6 votes |
/** * Retrieves contacts matching String. * Uses raw URI when <code>rawUri</code> is <code>true</code>, makes assets copy otherwise. * * @param searchString String to match * @param callback user provided callback to run at completion */ @ReactMethod public void getContactsMatchingString(final String searchString, final Callback callback) { AsyncTask<Void,Void,Void> myAsyncTask = new AsyncTask<Void,Void,Void>() { @Override protected Void doInBackground(final Void ... params) { Context context = getReactApplicationContext(); ContentResolver cr = context.getContentResolver(); ContactsProvider contactsProvider = new ContactsProvider(cr); WritableArray contacts = contactsProvider.getContactsMatchingString(searchString); callback.invoke(null, contacts); return null; } }; myAsyncTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); }
Example #20
Source File: SelectContactModule.java From react-native-select-contact with MIT License | 5 votes |
private void addPhoneEntry(WritableArray phones, Cursor cursor, Activity activity) { String phoneNumber = cursor.getString(cursor.getColumnIndex(Phone.NUMBER)); int phoneType = cursor.getInt(cursor.getColumnIndex(Phone.TYPE)); String phoneLabel = cursor.getString(cursor.getColumnIndex(Phone.LABEL)); CharSequence typeLabel = Phone.getTypeLabel(activity.getResources(), phoneType, phoneLabel); WritableMap phoneEntry = Arguments.createMap(); phoneEntry.putString("number", phoneNumber); phoneEntry.putString("type", String.valueOf(typeLabel)); phones.pushMap(phoneEntry); }
Example #21
Source File: InAppBillingBridge.java From react-native-billing with MIT License | 5 votes |
@ReactMethod public void getProductDetails(final ReadableArray productIds, final Promise promise) { if (bp != null) { try { ArrayList<String> productIdList = new ArrayList<>(); for (int i = 0; i < productIds.size(); i++) { productIdList.add(productIds.getString(i)); } List<SkuDetails> details = bp.getPurchaseListingDetails(productIdList); if (details != null) { WritableArray arr = Arguments.createArray(); for (SkuDetails detail : details) { if (detail != null) { WritableMap map = Arguments.createMap(); map.putString("productId", detail.productId); map.putString("title", detail.title); map.putString("description", detail.description); map.putBoolean("isSubscription", detail.isSubscription); map.putString("currency", detail.currency); map.putDouble("priceValue", detail.priceValue); map.putString("priceText", detail.priceText); arr.pushMap(map); } } promise.resolve(arr); } else { promise.reject("EUNSPECIFIED", "Details was not found."); } } catch (Exception ex) { promise.reject("EUNSPECIFIED", "Failure on getting product details: " + ex.getMessage()); } } else { promise.reject("EUNSPECIFIED", "Channel is not opened. Call open() on InAppBilling."); } }
Example #22
Source File: SleepHistory.java From react-native-google-fit with MIT License | 5 votes |
private void processDataSet(DataSet dataSet, Session session, WritableArray map) { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); dateFormat.setTimeZone(TimeZone.getDefault()); for (DataPoint dp : dataSet.getDataPoints()) { WritableMap sleepMap = Arguments.createMap(); sleepMap.putString("value", dp.getValue(Field.FIELD_ACTIVITY).asActivity()); sleepMap.putString("startDate", dateFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS))); sleepMap.putString("endDate", dateFormat.format(dp.getEndTime(TimeUnit.MILLISECONDS))); map.pushMap(sleepMap); } }
Example #23
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 #24
Source File: RNUnifiedContactsModule.java From react-native-unified-contacts with MIT License | 5 votes |
@NonNull private WritableArray getEmailAddressesFromContact(int contactId) { WritableArray emailAddresses = Arguments.createArray(); Cursor emailAddressesCursor = contentResolver.query( ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = " + contactId, null, null); while (emailAddressesCursor.moveToNext()) { WritableMap emailAddress = Arguments.createMap(); String value = getStringFromCursor( emailAddressesCursor, ContactsContract.CommonDataKinds.Email.ADDRESS ); String label = getStringFromCursor( emailAddressesCursor, ContactsContract.CommonDataKinds.Email.LABEL ); int typeInt = getIntFromCursor( emailAddressesCursor, ContactsContract.CommonDataKinds.Email.TYPE ); String type = String.valueOf(ContactsContract.CommonDataKinds.Email.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; emailAddress.putString("value", value); // TODO: Consider standardizing on "address" instead of "value". emailAddress.putString("address", value); // Added in case Android devs are used to accessing it like this. emailAddress.putString("label", label); emailAddress.putString("type", type); emailAddresses.pushMap(emailAddress); } emailAddressesCursor.close(); return emailAddresses; }
Example #25
Source File: CatalystNativeJavaToJSReturnValuesTestCase.java From react-native-GPay with MIT License | 5 votes |
@ReactMethod(isBlockingSynchronousMethod = true) WritableArray getArray() { WritableArray arr = new WritableNativeArray(); arr.pushString("a"); arr.pushBoolean(true); return arr; }
Example #26
Source File: StepHistory.java From react-native-google-fit with MIT License | 5 votes |
private void sendEvent(ReactContext reactContext, String eventName, @Nullable WritableArray params) { reactContext .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) .emit(eventName, params); }
Example #27
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 #28
Source File: UIImplementation.java From react-native-GPay with MIT License | 5 votes |
/** * Replaces the View specified by oldTag with the View specified by newTag within oldTag's parent. */ public void replaceExistingNonRootView(int oldTag, int newTag) { if (mShadowNodeRegistry.isRootNode(oldTag) || mShadowNodeRegistry.isRootNode(newTag)) { throw new IllegalViewOperationException("Trying to add or replace a root tag!"); } ReactShadowNode oldNode = mShadowNodeRegistry.getNode(oldTag); if (oldNode == null) { throw new IllegalViewOperationException("Trying to replace unknown view tag: " + oldTag); } ReactShadowNode parent = oldNode.getParent(); if (parent == null) { throw new IllegalViewOperationException("Node is not attached to a parent: " + oldTag); } int oldIndex = parent.indexOf(oldNode); if (oldIndex < 0) { throw new IllegalStateException("Didn't find child tag in parent"); } WritableArray tagsToAdd = Arguments.createArray(); tagsToAdd.pushInt(newTag); WritableArray addAtIndices = Arguments.createArray(); addAtIndices.pushInt(oldIndex); WritableArray indicesToRemove = Arguments.createArray(); indicesToRemove.pushInt(oldIndex); manageChildren(parent.getReactTag(), null, null, tagsToAdd, addAtIndices, indicesToRemove); }
Example #29
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 #30
Source File: CameraRollManager.java From react-native-GPay with MIT License | 5 votes |
private static void putEdges( ContentResolver resolver, Cursor photos, WritableMap response, int limit, @Nullable String assetType) { WritableArray edges = new WritableNativeArray(); photos.moveToFirst(); int idIndex = photos.getColumnIndex(Images.Media._ID); int mimeTypeIndex = photos.getColumnIndex(Images.Media.MIME_TYPE); int groupNameIndex = photos.getColumnIndex(Images.Media.BUCKET_DISPLAY_NAME); int dateTakenIndex = photos.getColumnIndex(Images.Media.DATE_TAKEN); int widthIndex = IS_JELLY_BEAN_OR_LATER ? photos.getColumnIndex(Images.Media.WIDTH) : -1; int heightIndex = IS_JELLY_BEAN_OR_LATER ? photos.getColumnIndex(Images.Media.HEIGHT) : -1; int longitudeIndex = photos.getColumnIndex(Images.Media.LONGITUDE); int latitudeIndex = photos.getColumnIndex(Images.Media.LATITUDE); for (int i = 0; i < limit && !photos.isAfterLast(); i++) { WritableMap edge = new WritableNativeMap(); WritableMap node = new WritableNativeMap(); boolean imageInfoSuccess = putImageInfo(resolver, photos, node, idIndex, widthIndex, heightIndex, assetType); if (imageInfoSuccess) { putBasicNodeInfo(photos, node, mimeTypeIndex, groupNameIndex, dateTakenIndex); putLocationInfo(photos, node, longitudeIndex, latitudeIndex); edge.putMap("node", node); edges.pushMap(edge); } else { // we skipped an image because we couldn't get its details (e.g. width/height), so we // decrement i in order to correctly reach the limit, if the cursor has enough rows i--; } photos.moveToNext(); } response.putArray("edges", edges); }