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

flex: 1 overrides the parent's flex-basis to 0 when it should be the content height #12200

Closed
sebmarkbage opened this issue Feb 3, 2017 · 1 comment
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@sebmarkbage
Copy link
Contributor

sebmarkbage commented Feb 3, 2017

flex: 1 sets flex-basis: 0 implicitly. However, in the web, when that happens in an inner node, that is only used for the flex-basis of that node. The final size of the node is still used for flex-basis: auto of the outer node.

The effect is that in this scenario React Native treats this large paragraph as flex-basis: 0...

<View style={{
    top: 100,
    width: 300,
    height: 300,
    flexDirection: 'column',
    backgroundColor: '#000',
  }}>
  <Text style={{ flexGrow: 1, backgroundColor: '#c00' }}>
    Hello world
  </Text>
  <View style={{ flexGrow: 1, flexDirection: 'column', backgroundColor: '#0c0' }}>
    <View style={{ flex: 1 }}>
      <Text style={{ backgroundColor: '#0c0' }}>
        Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
      </Text>
    </View>
  </View>
</View>

screen shot 2017-02-03 at 3 09 16 pm

Equivalent HTML/CSS for the web treats it as flex-basis: content.

<div style="
    position: relative;
    display: flex;
    top: 100px;
    width: 300px;
    height: 300px;
    flex-direction: column;
    background-color: #000;
  ">
  <div style="flex-grow: 1; background-color: #c00">
    Hello world
  </div>
  <div style="flex-grow: 1; overflow: hidden; display: flex; flex-direction: column; background-color: #0c0">
    <div style="flex: 1; overflow: hidden; display: flex;">
      <div style="background-color: #0c0; overflow: hidden;">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
      </div>
    </div>
  </div>
</div>

screen shot 2017-02-03 at 3 09 26 pm

If you remove flex: 1 from the example, it works as expected.

Tested in master. I believe this might be a bug in Yoga but not sure if there are other defaults that are not propagating correctly.

@sebmarkbage sebmarkbage changed the title flex: 1 overrides flex: 1 overrides the parent's flex-basis to 0 when it should be the content height Feb 3, 2017
@hramos
Copy link
Contributor

hramos commented May 25, 2017

We're cutting down on the number of outstanding issues, in order to allow us to focus. I'm closing this issue because it has been open for over 60 days with no activity. If you think it should still be opened let us know why. PRs are always welcome.

@hramos hramos closed this as completed May 25, 2017
@hramos hramos added the Icebox label May 26, 2017
@facebook facebook locked as resolved and limited conversation to collaborators May 29, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

3 participants