0
我必須在measure()
函數的幫助下測量幾個值。
因爲是異步操作,我只能寫:同時調用多個「測量」操作
this.refContainerView.measure((x, y, width, height, pageX, pageY) => {
const containerViewHeight = height
this.refCommentList.measure((x, y, width, height, pageX, pageY) => {
const commentListOffset = pageY
const commentListHeight = height
// do something
})
})
,如果需要測量更多的組件,它看起來像一個回調地獄。
是否可以同步編寫代碼,例如在await
或其他幫助下,例如:
const contaierView = this.refContainerView.measure()
const commentList = this.refCommentList.measure()
// and then do something with
contaierView {x, y, width, height, pageX, pageY}
commentList {x, y, width, height, pageX, pageY}