fix(android): use ceil for split-segment width to match commonmark path and rendered TextView#282
Conversation
…ath and rendered TextView
|
Finally nor round nor ceil is right Calculations definitely depend on left position of the text Seems like real calculation is cc @hryhoriiK97 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.`;
const counterCeilExample = `33333 aa xx 1 rrrrrr rrrrrr 1 www rrrrrr 111 www www 1 e , 111 1 e rrrrrr , aa www w e xx www aa 33333 111 1 rrrrrr aa e 33333 , e aa 111 w xx e , e 111 rrrrrr aa xx xx rrrrrr , aa xx e rrrrrr w 111 33333 w 33333 , w 111.`;
export default function PartsPlayground() {
console.log("rendering", PixelRatio.get(), PixelRatio.roundToNearestPixel(379));
return (
<View className="flex-1 bg-background p-0 pt-safe">
<EnrichedMarkdownText
containerStyle={{
backgroundColor: "red",
width: 379,
marginLeft: 16,
}}
flavor="github"
markdown={markdownB}
/>
<View className="h-6" />
<EnrichedMarkdownText
containerStyle={{
backgroundColor: "red",
width: 103.5,
marginLeft: 17,
}}
flavor="github"
markdown={counterCeilExample}
/>
</View>
);
} |
|
It seems like the If yogaWidth = ceil(right) - floor(left) ceilWidth = ceil(right - left) then yogaWidth - ceilWidth ∈ {0, 1} So for ceilWidth we have that max error is just 1, and 2 for others. At least seriously less probability to get the issue. Even if some re-measurement will be done in the future (or now but I have no idea how) ceil seems like the best choice. |
Nice analysis, |
hryhoriiK97
left a comment
There was a problem hiding this comment.
@istarkov thank you for the fix! It will be available in tomorrow’s nightly release 🙂
Fixes #281
measureAndCacheSplittruncated the Yoga width withwidth.toInt(),while the commonmark paths
https://github.com/software-mansion-labs/react-native-enriched-markdown/blob/main/android/src/main/java/com/swmansion/enriched/markdown/MeasurementStore.kt#L523
https://github.com/FylerSearch/react-native-enriched-markdown/blob/cd484331e51a1e937fada0431e80ab29943dc68f/android/src/main/java/com/swmansion/enriched/markdown/MeasurementStore.kt#L559-L561
already use
ceil(maxWidth).toInt().Yoga rounds the rendered TextView frame UP to the next pixel.
Locally I tested with the following code, and wasn't able to reproduce, (BTW it's rare bug on random ;-))