private WritableMap getDimensionsConstants() { DisplayMetrics windowDisplayMetrics = DisplayMetricsHolder.getWindowDisplayMetrics(); DisplayMetrics screenDisplayMetrics = DisplayMetricsHolder.getScreenDisplayMetrics(); WritableMap windowDisplayMetricsMap = Arguments.createMap(); windowDisplayMetricsMap.putInt("width", windowDisplayMetrics.widthPixels); windowDisplayMetricsMap.putInt("height", windowDisplayMetrics.heightPixels); windowDisplayMetricsMap.putDouble("scale", windowDisplayMetrics.density); windowDisplayMetricsMap.putDouble("fontScale", mFontScale); windowDisplayMetricsMap.putDouble("densityDpi", windowDisplayMetrics.densityDpi); WritableMap screenDisplayMetricsMap = Arguments.createMap(); screenDisplayMetricsMap.putInt("width", screenDisplayMetrics.widthPixels); screenDisplayMetricsMap.putInt("height", screenDisplayMetrics.heightPixels); screenDisplayMetricsMap.putDouble("scale", screenDisplayMetrics.density); screenDisplayMetricsMap.putDouble("fontScale", mFontScale); screenDisplayMetricsMap.putDouble("densityDpi", screenDisplayMetrics.densityDpi); WritableMap dimensionsMap = Arguments.createMap(); dimensionsMap.putMap("windowPhysicalPixels", windowDisplayMetricsMap); dimensionsMap.putMap("screenPhysicalPixels", screenDisplayMetricsMap); return dimensionsMap; }
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); } }
public UIManagerModule getUIManagerModule() { ReactApplicationContext reactContext = ReactTestHelper.createCatalystContextForTest(); List<ViewManager> viewManagers = Arrays.asList( new ViewManager[] { new ReactTextInputManager(), }); DisplayMetrics displayMetrics = reactContext.getResources().getDisplayMetrics(); DisplayMetricsHolder.setWindowDisplayMetrics(displayMetrics); DisplayMetricsHolder.setScreenDisplayMetrics(displayMetrics); UIManagerModule uiManagerModule = new UIManagerModule( reactContext, viewManagers, new UIImplementation(reactContext, viewManagers)); uiManagerModule.onHostResume(); return uiManagerModule; }
public UIManagerModule getUIManagerModule() { ReactApplicationContext reactContext = ReactTestHelper.createCatalystContextForTest(); DisplayMetrics displayMetrics = reactContext.getResources().getDisplayMetrics(); DisplayMetricsHolder.setWindowDisplayMetrics(displayMetrics); DisplayMetricsHolder.setScreenDisplayMetrics(displayMetrics); List<ViewManager> viewManagers = Arrays.asList( new ViewManager[] { new ReactTextViewManager(), new ReactRawTextManager(), }); UIManagerModule uiManagerModule = new UIManagerModule( reactContext, viewManagers, new UIImplementation(reactContext, viewManagers)); uiManagerModule.onHostResume(); return uiManagerModule; }
private void emitUpdateDimensionsEvent() { DisplayMetrics windowDisplayMetrics = DisplayMetricsHolder.getWindowDisplayMetrics(); DisplayMetrics screenDisplayMetrics = DisplayMetricsHolder.getScreenDisplayMetrics(); WritableMap windowDisplayMetricsMap = Arguments.createMap(); windowDisplayMetricsMap.putInt("width", windowDisplayMetrics.widthPixels); windowDisplayMetricsMap.putInt("height", windowDisplayMetrics.heightPixels); windowDisplayMetricsMap.putDouble("scale", windowDisplayMetrics.density); windowDisplayMetricsMap.putDouble("fontScale", windowDisplayMetrics.scaledDensity); windowDisplayMetricsMap.putDouble("densityDpi", windowDisplayMetrics.densityDpi); WritableMap screenDisplayMetricsMap = Arguments.createMap(); screenDisplayMetricsMap.putInt("width", screenDisplayMetrics.widthPixels); screenDisplayMetricsMap.putInt("height", screenDisplayMetrics.heightPixels); screenDisplayMetricsMap.putDouble("scale", screenDisplayMetrics.density); screenDisplayMetricsMap.putDouble("fontScale", screenDisplayMetrics.scaledDensity); screenDisplayMetricsMap.putDouble("densityDpi", screenDisplayMetrics.densityDpi); WritableMap dimensionsMap = Arguments.createMap(); dimensionsMap.putMap("windowPhysicalPixels", windowDisplayMetricsMap); dimensionsMap.putMap("screenPhysicalPixels", screenDisplayMetricsMap); sendEvent("didUpdateDimensions", dimensionsMap); }
private void checkForDeviceOrientationChanges() { final int rotation = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay().getRotation(); if (mDeviceRotation == rotation) { return; } mDeviceRotation = rotation; // It's important to repopulate DisplayMetrics and export them before emitting the // orientation change event, so that the Dimensions object returns the correct new values. DisplayMetricsHolder.initDisplayMetrics(getContext()); emitUpdateDimensionsEvent(); emitOrientationChanged(rotation); }
@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()); }
@Before public void setup() { mContext = new ReactApplicationContext(RuntimeEnvironment.application); mCatalystInstanceMock = ReactTestHelper.createMockCatalystInstance(); mContext.initializeWithInstance(mCatalystInstanceMock); mThemeContext = new ThemedReactContext(mContext, mContext); Fresco.initialize(mContext); DisplayMetricsHolder.setWindowDisplayMetrics(new DisplayMetrics()); }
private static void setDisplayMetrics(Context context) { DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); DisplayMetricsHolder.setWindowDisplayMetrics(displayMetrics); DisplayMetrics screenDisplayMetrics = new DisplayMetrics(); screenDisplayMetrics.setTo(displayMetrics); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); // Get the real display metrics if we are using API level 17 or higher. // The real metrics include system decor elements (e.g. soft menu bar). // // See: http://developer.android.com/reference/android/view/Display.html#getRealMetrics(android.util.DisplayMetrics) if (Build.VERSION.SDK_INT >= 17) { display.getRealMetrics(screenDisplayMetrics); } else { // For 14 <= API level <= 16, we need to invoke getRawHeight and getRawWidth to get the real dimensions. // Since react-native only supports API level 16+ we don't have to worry about other cases. // // Reflection exceptions are rethrown at runtime. // // See: http://stackoverflow.com/questions/14341041/how-to-get-real-screen-height-and-width/23861333#23861333 try { Method mGetRawH = Display.class.getMethod("getRawHeight"); Method mGetRawW = Display.class.getMethod("getRawWidth"); screenDisplayMetrics.widthPixels = (Integer) mGetRawW.invoke(display); screenDisplayMetrics.heightPixels = (Integer) mGetRawH.invoke(display); } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) { throw new RuntimeException("Error getting real dimensions for API level < 17", e); } } DisplayMetricsHolder.setScreenDisplayMetrics(screenDisplayMetrics); }
@Override public void onGlobalLayout() { if (mReactInstanceManager == null || !mIsAttachedToInstance || mReactInstanceManager.getCurrentReactContext() == null) { FLog.w( ReactConstants.TAG, "Unable to dispatch keyboard events in JS as the react instance has not been attached"); return; } 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); } }
public ARTVirtualNode() { mScale = DisplayMetricsHolder.getWindowDisplayMetrics().density; }
public DeviceInfoModule(Context context) { mReactApplicationContext = null; DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(context); mFontScale = context.getResources().getConfiguration().fontScale; }
ReactInstanceManager( Context applicationContext, @Nullable Activity currentActivity, @Nullable DefaultHardwareBackBtnHandler defaultHardwareBackBtnHandler, @Nullable JSBundleLoader bundleLoader, @Nullable String jsMainModuleName, List<ReactPackage> packages, boolean useDeveloperSupport, @Nullable NotThreadSafeBridgeIdleDebugListener bridgeIdleDebugListener, LifecycleState initialLifecycleState, UIImplementationProvider uiImplementationProvider, NativeModuleCallExceptionHandler nativeModuleCallExceptionHandler, JSCConfig jscConfig, @Nullable RedBoxHandler redBoxHandler, boolean lazyNativeModulesEnabled, boolean lazyViewManagersEnabled, boolean useStartupThread) { initializeSoLoaderIfNecessary(applicationContext); // TODO(9577825): remove this ApplicationHolder.setApplication((Application) applicationContext.getApplicationContext()); DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(applicationContext); mApplicationContext = applicationContext; mCurrentActivity = currentActivity; mDefaultBackButtonImpl = defaultHardwareBackBtnHandler; mBundleLoader = bundleLoader; mJSMainModuleName = jsMainModuleName; mPackages = packages; mUseDeveloperSupport = useDeveloperSupport; mDevSupportManager = DevSupportManagerFactory.create( applicationContext, mDevInterface, mJSMainModuleName, useDeveloperSupport, redBoxHandler); mBridgeIdleDebugListener = bridgeIdleDebugListener; mLifecycleState = initialLifecycleState; mUIImplementationProvider = uiImplementationProvider; mMemoryPressureRouter = new MemoryPressureRouter(applicationContext); mNativeModuleCallExceptionHandler = nativeModuleCallExceptionHandler; mJSCConfig = jscConfig; mLazyNativeModulesEnabled = lazyNativeModulesEnabled; mLazyViewManagersEnabled = lazyViewManagersEnabled; mUseStartupThread = useStartupThread; }
@After public void teardown() { DisplayMetricsHolder.setWindowDisplayMetrics(null); }