Java Code Examples for com.facebook.react.bridge.UiThreadUtil#assertOnUiThread()
The following examples show how to use
com.facebook.react.bridge.UiThreadUtil#assertOnUiThread() .
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: EventDispatcher.java From react-native-GPay with MIT License | 6 votes |
@Override public void doFrame(long frameTimeNanos) { UiThreadUtil.assertOnUiThread(); if (mShouldStop) { mIsPosted = false; } else { post(); } Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "ScheduleDispatchFrameCallback"); try { moveStagedEventsToDispatchQueue(); if (!mHasDispatchScheduled) { mHasDispatchScheduled = true; Systrace.startAsyncFlow( Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "ScheduleDispatchFrameCallback", mHasDispatchScheduledCount.get()); mReactContext.runOnJSQueueThread(mDispatchEventsRunnable); } } finally { Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE); } }
Example 2
Source File: NativeViewHierarchyManager.java From react-native-GPay with MIT License | 6 votes |
/** * Simplified version of manageChildren that only deals with adding children views */ public synchronized void setChildren( int tag, ReadableArray childrenTags) { UiThreadUtil.assertOnUiThread(); ViewGroup viewToManage = (ViewGroup) mTagsToViews.get(tag); ViewGroupManager viewManager = (ViewGroupManager) resolveViewManager(tag); for (int i = 0; i < childrenTags.size(); i++) { View viewToAdd = mTagsToViews.get(childrenTags.getInt(i)); if (viewToAdd == null) { throw new IllegalViewOperationException( "Trying to add unknown view tag: " + childrenTags.getInt(i) + "\n detail: " + constructSetChildrenErrorMessage( viewToManage, viewManager, childrenTags)); } viewManager.addView(viewToManage, viewToAdd, i); } }
Example 3
Source File: ReactInstanceManager.java From react-native-GPay with MIT License | 6 votes |
private void tearDownReactContext(ReactContext reactContext) { Log.d(ReactConstants.TAG, "ReactInstanceManager.tearDownReactContext()"); UiThreadUtil.assertOnUiThread(); if (mLifecycleState == LifecycleState.RESUMED) { reactContext.onHostPause(); } synchronized (mAttachedRootViews) { for (ReactRootView rootView : mAttachedRootViews) { rootView.removeAllViews(); rootView.setId(View.NO_ID); } } reactContext.destroy(); mDevSupportManager.onReactInstanceDestroyed(reactContext); mMemoryPressureRouter.removeMemoryPressureListener(reactContext.getCatalystInstance()); }
Example 4
Source File: ReactInstanceManager.java From react-native-GPay with MIT License | 6 votes |
/** * This method will give JS the opportunity to receive intents via Linking. */ @ThreadConfined(UI) public void onNewIntent(Intent intent) { UiThreadUtil.assertOnUiThread(); ReactContext currentContext = getCurrentReactContext(); if (currentContext == null) { FLog.w(ReactConstants.TAG, "Instance detached from instance manager"); } else { String action = intent.getAction(); Uri uri = intent.getData(); if (Intent.ACTION_VIEW.equals(action) && uri != null) { DeviceEventManagerModule deviceEventManagerModule = currentContext.getNativeModule(DeviceEventManagerModule.class); deviceEventManagerModule.emitNewIntentReceived(uri); } currentContext.onNewIntent(mCurrentActivity, intent); } }
Example 5
Source File: NativeViewHierarchyManager.java From react-native-GPay with MIT License | 6 votes |
/** * Show a {@link PopupMenu}. * * @param reactTag the tag of the anchor view (the PopupMenu is displayed next to this view); this * needs to be the tag of a native view (shadow views can not be anchors) * @param items the menu items as an array of strings * @param success will be called with the position of the selected item as the first argument, or * no arguments if the menu is dismissed */ public synchronized void showPopupMenu(int reactTag, ReadableArray items, Callback success, Callback error) { UiThreadUtil.assertOnUiThread(); View anchor = mTagsToViews.get(reactTag); if (anchor == null) { error.invoke("Can't display popup. Could not find view with tag " + reactTag); return; } mPopupMenu = new PopupMenu(getReactContextForView(reactTag), anchor); Menu menu = mPopupMenu.getMenu(); for (int i = 0; i < items.size(); i++) { menu.add(Menu.NONE, Menu.NONE, i, items.getString(i)); } PopupMenuCallbackHandler handler = new PopupMenuCallbackHandler(success); mPopupMenu.setOnMenuItemClickListener(handler); mPopupMenu.setOnDismissListener(handler); mPopupMenu.show(); }
Example 6
Source File: NativeViewHierarchyManager.java From react-native-GPay with MIT License | 6 votes |
/** * Returns the coordinates of a view relative to the window (not just the RootView * which is what measure will return) * * @param tag - the tag for the view * @param outputBuffer - output buffer that contains [x,y,width,height] of the view in coordinates * relative to the device window */ public synchronized void measureInWindow(int tag, int[] outputBuffer) { UiThreadUtil.assertOnUiThread(); View v = mTagsToViews.get(tag); if (v == null) { throw new NoSuchNativeViewException("No native view for " + tag + " currently exists"); } v.getLocationOnScreen(outputBuffer); // We need to remove the status bar from the height. getLocationOnScreen will include the // status bar. Resources resources = v.getContext().getResources(); int statusBarId = resources.getIdentifier("status_bar_height", "dimen", "android"); if (statusBarId > 0) { int height = (int) resources.getDimension(statusBarId); outputBuffer[1] -= height; } // outputBuffer[0,1] already contain what we want outputBuffer[2] = v.getWidth(); outputBuffer[3] = v.getHeight(); }
Example 7
Source File: DeviceEventManagerModule.java From react-native-GPay with MIT License | 5 votes |
public DeviceEventManagerModule( ReactApplicationContext reactContext, final DefaultHardwareBackBtnHandler backBtnHandler) { super(reactContext); mInvokeDefaultBackPressRunnable = new Runnable() { @Override public void run() { UiThreadUtil.assertOnUiThread(); backBtnHandler.invokeDefaultOnBackPressed(); } }; }
Example 8
Source File: RNTouchTargetHelper.java From react-native-sensors-analytics with Apache License 2.0 | 5 votes |
public static int findTargetTagAndCoordinatesForTouch(float eventX, float eventY, ViewGroup viewGroup, float[] viewCoords) { UiThreadUtil.assertOnUiThread(); int targetTag = viewGroup.getId(); viewCoords[0] = eventX; viewCoords[1] = eventY; View nativeTargetView = findTouchTargetView(viewCoords, viewGroup); if (nativeTargetView == null) { return targetTag; } View reactTargetView = findClosestReactAncestor(nativeTargetView); if (reactTargetView != null) { return getTouchTargetForView(reactTargetView, viewCoords[0], viewCoords[1]); } return targetTag; }
Example 9
Source File: NativeViewHierarchyManager.java From react-native-GPay with MIT License | 5 votes |
public synchronized void dispatchCommand( int reactTag, int commandId, @Nullable ReadableArray args) { UiThreadUtil.assertOnUiThread(); View view = mTagsToViews.get(reactTag); if (view == null) { throw new IllegalViewOperationException("Trying to send command to a non-existing view " + "with tag " + reactTag); } ViewManager viewManager = resolveViewManager(reactTag); viewManager.receiveCommand(view, commandId, args); }
Example 10
Source File: NativeViewHierarchyManager.java From react-native-GPay with MIT License | 5 votes |
public synchronized void updateInstanceHandle(int tag, long instanceHandle) { UiThreadUtil.assertOnUiThread(); try { updateInstanceHandle(resolveView(tag), instanceHandle); } catch (IllegalViewOperationException e) { FLog.e(TAG, "Unable to update properties for view tag " + tag, e); } }
Example 11
Source File: ReactInstanceManager.java From react-native-GPay with MIT License | 5 votes |
/** * Destroy this React instance and the attached JS context. */ @ThreadConfined(UI) public void destroy() { UiThreadUtil.assertOnUiThread(); PrinterHolder.getPrinter().logMessage(ReactDebugOverlayTags.RN_CORE, "RNCore: Destroy"); mHasStartedDestroying = true; if (mUseDeveloperSupport) { mDevSupportManager.setDevSupportEnabled(false); mDevSupportManager.stopInspector(); } moveToBeforeCreateLifecycleState(); if (mCreateReactContextThread != null) { mCreateReactContextThread = null; } mMemoryPressureRouter.destroy(mApplicationContext); synchronized (mReactContextLock) { if (mCurrentReactContext != null) { mCurrentReactContext.destroy(); mCurrentReactContext = null; } } mHasStartedCreatingInitialContext = false; mCurrentActivity = null; ResourceDrawableIdHelper.getInstance().clear(); mHasStartedDestroying = false; synchronized (mHasStartedDestroying) { mHasStartedDestroying.notifyAll(); } }
Example 12
Source File: ReactInstanceManager.java From react-native-GPay with MIT License | 5 votes |
/** * Detach given {@param rootView} from current catalyst instance. It's safe to call this method * multiple times on the same {@param rootView} - in that case view will be detached with the * first call. */ @ThreadConfined(UI) public void detachRootView(ReactRootView rootView) { UiThreadUtil.assertOnUiThread(); if (mAttachedRootViews.remove(rootView)) { ReactContext currentContext = getCurrentReactContext(); if (currentContext != null && currentContext.hasActiveCatalystInstance()) { detachViewFromInstance(rootView, currentContext.getCatalystInstance()); } } }
Example 13
Source File: NativeViewHierarchyManager.java From react-native-GPay with MIT License | 5 votes |
public synchronized void updateViewExtraData(int tag, Object extraData) { UiThreadUtil.assertOnUiThread(); ViewManager viewManager = resolveViewManager(tag); View viewToUpdate = resolveView(tag); viewManager.updateExtraData(viewToUpdate, extraData); }
Example 14
Source File: NativeViewHierarchyManager.java From react-native-GPay with MIT License | 5 votes |
public synchronized int findTargetTagForTouch(int reactTag, float touchX, float touchY) { UiThreadUtil.assertOnUiThread(); View view = mTagsToViews.get(reactTag); if (view == null) { throw new JSApplicationIllegalArgumentException("Could not find view with tag " + reactTag); } return TouchTargetHelper.findTargetTagForTouch(touchX, touchY, (ViewGroup) view); }
Example 15
Source File: NativeViewHierarchyManager.java From react-native-GPay with MIT License | 5 votes |
public synchronized void updateProperties(int tag, ReactStylesDiffMap props) { UiThreadUtil.assertOnUiThread(); try { ViewManager viewManager = resolveViewManager(tag); View viewToUpdate = resolveView(tag); if (props != null) { viewManager.updateProperties(viewToUpdate, props); } } catch (IllegalViewOperationException e) { FLog.e(TAG, "Unable to update properties for view tag " + tag, e); } }
Example 16
Source File: ReactChoreographer.java From react-native-GPay with MIT License | 4 votes |
public static void initialize() { if (sInstance == null) { UiThreadUtil.assertOnUiThread(); sInstance = new ReactChoreographer(); } }
Example 17
Source File: DevSupportManagerImpl.java From react-native-GPay with MIT License | 4 votes |
private void reload() { UiThreadUtil.assertOnUiThread(); // reload settings, show/hide debug overlay if required & start/stop shake detector if (mIsDevSupportEnabled) { // update visibility of FPS debug overlay depending on the settings if (mDebugOverlayController != null) { mDebugOverlayController.setFpsDebugViewVisible(mDevSettings.isFpsDebugEnabled()); } // start shake gesture detector if (!mIsShakeDetectorStarted) { mShakeDetector.start( (SensorManager) mApplicationContext.getSystemService(Context.SENSOR_SERVICE)); mIsShakeDetectorStarted = true; } // register reload app broadcast receiver if (!mIsReceiverRegistered) { IntentFilter filter = new IntentFilter(); filter.addAction(getReloadAppAction(mApplicationContext)); mApplicationContext.registerReceiver(mReloadAppBroadcastReceiver, filter); mIsReceiverRegistered = true; } // show the dev loading if it should be if (mDevLoadingViewVisible) { mDevLoadingViewController.showMessage("Reloading..."); } mDevServerHelper.openPackagerConnection(this.getClass().getSimpleName(), this); if (mDevSettings.isReloadOnJSChangeEnabled()) { mDevServerHelper.startPollingOnChangeEndpoint( new DevServerHelper.OnServerContentChangeListener() { @Override public void onServerContentChanged() { handleReloadJS(); } }); } else { mDevServerHelper.stopPollingOnChangeEndpoint(); } } else { // hide FPS debug overlay if (mDebugOverlayController != null) { mDebugOverlayController.setFpsDebugViewVisible(false); } // stop shake gesture detector if (mIsShakeDetectorStarted) { mShakeDetector.stop(); mIsShakeDetectorStarted = false; } // unregister app reload broadcast receiver if (mIsReceiverRegistered) { mApplicationContext.unregisterReceiver(mReloadAppBroadcastReceiver); mIsReceiverRegistered = false; } // hide redbox dialog hideRedboxDialog(); // hide dev options dialog hideDevOptionsDialog(); // hide loading view mDevLoadingViewController.hide(); mDevServerHelper.closePackagerConnection(); mDevServerHelper.stopPollingOnChangeEndpoint(); } }
Example 18
Source File: ReactInstanceManager.java From react-native-GPay with MIT License | 4 votes |
@ThreadConfined(UI) public void showDevOptionsDialog() { UiThreadUtil.assertOnUiThread(); mDevSupportManager.showDevOptionsDialog(); }
Example 19
Source File: EventDispatcher.java From react-native-GPay with MIT License | 4 votes |
private void stopFrameCallback() { UiThreadUtil.assertOnUiThread(); mCurrentFrameCallback.stop(); }
Example 20
Source File: UIImplementation.java From react-native-GPay with MIT License | 2 votes |
/** * Used by native animated module to bypass the process of updating the values through the shadow * view hierarchy. This method will directly update native views, which means that updates for * layout-related propertied won't be handled properly. * Make sure you know what you're doing before calling this method :) */ public void synchronouslyUpdateViewOnUIThread(int tag, ReactStylesDiffMap props) { UiThreadUtil.assertOnUiThread(); mOperationsQueue.getNativeViewHierarchyManager().updateProperties(tag, props); }