mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-02 22:41:18 +08:00
BREAKING: Android: Correct value of Dimensions.get('screen').fontScale
Summary:
The PR description has been updated to reflect the new approach.
**Breaking Change Summary**
On Android, the following properties now return a different number:
- `Dimensions.get('window').fontScale`
- `Dimensions.get('screen').fontScale`
- `PixelRatio.getFontScale()`
This is a breaking change to anyone who was using these properties because the meaning of these properties has now changed.
These properties used to return a value representing font scale times density ([`DisplayMetrics.scaledDensity`](https://developer.android.com/reference/android/util/DisplayMetrics.html#scaledDensity)). Now they return a value representing just font scale ([`Configuration.fontScale`](https://developer.android.com/reference/android/content/res/Configuration.html#fontScale)).
**PR Description**
This PR changes a few things:
- Correctly exposes the font scale to JavaScript as `Dimensions.get('screen').fontScale`. UIManager was exporting `DisplayMetrics.scaledDensity` under the name `fontScale`. How
Closes https://github.com/facebook/react-native/pull/11008
Differential Revision: D4558207
Pulled By: astreet
fbshipit-source-id: 096ce7b28051325dfd45fdb2a14b5e9b7d3bc46f
This commit is contained in:
committed by
Facebook Github Bot
parent
7f9876c049
commit
186f308aec
@@ -394,27 +394,10 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView
|
||||
}
|
||||
|
||||
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);
|
||||
mReactInstanceManager
|
||||
.getCurrentReactContext()
|
||||
.getNativeModule(UIManagerModule.class)
|
||||
.emitUpdateDimensionsEvent();
|
||||
}
|
||||
|
||||
private void sendEvent(String eventName, @Nullable WritableMap params) {
|
||||
|
||||
Reference in New Issue
Block a user