React Native: Determine number of lines of Text component

前端 未结 4 1112

As the title says, I\'ve been trying to find a way to determine the number of lines the text component AFTER it has been given text. Look at my example below.



        
4条回答
  •  庸人自扰
    2020-12-06 09:52

    It looks like React Native 0.24 implements an onLayout function
    http://facebook.github.io/react-native/docs/text.html#onlayout

    onLayout function
    Invoked on mount and layout changes with
    {nativeEvent: {layout: {x, y, width, height}}}

    So it looks like you could pass an onLayout callback function, get the height of the Text component and then do some calculations using the line height to get to the number of lines

提交回复
热议问题