-
Notifications
You must be signed in to change notification settings - Fork 24.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BREAKING: Android: Correct value of Dimensions.get('screen').fontScale #11008
Changes from all commits
f27182f
2f896a7
0f5ea42
340f7ca
3ce2b47
e8fc329
55a9467
f5c2fff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ | |
import android.view.accessibility.AccessibilityEvent; | ||
import android.widget.ImageView; | ||
|
||
import com.facebook.react.bridge.Arguments; | ||
import com.facebook.react.bridge.WritableMap; | ||
import com.facebook.react.common.MapBuilder; | ||
import com.facebook.react.uimanager.events.TouchEventType; | ||
|
||
|
@@ -81,7 +83,7 @@ | |
.build(); | ||
} | ||
|
||
public static Map<String, Object> getConstants() { | ||
public static Map<String, Object> getConstants(float fontScale) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't we decide we can get this off of displayMetrics as scaledDensity / density? At the least, I'd rather just pass in the Configuration object if you're worried about loss of precision There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this earlier comment you mentioned that we should get the font scale from The reason I pass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, this sounds reasonable |
||
HashMap<String, Object> constants = new HashMap<String, Object>(); | ||
constants.put( | ||
"UIView", | ||
|
@@ -95,35 +97,9 @@ public static Map<String, Object> getConstants() { | |
"ScaleAspectCenter", | ||
ImageView.ScaleType.CENTER_INSIDE.ordinal()))); | ||
|
||
DisplayMetrics displayMetrics = DisplayMetricsHolder.getWindowDisplayMetrics(); | ||
DisplayMetrics screenDisplayMetrics = DisplayMetricsHolder.getScreenDisplayMetrics(); | ||
constants.put( | ||
"Dimensions", | ||
MapBuilder.of( | ||
"windowPhysicalPixels", | ||
MapBuilder.of( | ||
"width", | ||
displayMetrics.widthPixels, | ||
"height", | ||
displayMetrics.heightPixels, | ||
"scale", | ||
displayMetrics.density, | ||
"fontScale", | ||
displayMetrics.scaledDensity, | ||
"densityDpi", | ||
displayMetrics.densityDpi), | ||
"screenPhysicalPixels", | ||
MapBuilder.of( | ||
"width", | ||
screenDisplayMetrics.widthPixels, | ||
"height", | ||
screenDisplayMetrics.heightPixels, | ||
"scale", | ||
screenDisplayMetrics.density, | ||
"fontScale", | ||
screenDisplayMetrics.scaledDensity, | ||
"densityDpi", | ||
screenDisplayMetrics.densityDpi))); | ||
getDimensionsConstants(fontScale)); | ||
|
||
constants.put( | ||
"StyleConstants", | ||
|
@@ -157,4 +133,29 @@ public static Map<String, Object> getConstants() { | |
|
||
return constants; | ||
} | ||
|
||
public static WritableMap getDimensionsConstants(float fontScale) { | ||
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", fontScale); | ||
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", fontScale); | ||
screenDisplayMetricsMap.putDouble("densityDpi", screenDisplayMetrics.densityDpi); | ||
|
||
WritableMap dimensionsMap = Arguments.createMap(); | ||
dimensionsMap.putMap("windowPhysicalPixels", windowDisplayMetricsMap); | ||
dimensionsMap.putMap("screenPhysicalPixels", screenDisplayMetricsMap); | ||
|
||
return dimensionsMap; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you're not adding this, but seems like we should be sharing code with where we create this map when exposing the initial constants.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed this now. One interesting detail is that the dimensions part of constants is now a
WritableMap
instead of aHashMap
. I wasn't sure what the impact of this would be. It built and ran fine.