Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

width is specified as the screen width by default #107

Open
otusweb opened this issue Feb 26, 2019 · 6 comments
Open

width is specified as the screen width by default #107

otusweb opened this issue Feb 26, 2019 · 6 comments

Comments

@otusweb
Copy link

otusweb commented Feb 26, 2019

It would be great if the component could just take the width of its container (could use the 'stretch' mode)

As of right now, I have to calculate the width manually otherwise the web view overflows the container.

@iou90
Copy link
Owner

iou90 commented Feb 27, 2019

You can wrap a View to do this:

<View
  style={{ flex: 1, alignSelf: 'stretch' }}
  onLayout={event => {
    this.setState({ webviewWidth: event.nativeEvent.layout.width });
  }}
>
  <AutoHeightWebView
    style={{ width: this.state.webviewWidth }}

@otusweb
Copy link
Author

otusweb commented Feb 27, 2019

Sure I can do that. But that is pretty complex. If I want other react control to stretch the whole screen I don't have to do the logic you just mention.

It would be great if the code could look for the other layout attribute than width before deciding to set its width to the screen width.
Maybe what we'd need is a way to lock the width and let the default layout attribute take care of setting the size when in that mode.

@iou90
Copy link
Owner

iou90 commented Feb 28, 2019

@otusweb The only way to horizontally stretch a WebView is to set explicit width: react-native-webview/react-native-webview#27
I will try with onLayout inside this lib when this PR (react-native-webview/react-native-webview#206) was merged.

@otusweb
Copy link
Author

otusweb commented Feb 28, 2019

@iou90 Good to know and thanks for considering this feature request!

@iou90
Copy link
Owner

iou90 commented Mar 24, 2019

Unfortunately, I found the onLayout callback on NativeWebView of react-native-webview can not provide the width of its container like View does, may be they should put the onLayout callback to it's View wrapper.

@vasylnahuliak
Copy link

vasylnahuliak commented Oct 25, 2022

It just helped me style={{ width: '100%' }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants