注意初始化阶段需要delay至少500ms再去调用,不然可能访问不到节点
setTimeout(() => {
const query = Taro.createSelectorQuery()
query.select(".toggle-open").boundingClientRect()
query.select(".notice-world").boundingClientRect()
query.select('.check-world-len').boundingClientRect()
query.exec((res) => {
const out1Width = res[0]?.width;
const out2Width = res[1]?.width;
const intWidth = res[2]?.width;
if (intWidth && (intWidth < out1Width || intWidth < out2Width)) {
this.setState({
showUpIcon: false
})
}
})
}, 1000)
{toggleNotice ?
<View className='notice-world notice-world-open' ref={(ref) => { myInput = ref }}><Text className="check-world-len">{unescape(noticeWorld)}</Text></View>
:
\<View className='toggle-open ' ref={(ref) => { myInput = ref }}><Text className="check-world-len">{unescape(noticeWorld).replace(/\n/, '\n')}</Text></View>
}
{showUpIcon && <Image className='notice-img-close notice-img-open' src={noticeOpenImg} />}
实现效果