Open esbenvb opened 4 days ago
I had the same problem on React Native New Architecture iOS. Measuring a <Text/>
in the onLayout event returned the <Svg/>
size, not the <Text/>
size, and the onLayout event never fired again.
<View
style={{
width: textSize ? textSize.width : 0,
height: textSize.height ? textSize.height : 0,
opacity: textSize ? 1 : 0,
borderWidth: 4,
borderColor: red,
}}
...
>
<Svg width="150" height="14">
<Text
dx={1 + 10}
dy={10}
fontSize={12}
fontWeight="800"
fontFamily="Onest-SemiBold"
textAnchor="start"
stroke="rgba(0, 0, 0, 1)"
strokeWidth={2}
strokeOpacity={0.75}
onLayout={(e) => {
// same e.nativeEvent.layout
e.target.measure((x, y, width, height) => {
setTextSize({ width, height });
});
}}
>
{props.text}
</Text>
...
</Svg>
</View>
width: 150, height: 0
onLayout={(e) => { // same e.nativeEvent.layout e.target.measure((x, y, width, height) => { setTextSize({ width, height }); }); }}
Same result, I get the width of the container here instead of the Text element
Description
I use the
<Text>
element and add an onLayout callback, and get a width which is the entire available space, not the dimensions of the text itself.With new architecture - reports wrong width
Without new architecture - reports correct width
Steps to reproduce
Clone the repo, or try yourself with this code:
Snack or a link to a repository
https://github.com/esbenvb/rn-font-weight-issue
SVG version
15.9.0.
React Native version
0.76.2
Platforms
iOS
JavaScript runtime
Hermes
Workflow
React Native
Architecture
Fabric (New Architecture)
Build type
Debug app & dev bundle
Device
iOS simulator
Device model
No response
Acknowledgements
Yes