com.facebook.react.uimanager.DisplayMetricsHolder Java Examples

The following examples show how to use com.facebook.react.uimanager.DisplayMetricsHolder. 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: ReactRootView.java    From react-native-GPay with MIT License 6 votes vote down vote up
private void checkForKeyboardEvents() {
  getRootView().getWindowVisibleDisplayFrame(mVisibleViewArea);
  final int heightDiff =
    DisplayMetricsHolder.getWindowDisplayMetrics().heightPixels - mVisibleViewArea.bottom;
  if (mKeyboardHeight != heightDiff && heightDiff > mMinKeyboardHeightDetected) {
    // keyboard is now showing, or the keyboard height has changed
    mKeyboardHeight = heightDiff;
    WritableMap params = Arguments.createMap();
    WritableMap coordinates = Arguments.createMap();
    coordinates.putDouble("screenY", PixelUtil.toDIPFromPixel(mVisibleViewArea.bottom));
    coordinates.putDouble("screenX", PixelUtil.toDIPFromPixel(mVisibleViewArea.left));
    coordinates.putDouble("width", PixelUtil.toDIPFromPixel(mVisibleViewArea.width()));
    coordinates.putDouble("height", PixelUtil.toDIPFromPixel(mKeyboardHeight));
    params.putMap("endCoordinates", coordinates);
    sendEvent("keyboardDidShow", params);
  } else if (mKeyboardHeight != 0 && heightDiff <= mMinKeyboardHeightDetected) {
    // keyboard is now hidden
    mKeyboardHeight = 0;
    sendEvent("keyboardDidHide", null);
  }
}
 
Example #2
Source File: FabricUIManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
public FabricUIManager(
    ReactApplicationContext reactContext,
    ViewManagerRegistry viewManagerRegistry,
    JavaScriptContextHolder jsContext,
    EventDispatcher eventDispatcher) {
  DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(reactContext);
  mReactApplicationContext = reactContext;
  mViewManagerRegistry = viewManagerRegistry;
  mNativeViewHierarchyManager = new NativeViewHierarchyManager(viewManagerRegistry);
  mUIViewOperationQueue =
      new UIViewOperationQueue(
          reactContext, mNativeViewHierarchyManager, 0);
  mFabricReconciler = new FabricReconciler(mUIViewOperationQueue);
  mFabricEventEmitter =
    new FabricEventEmitter(mReactApplicationContext, this);
  mEventDispatcher = eventDispatcher;
  mJSContext = jsContext;
}
 
Example #3
Source File: ReactImagePropertyTest.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Before
public void setup() {
  SoLoader.setInTestMode();
  mContext = new ReactApplicationContext(RuntimeEnvironment.application);
  mCatalystInstanceMock = ReactTestHelper.createMockCatalystInstance();
  mContext.initializeWithInstance(mCatalystInstanceMock);
  mThemeContext = new ThemedReactContext(mContext, mContext);
  Fresco.initialize(mContext);
  DisplayMetricsHolder.setWindowDisplayMetrics(new DisplayMetrics());
}
 
Example #4
Source File: ReactTextInputPropertyTest.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Before
public void setup() {
  mContext = new ReactApplicationContext(RuntimeEnvironment.application);
  mCatalystInstanceMock = ReactTestHelper.createMockCatalystInstance();
  mContext.initializeWithInstance(mCatalystInstanceMock);
  mThemedContext = new ThemedReactContext(mContext, mContext);
  mManager = new ReactTextInputManager();
  DisplayMetricsHolder.setWindowDisplayMetrics(new DisplayMetrics());
}
 
Example #5
Source File: ReactHorizontalScrollViewManager.java    From react-native-GPay with MIT License 5 votes vote down vote up
@ReactProp(name = "snapToOffsets")
public void setSnapToOffsets(ReactHorizontalScrollView view, @Nullable ReadableArray snapToOffsets) {
  DisplayMetrics screenDisplayMetrics = DisplayMetricsHolder.getScreenDisplayMetrics();
  List<Integer> offsets = new ArrayList<Integer>();
  for (int i = 0; i < snapToOffsets.size(); i++) {
    offsets.add((int) (snapToOffsets.getDouble(i) * screenDisplayMetrics.density));
  }
  view.setSnapOffsets(offsets);
}
 
Example #6
Source File: ReactRootView.java    From react-native-GPay with MIT License 5 votes vote down vote up
private void checkForDeviceDimensionsChanges() {
  // Get current display metrics.
  DisplayMetricsHolder.initDisplayMetrics(getContext());
  // Check changes to both window and screen display metrics since they may not update at the same time.
  if (!areMetricsEqual(mWindowMetrics, DisplayMetricsHolder.getWindowDisplayMetrics()) ||
    !areMetricsEqual(mScreenMetrics, DisplayMetricsHolder.getScreenDisplayMetrics())) {
    mWindowMetrics.setTo(DisplayMetricsHolder.getWindowDisplayMetrics());
    mScreenMetrics.setTo(DisplayMetricsHolder.getScreenDisplayMetrics());
    emitUpdateDimensionsEvent();
  }
}
 
Example #7
Source File: ReactScrollViewManager.java    From react-native-GPay with MIT License 5 votes vote down vote up
@ReactProp(name = "snapToOffsets")
public void setSnapToOffsets(ReactScrollView view, @Nullable ReadableArray snapToOffsets) {
  DisplayMetrics screenDisplayMetrics = DisplayMetricsHolder.getScreenDisplayMetrics();
  List<Integer> offsets = new ArrayList<Integer>();
  for (int i = 0; i < snapToOffsets.size(); i++) {
    offsets.add((int) (snapToOffsets.getDouble(i) * screenDisplayMetrics.density));
  }
  view.setSnapOffsets(offsets);
}
 
Example #8
Source File: DeviceInfoModule.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Override
public @Nullable Map<String, Object> getConstants() {
  HashMap<String, Object> constants = new HashMap<>();
  constants.put(
      "Dimensions",
      DisplayMetricsHolder.getDisplayMetricsMap(mFontScale));
  return constants;
}
 
Example #9
Source File: DeviceInfoModule.java    From react-native-GPay with MIT License 5 votes vote down vote up
public void emitUpdateDimensionsEvent() {
  if (mReactApplicationContext == null) {
    return;
  }

  mReactApplicationContext
      .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
      .emit("didUpdateDimensions", DisplayMetricsHolder.getDisplayMetricsNativeMap(mFontScale));
}
 
Example #10
Source File: ReactImagePropertyTest.java    From react-native-GPay with MIT License 4 votes vote down vote up
@After
public void teardown() {
  DisplayMetricsHolder.setWindowDisplayMetrics(null);
}
 
Example #11
Source File: ARTVirtualNode.java    From art with MIT License 4 votes vote down vote up
public ARTVirtualNode() {
  mScale = DisplayMetricsHolder.getWindowDisplayMetrics().density;
}
 
Example #12
Source File: ReactRootView.java    From react-native-GPay with MIT License 4 votes vote down vote up
CustomGlobalLayoutListener() {
  DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(getContext().getApplicationContext());
  mVisibleViewArea = new Rect();
  mMinKeyboardHeightDetected = (int) PixelUtil.toPixelFromDIP(60);
}
 
Example #13
Source File: ReactInstanceManager.java    From react-native-GPay with MIT License 4 votes vote down vote up
ReactInstanceManager(
  Context applicationContext,
  @Nullable Activity currentActivity,
  @Nullable DefaultHardwareBackBtnHandler defaultHardwareBackBtnHandler,
  JavaScriptExecutorFactory javaScriptExecutorFactory,
  @Nullable JSBundleLoader bundleLoader,
  @Nullable String jsMainModulePath,
  List<ReactPackage> packages,
  boolean useDeveloperSupport,
  @Nullable NotThreadSafeBridgeIdleDebugListener bridgeIdleDebugListener,
  LifecycleState initialLifecycleState,
  @Nullable UIImplementationProvider mUIImplementationProvider,
  NativeModuleCallExceptionHandler nativeModuleCallExceptionHandler,
  @Nullable RedBoxHandler redBoxHandler,
  boolean lazyViewManagersEnabled,
  @Nullable DevBundleDownloadListener devBundleDownloadListener,
  int minNumShakes,
  int minTimeLeftInFrameForNonBatchedOperationMs,
  @Nullable JSIModulePackage jsiModulePackage,
  @Nullable Map<String, RequestHandler> customPackagerCommandHandlers) {
  Log.d(ReactConstants.TAG, "ReactInstanceManager.ctor()");
  initializeSoLoaderIfNecessary(applicationContext);

  DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(applicationContext);

  mApplicationContext = applicationContext;
  mCurrentActivity = currentActivity;
  mDefaultBackButtonImpl = defaultHardwareBackBtnHandler;
  mJavaScriptExecutorFactory = javaScriptExecutorFactory;
  mBundleLoader = bundleLoader;
  mJSMainModulePath = jsMainModulePath;
  mPackages = new ArrayList<>();
  mUseDeveloperSupport = useDeveloperSupport;
  mDevSupportManager =
      DevSupportManagerFactory.create(
          applicationContext,
          createDevHelperInterface(),
          mJSMainModulePath,
          useDeveloperSupport,
          redBoxHandler,
          devBundleDownloadListener,
          minNumShakes,
          customPackagerCommandHandlers);
  mBridgeIdleDebugListener = bridgeIdleDebugListener;
  mLifecycleState = initialLifecycleState;
  mMemoryPressureRouter = new MemoryPressureRouter(applicationContext);
  mNativeModuleCallExceptionHandler = nativeModuleCallExceptionHandler;
  synchronized (mPackages) {
    PrinterHolder.getPrinter()
        .logMessage(ReactDebugOverlayTags.RN_CORE, "RNCore: Use Split Packages");
    mPackages.add(
        new CoreModulesPackage(
            this,
            new DefaultHardwareBackBtnHandler() {
              @Override
              public void invokeDefaultOnBackPressed() {
                ReactInstanceManager.this.invokeDefaultOnBackPressed();
              }
            },
            mUIImplementationProvider,
            lazyViewManagersEnabled,
            minTimeLeftInFrameForNonBatchedOperationMs));
    if (mUseDeveloperSupport) {
      mPackages.add(new DebugCorePackage());
    }
    mPackages.addAll(packages);
  }
  mJSIModulePackage = jsiModulePackage;

  // Instantiate ReactChoreographer in UI thread.
  ReactChoreographer.initialize();
  if (mUseDeveloperSupport) {
    mDevSupportManager.startInspector();
  }
}
 
Example #14
Source File: DeviceInfoModule.java    From react-native-GPay with MIT License 4 votes vote down vote up
public DeviceInfoModule(Context context) {
  mReactApplicationContext = null;
  DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(context);
  mFontScale = context.getResources().getConfiguration().fontScale;
}
 
Example #15
Source File: ReactScrollViewManager.java    From react-native-GPay with MIT License 4 votes vote down vote up
@ReactProp(name = "snapToInterval")
public void setSnapToInterval(ReactScrollView view, float snapToInterval) {
  // snapToInterval needs to be exposed as a float because of the Javascript interface.
  DisplayMetrics screenDisplayMetrics = DisplayMetricsHolder.getScreenDisplayMetrics();
  view.setSnapInterval((int) (snapToInterval * screenDisplayMetrics.density));
}
 
Example #16
Source File: ReactHorizontalScrollViewManager.java    From react-native-GPay with MIT License 4 votes vote down vote up
@ReactProp(name = "snapToInterval")
public void setSnapToInterval(ReactHorizontalScrollView view, float snapToInterval) {
  // snapToInterval needs to be exposed as a float because of the Javascript interface.
  DisplayMetrics screenDisplayMetrics = DisplayMetricsHolder.getScreenDisplayMetrics();
  view.setSnapInterval((int) (snapToInterval * screenDisplayMetrics.density));
}
 
Example #17
Source File: ARTVirtualNode.java    From react-native-GPay with MIT License 4 votes vote down vote up
public ARTVirtualNode() {
  mScale = DisplayMetricsHolder.getWindowDisplayMetrics().density;
}
 
Example #18
Source File: RNTextSizeModule.java    From react-native-text-size with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Retuns the current density.
 */
@SuppressWarnings("deprecation")
private float getCurrentDensity() {
    return DisplayMetricsHolder.getWindowDisplayMetrics().density;
}