mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fix precision of TextInlineViews in Android
Summary: TextInlineViews in Android was incorrectly converting values to from float to int, this produced to loose precision and to render incomplete texts in some components. This diff changed the types from int to float, avoiding loose precision. The impact of this bug is not that high because in the conversion to int we were using Math.ceil(), which was already rounding the result to the next pixel. changeLog: [Android][Fixed] Fix precision of TextInlineViews in Fabric Android Reviewed By: JoshuaGross, shergin Differential Revision: D21541159 fbshipit-source-id: 4741ab96964c35af1c1b7d3e821e505ecef2efce
This commit is contained in:
committed by
Facebook GitHub Bot
parent
774ebd9c12
commit
e3f4a7ba09
@@ -464,7 +464,7 @@ public class FabricUIManager implements UIManager, LifecycleEventListener {
|
||||
float maxWidth,
|
||||
float minHeight,
|
||||
float maxHeight,
|
||||
@Nullable int[] attachmentsPositions) {
|
||||
@Nullable float[] attachmentsPositions) {
|
||||
ReactContext context =
|
||||
rootTag < 0 ? mReactApplicationContext : mReactContextForRootTag.get(rootTag);
|
||||
return mMountingManager.measure(
|
||||
|
||||
@@ -519,7 +519,7 @@ public class MountingManager {
|
||||
@NonNull YogaMeasureMode widthMode,
|
||||
float height,
|
||||
@NonNull YogaMeasureMode heightMode,
|
||||
@Nullable int[] attachmentsPositions) {
|
||||
@Nullable float[] attachmentsPositions) {
|
||||
|
||||
return mViewManagerRegistry
|
||||
.get(componentName)
|
||||
|
||||
@@ -318,7 +318,7 @@ public abstract class ViewManager<T extends View, C extends ReactShadowNode>
|
||||
YogaMeasureMode widthMode,
|
||||
float height,
|
||||
YogaMeasureMode heightMode,
|
||||
@Nullable int[] attachmentsPositions) {
|
||||
@Nullable float[] attachmentsPositions) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -259,7 +259,7 @@ public class ReactSliderManager extends SimpleViewManager<ReactSlider>
|
||||
YogaMeasureMode widthMode,
|
||||
float height,
|
||||
YogaMeasureMode heightMode,
|
||||
@Nullable int[] attachmentsPositions) {
|
||||
@Nullable float[] attachmentsPositions) {
|
||||
SeekBar reactSlider = new ReactSlider(context, null, STYLE);
|
||||
final int spec =
|
||||
View.MeasureSpec.makeMeasureSpec(
|
||||
|
||||
+1
-1
@@ -210,7 +210,7 @@ public class ReactSwitchManager extends SimpleViewManager<ReactSwitch>
|
||||
YogaMeasureMode widthMode,
|
||||
float height,
|
||||
YogaMeasureMode heightMode,
|
||||
@Nullable int[] attachmentsPositions) {
|
||||
@Nullable float[] attachmentsPositions) {
|
||||
ReactSwitch view = new ReactSwitch(context);
|
||||
view.setShowText(false);
|
||||
int measureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
|
||||
|
||||
@@ -120,7 +120,7 @@ public class ReactTextViewManager
|
||||
YogaMeasureMode widthMode,
|
||||
float height,
|
||||
YogaMeasureMode heightMode,
|
||||
@Nullable int[] attachmentsPositions) {
|
||||
@Nullable float[] attachmentsPositions) {
|
||||
|
||||
return TextLayoutManager.measureText(
|
||||
context,
|
||||
|
||||
@@ -216,7 +216,7 @@ public class TextLayoutManager {
|
||||
float height,
|
||||
YogaMeasureMode heightYogaMeasureMode,
|
||||
ReactTextViewManagerCallback reactTextViewManagerCallback,
|
||||
@Nullable int[] attachmentsPositions) {
|
||||
@Nullable float[] attachmentsPositions) {
|
||||
|
||||
// TODO(5578671): Handle text direction (see View#getTextDirectionHeuristic)
|
||||
TextPaint textPaint = sTextPaintInstance;
|
||||
@@ -234,6 +234,7 @@ public class TextLayoutManager {
|
||||
if (text == null) {
|
||||
throw new IllegalStateException("Spannable element has not been prepared in onBeforeLayout");
|
||||
}
|
||||
|
||||
BoringLayout.Metrics boring = BoringLayout.isBoring(text, textPaint);
|
||||
float desiredWidth = boring == null ? Layout.getDesiredWidth(text, textPaint) : Float.NaN;
|
||||
|
||||
@@ -412,9 +413,9 @@ public class TextLayoutManager {
|
||||
|
||||
// The attachment array returns the positions of each of the attachments as
|
||||
attachmentsPositions[attachmentPosition] =
|
||||
(int) Math.ceil(PixelUtil.toSPFromPixel(placeholderTopPosition));
|
||||
PixelUtil.toSPFromPixel(placeholderTopPosition);
|
||||
attachmentsPositions[attachmentPosition + 1] =
|
||||
(int) Math.ceil(PixelUtil.toSPFromPixel(placeholderLeftPosition));
|
||||
PixelUtil.toSPFromPixel(placeholderLeftPosition);
|
||||
attachmentIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user