Skip to content

Commit 8e37d0b

Browse files
NickGerlemanmeta-codesync[bot]
authored andcommitted
Support textBreakStrategy and justificationMode for Selectable Facsimile TextView (facebook#55660)
Summary: Pull Request resolved: facebook#55660 `getReactTextUpdateFromPreparedLayout()` hardcoded `textBreakStrategy` to `BREAK_STRATEGY_HIGH_QUALITY` and `justificationMode` to `0`, causing user-specified values like `textBreakStrategy: "simple"` or `textAlign: "justify"` to be ignored when the PreparedLayout code path is used via `ReferenceStateWrapper`. This change surfaces the `textBreakStrategy` and `justificationMode` values already computed in `TextLayoutManager.createLayout()` by: - Introducing a `CreateLayoutResult` wrapper to return them alongside the `Layout` - Adding both fields to `PreparedLayout` - Propagating them through `FabricUIManager.reusePreparedLayoutWithNewReactTags()` - Using the real values in `ReactTextViewManager.getReactTextUpdateFromPreparedLayout()` Changelog: [Internal] Differential Revision: D93933310
1 parent 9846369 commit 8e37d0b

File tree

4 files changed

+49
-27
lines changed

4 files changed

+49
-27
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,9 @@ public PreparedLayout reusePreparedLayoutWithNewReactTags(
687687
preparedLayout.getLayout(),
688688
preparedLayout.getMaximumNumberOfLines(),
689689
preparedLayout.getVerticalOffset(),
690-
reactTags);
690+
reactTags,
691+
preparedLayout.getTextBreakStrategy(),
692+
preparedLayout.getJustificationMode());
691693
}
692694

693695
@AnyThread

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/PreparedLayout.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ internal class PreparedLayout(
2020
val maximumNumberOfLines: Int,
2121
val verticalOffset: Float,
2222
val reactTags: IntArray,
23+
val textBreakStrategy: Int,
24+
val justificationMode: Int,
2325
)

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewManager.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ public constructor(
206206
spanned,
207207
-1,
208208
textAlign,
209-
Layout.BREAK_STRATEGY_HIGH_QUALITY,
210-
0,
209+
preparedLayout.textBreakStrategy,
210+
preparedLayout.justificationMode,
211211
)
212212
}
213213

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.kt

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -821,15 +821,16 @@ internal object TextLayoutManager {
821821
}
822822

823823
return createLayout(
824-
text,
825-
paint,
826-
attributedString,
827-
paragraphAttributes,
828-
width,
829-
widthYogaMeasureMode,
830-
height,
831-
heightYogaMeasureMode,
832-
)
824+
text,
825+
paint,
826+
attributedString,
827+
paragraphAttributes,
828+
width,
829+
widthYogaMeasureMode,
830+
height,
831+
heightYogaMeasureMode,
832+
)
833+
.layout
833834
}
834835

835836
private fun createLayout(
@@ -841,7 +842,7 @@ internal object TextLayoutManager {
841842
widthYogaMeasureMode: YogaMeasureMode,
842843
height: Float,
843844
heightYogaMeasureMode: YogaMeasureMode,
844-
): Layout {
845+
): CreateLayoutResult {
845846
val boring = isBoring(text, paint)
846847

847848
val textBreakStrategy =
@@ -899,19 +900,23 @@ internal object TextLayoutManager {
899900
)
900901
}
901902

902-
return createLayout(
903-
text,
904-
boring,
905-
width,
906-
widthYogaMeasureMode,
907-
includeFontPadding,
903+
return CreateLayoutResult(
904+
createLayout(
905+
text,
906+
boring,
907+
width,
908+
widthYogaMeasureMode,
909+
includeFontPadding,
910+
textBreakStrategy,
911+
hyphenationFrequency,
912+
alignment,
913+
justificationMode,
914+
ellipsizeMode,
915+
maximumNumberOfLines,
916+
paint,
917+
),
908918
textBreakStrategy,
909-
hyphenationFrequency,
910-
alignment,
911919
justificationMode,
912-
ellipsizeMode,
913-
maximumNumberOfLines,
914-
paint,
915920
)
916921
}
917922

@@ -937,7 +942,7 @@ internal object TextLayoutManager {
937942
)
938943
val baseTextAttributes =
939944
TextAttributeProps.fromMapBuffer(attributedString.getMapBuffer(AS_KEY_BASE_ATTRIBUTES))
940-
val layout =
945+
val result =
941946
createLayout(
942947
text,
943948
newPaintWithAttributes(baseTextAttributes, context),
@@ -956,14 +961,21 @@ internal object TextLayoutManager {
956961

957962
val verticalOffset =
958963
getVerticalOffset(
959-
layout,
964+
result.layout,
960965
paragraphAttributes,
961966
height,
962967
heightYogaMeasureMode,
963968
maximumNumberOfLines,
964969
)
965970

966-
return PreparedLayout(layout, maximumNumberOfLines, verticalOffset, reactTags)
971+
return PreparedLayout(
972+
result.layout,
973+
maximumNumberOfLines,
974+
verticalOffset,
975+
reactTags,
976+
result.textBreakStrategy,
977+
result.justificationMode,
978+
)
967979
}
968980

969981
@JvmStatic
@@ -1373,6 +1385,12 @@ internal object TextLayoutManager {
13731385
BoringLayout.isBoring(text, paint, TextDirectionHeuristics.FIRSTSTRONG_LTR, true, null)
13741386
}
13751387

1388+
private class CreateLayoutResult(
1389+
val layout: Layout,
1390+
val textBreakStrategy: Int,
1391+
val justificationMode: Int,
1392+
)
1393+
13761394
private class AttachmentMetrics {
13771395
var wasFound: Boolean = false
13781396
var top: Float = 0f

0 commit comments

Comments
 (0)