Skip to content

Flex styles are not working for WebView #11101

Closed

Description

@NoelBroda

Description

What I did: Check the rnplay
What is happening: Flex styles are not working for WebView
What should happens: Flex working for WebView

Reproduction

https://rnplay.org/apps/K8tUAw

Check line 24 (<WebView style={styles.webview} source={{uri: 'http://random.org'}}></WebView>).
Replace that line for: <View style={styles.webview}></View> and you will see that the View is working with Flex values.

If you add a width: 300 value in styles.webview (for the WebView component), you will see it will works.

Solution

No idea.

Additional Information

  • React Native version:
    react-native-cli: 1.2.0
    react-native: 0.37.0
  • Platform: Both
  • Operating System: MacOS

Activity

  1. mkonicek commented on Nov 27, 2016

    @mkonicek
    Contributor

    Here's a WebView stretched to fill its parent: https://rnplay.org/apps/z3g5qw

  2. mkonicek commented on Nov 27, 2016

    @mkonicek
    Contributor
  3. kaykaul commented on Mar 31, 2017

    @kaykaul

    @mkonicek
    I'm running react-native v 0.42.0 and am facing problems in laying out WebView with flex

    <View style={{flex: 1, backgroundColor: 'red'}}>
                    <WebView style={{flex: 10, backgroundColor: 'yellow'}} source={{
                        html: `
                        <html>
                            <head></head>
                            <body style="background-color: red;">
                                Hi this is a html body
                            </body>
                        </html>    
                        `
                    }}/>
                    <Text style={{flex:1, backgroundColor: 'blue'}}>
                        Hello There!
                    </Text>
                </View>
    

    In the above snippet, the WebView flex should cover more height as I have set flex=10. But that's not the case.
    simulator screen shot 31-mar-2017 7 24 04 pm

    Comparing the above to working flex example:

    <View style={{flex: 1, backgroundColor: 'red'}}>
                    <Text style={{flex:10, backgroundColor: 'yellow'}}>
                        Hi Again!
                    </Text>
                    <Text style={{flex:1, backgroundColor: 'blue'}}>
                        Hello There!
                    </Text>
                </View>
    

    simulator screen shot 31-mar-2017 7 23 31 pm

  4. daltonrenaldo commented on Dec 6, 2017

    @daltonrenaldo

    I am having similar issues... it seems flex is always overridden to be flex: 1 on the webview

  5. zfang6 commented on Dec 21, 2017

    @zfang6

    Is this issue addressed?

  6. LeeZC commented on Mar 1, 2018

    @LeeZC

    hi guys , i fixed in my case, by package a father view , like:
    <View style={{flex:10}}>
    <WebView style={{flex:1}} />
    </View>
    <View style={{flex:1}}>
    <WebView style={{flex:1}} />
    </View>

  7. locked as resolved and limited conversation to collaborators on May 24, 2018
  8. added
    Resolution: Locked
    on Jul 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution: Locked

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions