How to adjust font size to fit view in React Native for Android?

后端 未结 6 2109
死守一世寂寞
死守一世寂寞 2020-12-16 10:14

How I can make the font size of the text auto change inside a view in react native?

I have text with different lengths, some of which doesn\'t fit the view so decrea

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-16 10:43

    A bit improved Jeffy Lee code worked for me

    const AdjustLabel = ({
      fontSize, text, style, numberOfLines
    }) => {
      const [currentFont, setCurrentFont] = useState(fontSize);
    
      return (
         {
            const { lines } = e.nativeEvent;
            if (lines.length > numberOfLines) {
              setCurrentFont(currentFont - 1);
            }
          } }
        >
          { text }
        
      );
    };

提交回复
热议问题