Java Code Examples for com.facebook.react.bridge.WritableMap
The following examples show how to use
com.facebook.react.bridge.WritableMap. These examples are extracted from open source projects.
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 Project: react-native-GPay Source File: ImageLoaderModule.java License: MIT License | 7 votes |
@ReactMethod public void queryCache(final ReadableArray uris, final Promise promise) { // perform cache interrogation in async task as disk cache checks are expensive new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) { @Override protected void doInBackgroundGuarded(Void... params) { WritableMap result = Arguments.createMap(); ImagePipeline imagePipeline = Fresco.getImagePipeline(); for (int i = 0; i < uris.size(); i++) { String uriString = uris.getString(i); final Uri uri = Uri.parse(uriString); if (imagePipeline.isInBitmapMemoryCache(uri)) { result.putString(uriString, "memory"); } else if (imagePipeline.isInDiskCacheSync(uri)) { result.putString(uriString, "disk"); } } promise.resolve(result); } }.executeOnExecutor(GuardedAsyncTask.THREAD_POOL_EXECUTOR); }
Example 2
Source Project: rn-floating-video-widget Source File: FloatingVideoWidgetShowService.java License: MIT License | 6 votes |
public void returnToApp(View view) { long seek = videoView.getCurrentPosition(); Intent intent = getPackageManager().getLaunchIntentForPackage(reactContext.getPackageName()); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); videoView.setKeepScreenOn(false); stopSelf(); WritableMap args = new Arguments().createMap(); args.putInt("index", index); args.putInt("seek", (int) seek); args.putString("type", "close"); args.putString("url", playingVideo.getString("url")); sendEvent(reactContext, "onClose", args); onDestroy(); }
Example 3
Source Project: Instabug-React-Native Source File: RNInstabugBugReportingModule.java License: MIT License | 6 votes |
/** * Sets a block of code to be executed right after the SDK's UI is dismissed. * This block is executed on the UI thread. Could be used for performing any * UI changes after the SDK's UI is dismissed. * * @param handler - A callback to get executed after * dismissing the SDK. */ @ReactMethod public void setOnSDKDismissedHandler(final Callback handler) { MainThreadHandler.runOnMainThread(new Runnable() { @Override public void run() { try { BugReporting.setOnDismissCallback(new OnSdkDismissCallback() { @Override public void call(DismissType dismissType, ReportType reportType) { WritableMap params = Arguments.createMap(); params.putString("dismissType", dismissType.toString()); params.putString("reportType", reportType.toString()); InstabugUtil.sendEvent(getReactApplicationContext(), Constants.IBG_POST_INVOCATION_HANDLER, params); } }); } catch (java.lang.Exception exception) { exception.printStackTrace(); } } }); }
Example 4
Source Project: react-native-google-nearby-connection Source File: NearbyConnectionModule.java License: MIT License | 6 votes |
@Override public void onReceive(Context context, Intent intent) { if (getReactApplicationContext().hasActiveCatalystInstance()) { String serviceId = intent.getStringExtra("serviceId"); String endpointId = intent.getStringExtra("endpointId"); int payloadType = intent.getIntExtra("payloadType", -1); String payloadId = intent.getStringExtra("payloadId"); WritableMap out = Arguments.createMap(); out.putString("serviceId", serviceId); out.putString("endpointId", endpointId); out.putInt("payloadType", payloadType); out.putString("payloadId", payloadId); if (payloadType == Payload.Type.FILE) { long payloadSize = intent.getLongExtra("payloadSize", -1); out.putDouble("payloadSize", payloadSize); } sendEvent(getReactApplicationContext(), "receive_payload", out); } }
Example 5
Source Project: react-native-GPay Source File: WebSocketModule.java License: MIT License | 6 votes |
@ReactMethod public void ping(int id) { WebSocket client = mWebSocketConnections.get(id); if (client == null) { // This is a programmer error -- display development warning WritableMap params = Arguments.createMap(); params.putInt("id", id); params.putString("message", "client is null"); sendEvent("websocketFailed", params); params = Arguments.createMap(); params.putInt("id", id); params.putInt("code", 0); params.putString("reason", "client is null"); sendEvent("websocketClosed", params); mWebSocketConnections.remove(id); mContentHandlers.remove(id); return; } try { client.send(ByteString.EMPTY); } catch (Exception e) { notifyWebSocketFailed(id, e.getMessage()); } }
Example 6
Source Project: react-native-orientation-locker Source File: OrientationModule.java License: MIT License | 6 votes |
@ReactMethod public void lockToLandscapeLeft() { final Activity activity = getCurrentActivity(); if (activity == null) return; activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); isLocked = true; // force send an UI orientation event lastOrientationValue = "LANDSCAPE-LEFT"; WritableMap params = Arguments.createMap(); params.putString("orientation", lastOrientationValue); if (ctx.hasActiveCatalystInstance()) { ctx .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) .emit("orientationDidChange", params); } // send a locked event WritableMap lockParams = Arguments.createMap(); lockParams.putString("orientation", lastOrientationValue); if (ctx.hasActiveCatalystInstance()) { ctx .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) .emit("lockDidChange", lockParams); } }
Example 7
Source Project: opentok-react-native Source File: OTSessionManager.java License: MIT License | 6 votes |
@Override public void onVideoDisabled(SubscriberKit subscriber, String reason) { String streamId = Utils.getStreamIdBySubscriber(subscriber); if (streamId.length() > 0) { ConcurrentHashMap<String, Stream> streams = sharedState.getSubscriberStreams(); Stream mStream = streams.get(streamId); WritableMap subscriberInfo = Arguments.createMap(); if (mStream != null) { subscriberInfo.putMap("stream", EventUtils.prepareJSStreamMap(mStream, subscriber.getSession())); } subscriberInfo.putString("reason", reason); sendEventMap(this.getReactApplicationContext(), subscriberPreface + "onVideoDisabled", subscriberInfo); } printLogs("onVideoDisabled " + reason); }
Example 8
Source Project: react-native-orientation-locker Source File: OrientationModule.java License: MIT License | 6 votes |
@ReactMethod public void lockToPortraitUpsideDown() { final Activity activity = getCurrentActivity(); if (activity == null) return; activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); isLocked = true; // force send an UI orientation event lastOrientationValue = "PORTRAIT-UPSIDEDOWN"; WritableMap params = Arguments.createMap(); params.putString("orientation", lastOrientationValue); if (ctx.hasActiveCatalystInstance()) { ctx .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) .emit("orientationDidChange", params); } // send a locked event WritableMap lockParams = Arguments.createMap(); lockParams.putString("orientation", lastOrientationValue); if (ctx.hasActiveCatalystInstance()) { ctx .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) .emit("lockDidChange", lockParams); } }
Example 9
Source Project: google-signin Source File: RNGoogleSigninModule.java License: MIT License | 6 votes |
private void handleException(RNGoogleSigninModule moduleInstance, Exception cause, WritableMap userProperties, @Nullable WritableMap settings) { boolean isRecoverable = cause instanceof UserRecoverableAuthException; if (isRecoverable) { boolean shouldRecover = settings != null && settings.hasKey(SHOULD_RECOVER) && settings.getBoolean(SHOULD_RECOVER); if (shouldRecover) { attemptRecovery(moduleInstance, cause, userProperties); } else { moduleInstance.promiseWrapper.reject(ERROR_USER_RECOVERABLE_AUTH, cause); } } else { moduleInstance.promiseWrapper.reject(MODULE_NAME, cause); } }
Example 10
Source Project: opentok-react-native Source File: OTSessionManager.java License: MIT License | 6 votes |
@Override public void onStreamVideoDimensionsChanged(Session session, Stream stream, int width, int height) { ConcurrentHashMap<String, Stream> mSubscriberStreams = sharedState.getSubscriberStreams(); Stream mStream = mSubscriberStreams.get(stream.getStreamId()); WritableMap oldVideoDimensions = Arguments.createMap(); if ( mStream != null ){ oldVideoDimensions.putInt("height", mStream.getVideoHeight()); oldVideoDimensions.putInt("width", mStream.getVideoWidth()); } WritableMap newVideoDimensions = Arguments.createMap(); newVideoDimensions.putInt("height", height); newVideoDimensions.putInt("width", width); WritableMap eventData = EventUtils.prepareStreamPropertyChangedEventData("videoDimensions", oldVideoDimensions, newVideoDimensions, stream, session); sendEventMap(this.getReactApplicationContext(), session.getSessionId() + ":" + sessionPreface + "onStreamPropertyChanged", eventData); printLogs("onStreamVideoDimensionsChanged"); }
Example 11
Source Project: react-native-google-nearby-connection Source File: NearbyConnectionModule.java License: MIT License | 6 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"); String authenticationToken = intent.getStringExtra("authenticationToken"); Boolean incomingConnection = intent.getBooleanExtra("incomingConnection", false); WritableMap out = Arguments.createMap(); out.putString("endpointId", endpointId); out.putString("endpointName", endpointName); out.putString("serviceId", serviceId); out.putString("authenticationToken", authenticationToken); out.putBoolean("incomingConnection", incomingConnection); sendEvent(getReactApplicationContext(), "connection_initiated_to_endpoint", out); } }
Example 12
Source Project: react-native-GPay Source File: ImageLoadEvent.java License: MIT License | 6 votes |
@Override public void dispatch(RCTEventEmitter rctEventEmitter) { WritableMap eventData = null; if (mImageUri != null || mEventType == ON_LOAD) { eventData = Arguments.createMap(); if (mImageUri != null) { eventData.putString("uri", mImageUri); } if (mEventType == ON_LOAD) { WritableMap source = Arguments.createMap(); source.putDouble("width", mWidth); source.putDouble("height", mHeight); if (mImageUri != null) { source.putString("url", mImageUri); } eventData.putMap("source", source); } } rctEventEmitter.receiveEvent(getViewTag(), getEventName(), eventData); }
Example 13
Source Project: Instabug-React-Native Source File: RNInstabugReactnativeModuleTest.java License: MIT License | 6 votes |
@Test public void givenCallback$getAllUserAttributes_whenQuery_thenShouldCallNativeApiAndInvokeCallback() { // given PowerMockito.mockStatic(Instabug.class); PowerMockito.mockStatic(Arguments.class); Callback callback = mock(Callback.class); // when HashMap<String, String> userAttributes = new HashMap<>(); userAttributes.put("email", "[email protected]"); PowerMockito.when(Arguments.createMap()).thenReturn(new JavaOnlyMap()); PowerMockito.when(Instabug.getAllUserAttributes()).thenReturn(userAttributes); rnModule.getAllUserAttributes(callback); // then PowerMockito.verifyStatic(VerificationModeFactory.times(1)); Instabug.getAllUserAttributes(); WritableMap expectedMap = new JavaOnlyMap(); expectedMap.putString("email", "[email protected]"); verify(callback).invoke(expectedMap); }
Example 14
Source Project: react-native-fcm Source File: FIRMessagingModule.java License: MIT License | 6 votes |
private WritableMap parseIntent(Intent intent){ WritableMap params; Bundle extras = intent.getExtras(); if (extras != null) { try { params = Arguments.fromBundle(extras); } catch (Exception e){ Log.e(TAG, e.getMessage()); params = Arguments.createMap(); } } else { params = Arguments.createMap(); } WritableMap fcm = Arguments.createMap(); fcm.putString("action", intent.getAction()); params.putMap("fcm", fcm); params.putInt("opened_from_tray", 1); return params; }
Example 15
Source Project: react-native-fbads Source File: NativeAdView.java License: MIT License | 6 votes |
/** * Called by the view manager when adsManager prop is set. Sends serialised * version of a native ad back to Javascript. * * @param nativeAd */ public void setNativeAd(NativeAd nativeAd) { if (mNativeAd != null) { mNativeAd.unregisterView(); } mNativeAd = nativeAd; if (nativeAd == null) { mEventEmitter.receiveEvent(getId(), "onAdLoaded", null); return; } WritableMap event = Arguments.createMap(); event.putString("headline", nativeAd.getAdHeadline()); event.putString("socialContext", nativeAd.getAdSocialContext()); event.putString("bodyText", nativeAd.getAdBodyText()); event.putString("callToActionText", nativeAd.getAdCallToAction()); event.putString("sponsoredTranslation", nativeAd.getSponsoredTranslation()); event.putString("advertiserName", nativeAd.getAdvertiserName()); event.putString("promotedTranslation", nativeAd.getPromotedTranslation()); event.putString("translation", nativeAd.getAdTranslation()); event.putString("linkDescription", nativeAd.getAdLinkDescription()); mEventEmitter.receiveEvent(getId(), "onAdLoaded", event); }
Example 16
Source Project: react-native-incall-manager Source File: InCallManagerModule.java License: ISC License | 6 votes |
private WritableMap getAudioDeviceStatusMap() { WritableMap data = Arguments.createMap(); String audioDevicesJson = "["; for (AudioDevice s: audioDevices) { audioDevicesJson += "\"" + s.name() + "\","; } // --- strip the last `,` if (audioDevicesJson.length() > 1) { audioDevicesJson = audioDevicesJson.substring(0, audioDevicesJson.length() - 1); } audioDevicesJson += "]"; data.putString("availableAudioDeviceList", audioDevicesJson); data.putString("selectedAudioDevice", (selectedAudioDevice == null) ? "" : selectedAudioDevice.name()); return data; }
Example 17
Source Project: react-native-app-auth Source File: TokenResponseFactory.java License: MIT License | 6 votes |
public static final WritableMap tokenResponseToMap(TokenResponse response, AuthorizationResponse authResponse) { WritableMap map = Arguments.createMap(); map.putString("accessToken", response.accessToken); map.putMap("authorizeAdditionalParameters", MapUtil.createAdditionalParametersMap(authResponse.additionalParameters)); map.putMap("tokenAdditionalParameters", MapUtil.createAdditionalParametersMap(response.additionalParameters)); map.putString("idToken", response.idToken); map.putString("refreshToken", response.refreshToken); map.putString("tokenType", response.tokenType); map.putArray("scopes", createScopeArray(authResponse.scope)); if (response.accessTokenExpirationTime != null) { map.putString("accessTokenExpirationDate", DateUtil.formatTimestamp(response.accessTokenExpirationTime)); } return map; }
Example 18
Source Project: imsdk-android Source File: QimRNBModule.java License: MIT License | 6 votes |
/** * 获取指定联系人nick * * @param xmppId * @param callback */ @ReactMethod public void getContactsNick(String xmppId, final Callback callback) { ConnectionUtil.getInstance().getUserCard(xmppId, new IMLogicManager.NickCallBack() { @Override public void onNickCallBack(Nick nick) { WritableNativeMap item = new WritableNativeMap(); String name = nick.getName(); String pinyin = nick.getXmppId(); if (!TextUtils.isEmpty(name)) { pinyin = HanziToPinyin.zh2Abb(name); } item.putString("Name", TextUtils.isEmpty(name) ? nick.getXmppId() : name); item.putString("HeaderUri", TextUtils.isEmpty(nick.getHeaderSrc()) ? "" : nick.getHeaderSrc()); item.putString("SearchIndex", pinyin); item.putString("XmppId", nick.getXmppId()); item.putString("Remark", nick.getMark()); item.putString("Mood",nick.getMood()); WritableMap map = new WritableNativeMap(); map.putMap("nick", item); callback.invoke(map); } }, true, false); }
Example 19
Source Project: react-native-twilio-ip-messaging Source File: RCTConvert.java License: MIT License | 6 votes |
public static WritableMap Member(Member member) { WritableMap map = Arguments.createMap(); map.putMap("userInfo", UserInfo(member.getUserInfo())); if (member.getLastConsumedMessageIndex() == null) { map.putNull("lastConsumedMessageIndex"); } else { map.putInt("lastConsumedMessageIndex", member.getLastConsumedMessageIndex().intValue()); } if (member.getLastConsumptionTimestamp() == null) { map.putNull("lastConsumptionTimestamp"); } else { map.putString("lastConsumptionTimestamp", member.getLastConsumptionTimestamp()); } return map; }
Example 20
Source Project: react-native-ble-manager Source File: BleManager.java License: 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 21
Source Project: react-native-fused-location Source File: FusedLocationModule.java License: MIT License | 6 votes |
private WritableMap convertLocationToJSON(Location l) { WritableMap params = new WritableNativeMap(); params.putDouble("latitude", l.getLatitude()); params.putDouble("longitude", l.getLongitude()); params.putDouble("accuracy", l.getAccuracy()); params.putDouble("altitude", l.getAltitude()); params.putDouble("bearing", l.getBearing()); params.putString("provider", l.getProvider()); params.putDouble("speed", l.getSpeed()); params.putString("timestamp", Long.toString(l.getTime())); boolean isMock; if (android.os.Build.VERSION.SDK_INT >= 18) { isMock = l.isFromMockProvider(); } else { isMock = !Settings.Secure.getString(getReactApplicationContext().getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION).equals("0"); } params.putBoolean("mocked", isMock); return params; }
Example 22
Source Project: react-native-navigation-bar-color Source File: NavigationBarColorModule.java License: MIT License | 6 votes |
@ReactMethod public void hideNavigationBar(Promise promise) { try { runOnUiThread(new Runnable() { @Override public void run() { if (getCurrentActivity() != null) { View decorView = getCurrentActivity().getWindow().getDecorView(); decorView.setSystemUiVisibility(UI_FLAG_HIDE_NAV_BAR); } } }); } catch (IllegalViewOperationException e) { WritableMap map = Arguments.createMap(); map.putBoolean("success", false); promise.reject("error", e); } }
Example 23
Source Project: imsdk-android Source File: QtalkPlugin.java License: MIT License | 6 votes |
/** * 获取指定联系人nick * * @param xmppId * @param callback */ @ReactMethod public void getContactsNick(String xmppId, final Callback callback) { ConnectionUtil.getInstance().getUserCard(xmppId, new IMLogicManager.NickCallBack() { @Override public void onNickCallBack(Nick nick) { WritableNativeMap item = new WritableNativeMap(); String name = nick.getName(); String pinyin = nick.getXmppId(); if (!TextUtils.isEmpty(name)) { pinyin = HanziToPinyin.zh2Abb(name); } item.putString("Name", TextUtils.isEmpty(name) ? nick.getXmppId() : name); item.putString("HeaderUri", TextUtils.isEmpty(nick.getHeaderSrc()) ? "" : nick.getHeaderSrc()); item.putString("SearchIndex", pinyin); item.putString("XmppId", nick.getXmppId()); item.putString("Remark", nick.getMark()); WritableMap map = new WritableNativeMap(); map.putMap("nick", item); callback.invoke(map); } }, true, false); }
Example 24
Source Project: react-native-app-auth Source File: TokenResponseFactory.java License: MIT License | 5 votes |
public static final WritableMap tokenResponseToMap(TokenResponse response) { WritableMap map = Arguments.createMap(); map.putString("accessToken", response.accessToken); map.putMap("additionalParameters", MapUtil.createAdditionalParametersMap(response.additionalParameters)); map.putString("idToken", response.idToken); map.putString("refreshToken", response.refreshToken); map.putString("tokenType", response.tokenType); if (response.accessTokenExpirationTime != null) { map.putString("accessTokenExpirationDate", DateUtil.formatTimestamp(response.accessTokenExpirationTime)); } return map; }
Example 25
Source Project: react-native-twilio-ip-messaging Source File: RCTConvert.java License: MIT License | 5 votes |
public static WritableMap TwilioIPMessagingClient(TwilioIPMessagingClient client) { WritableMap map = Arguments.createMap(); map.putMap("userInfo", UserInfo(client.getMyUserInfo())); map.putBoolean("isReachabilityEnabled", client.isReachabilityEnabled()); return map; }
Example 26
Source Project: react-native-twilio-ip-messaging Source File: RCTTwilioIPMessagingClient.java License: 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 27
Source Project: react-native-flurry-sdk Source File: FlurryModule.java License: Apache License 2.0 | 5 votes |
@ReactMethod public void getVersionsPromise(Promise promise) { try { WritableMap map = Arguments.createMap(); map.putInt("agentVersion", FlurryAgent.getAgentVersion()); map.putString("releaseVersion", FlurryAgent.getReleaseVersion()); map.putString("sessionId", FlurryAgent.getSessionId()); promise.resolve(map); } catch (IllegalViewOperationException e) { promise.reject("Flurry.getVersionsPromise", e); } }
Example 28
Source Project: react-native-lock Source File: InitOptionsTest.java License: MIT License | 5 votes |
@Test public void testAll() throws Exception { WritableMap options = new SimpleMap(); options.putString("clientId", "client-id-value"); options.putString("domain", "domain-value"); options.putString("configurationDomain", "configuration-domain-value"); options.putBoolean("useBrowser", true); InitOptions initOptions = new InitOptions(options); assertThat(initOptions.getClientId(), is(equalTo("client-id-value"))); assertThat(initOptions.getConfigurationDomain(), is(equalTo("configuration-domain-value"))); assertThat(initOptions.getDomain(), is(equalTo("domain-value"))); assertThat(initOptions.useBrowser(), is(true)); }
Example 29
Source Project: react-native-admob Source File: RNPublisherBannerViewManager.java License: BSD 2-Clause "Simplified" License | 5 votes |
@Override public void onAppEvent(String name, String info) { WritableMap event = Arguments.createMap(); event.putString("name", name); event.putString("info", info); sendEvent(RNPublisherBannerViewManager.EVENT_APP_EVENT, event); }
Example 30
Source Project: react-native-fitness Source File: Manager.java License: MIT License | 5 votes |
private void processStep(DataSet dataSet, WritableArray map) { WritableMap stepMap = Arguments.createMap(); for (DataPoint dp : dataSet.getDataPoints()) { for(Field field : dp.getDataType().getFields()) { stepMap.putString("startDate", dateFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS))); stepMap.putString("endDate", dateFormat.format(dp.getEndTime(TimeUnit.MILLISECONDS))); stepMap.putDouble("quantity", dp.getValue(field).asInt()); map.pushMap(stepMap); } } }