Skip to content

Incorrect text measurement on Android. #281

@istarkov

Description

@istarkov

The text renders with extra vertical space / wrong wrapping compared to the actual content size. In the screenshot, the red background shows the measured container area is larger than expected.

To Reproduce

import { PixelRatio, View } from "react-native";
import { EnrichedMarkdownText } from "react-native-enriched-markdown";

const markdownB = `, it emphasizes higher goals requires a fundamental change in thinking and effort rather than working more odntly emphasizes that reaching higher goals  a fundamental change in thinking and effort rather than simply working more hours. fields, it consistently that reaching higher goals fundamental change in thinking and effort rather than simply working more hours.`;

export default function PartsPlayground() {
  return (
    <View className="flex-1 bg-background p-4 pt-safe">
      <EnrichedMarkdownText
        containerStyle={{
          backgroundColor: "red",
          width: 379,
        }}
        flavor="github"
        markdown={markdownB}
      />
    </View>
  );
}

See result

Image

Expected behavior

A text measured without blank line at the end

Image

Fast (client side) workaround fix

containerStyle={{
  backgroundColor: "red",
  width: PixelRatio.roundToNearestPixel(containerWidth),
}}

Tested workaround on a fixture which generates 600 blocks of random markdown and the issue is not reproduced.

So it looks like Android text measurement is sensitive to non-rounded / fractional device physical pixel width.

Device (please complete the following information):

  • Device: Pixel 9a (real and emulator)
  • OS: Android 16
  • Version 16

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions