diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/FontMetricsUtil.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/FontMetricsUtil.java index 8d25d24b250613..019573d4fb4baa 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/FontMetricsUtil.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/FontMetricsUtil.java @@ -61,22 +61,28 @@ public static WritableMap getFontMetrics( line.putString( "text", text.subSequence(layout.getLineStart(i), layout.getLineEnd(i)).toString()); - for (int j = 0; j < textLayoutRegions.getCount(); j++) { + lines.pushMap(line); + } + + for (int j = 0; j < textLayoutRegions.getCount(); j++) { + for (int i = 0; i < layout.getLineCount(); i++) { + Rect bounds = new Rect(); + layout.getLineBounds(i, bounds); + MapBuffer textLayoutRegion = textLayoutRegions.getMapBuffer(j); + int offset = layout.getLineEnd(i) >= textLayoutRegion.getInt(1) ? 0 : 1; int startIndex = Math.max(layout.getLineStart(i), textLayoutRegion.getInt(0)); - int endIndex = Math.min(layout.getLineEnd(i), textLayoutRegion.getInt(1)); + int endIndex = Math.min(layout.getLineEnd(i), textLayoutRegion.getInt(1)) - offset; - if (startIndex > endIndex) { + if (startIndex > endIndex + 1) { break; } - int offset = layout.getLineEnd(i) >= textLayoutRegion.getInt(1) ? 0 : 1; - Rect regionBounds = new Rect( (int)layout.getPrimaryHorizontal(startIndex), bounds.top, - (int)layout.getPrimaryHorizontal(endIndex - offset), + (int)layout.getPrimaryHorizontal(endIndex), bounds.bottom); WritableMap region = Arguments.createMap(); @@ -89,8 +95,6 @@ public static WritableMap getFontMetrics( region.putInt("line", i); regions.pushMap(region); } - - lines.pushMap(line); } WritableMap textLayoutMetrics = Arguments.createMap();