9

I'm trying to use onLayout on my WebView but it's not triggering.

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,
  },
})

Have someone an idea about why this isn't triggering? I checked the documentation and it seems to be available to be used.

Bruno Konrad
  • 101
  • 3

1 Answers1

0

If you want to get the WebView dimensions you can use the onLayout on the container view. Otherwise, If you need to get the dimensions of the HTML content you can have a look at this post or use onContentSizeChange on Android.

Mariano Miani
  • 182
  • 1
  • 3
  • 15