onLayout不会在WebView上触发

Bru*_*rad 9 react-native

我试图onLayout在我身上使用,WebView但它没有触发.

export default class Sandbox extends Component {
  render() {
    return (
      <View style={styles.fill}>
        <WebView
          onLayout={(event) => {
            console.log(event.nativeEvent.layout)
          }}
          source={{uri: 'https://github.com/facebook/react-native'}}
        />
      </View>
    )
  }
}

const styles = StyleSheet.create({
  fill: {
    flex: 1,
  },
})
Run Code Online (Sandbox Code Playgroud)

有人知道为什么这不会触发?我检查了文档,似乎可以使用.

小智 0

如果您想获取 WebView 尺寸,可以onLayout在容器视图上使用。否则,如果您需要获取 HTML 内容的尺寸,您可以查看这篇文章onContentSizeChange在 Android 上使用。