[react native]<Text>에서 line 갯수 알아내기

지리·2023년 6월 1일
post-thumbnail

위의 이미지와 같이 line 갯수가 많아지면 열기버튼을 눌러서 글을 더 볼 수 있고, line 갯수가 일정 수 이상이 안되면 더보기 버튼이 없어지게 만들어야 할때 <Text>onTextLayout을 이용하면 <Text> 컴포넌트안에 있는 line 갯수를 알 수 있다!

function getLineLength(event){
  console.log(event.nativeEvent.lines.length)
}

<Text onTextLayout={getLineLength}>
  text contents
</Text>

참고
Determine the Number of Lines a Text Component Takes Up in React Native

profile
공부한것들, 경험한 것들을 기록하려 노력합니다✨

0개의 댓글