flex: 1 does not set flexGrow: 1 #1323
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
Setting the style
flex: 1
is supposed to setflexGrow: 1
,flexShrink: 1
andflexBasis: "auto"
.Apparently it doesn't work because setting
flex: 1
produces a different output thanflexGrow: 1
,flexShrink: 1
andflexBasis: "auto"
(see screenshots below).React Native version:
react-native-elements
is at version 3.4.1.Steps To Reproduce
The view you see in the Flipper screenshots below is the one created by
react-native-elements
'sListItem.Content
, which applies the styles instyles.container
to its childrenView
(which gets automatically created):react-native-elements
'sListItem.Content
also appliesflex: 1
to its automatically created childrenView
, but despite that if I omitflexGrow: 1
instyles.container
the layout breaks. That means that the shorthandflex: 1
somehow does not setflexGrow: 1
.Expected Results
flex: 1
should automatically setflexGrow: 1
,flexShrink: 1
andflexBasis: "auto"
. It shouldn't be necessary to manually setflexGrow: 1
.Snack, code example, screenshot, or link to a repository:
flexGrow: 1
+flexShrink: 1
+flexBasis: "auto"
:flex: 1
:@ecreeth
flex: 1
doesn't setflexGrow: 1, flexShrink: 1, flexBasis: 0
either, becauseflexGrow: 1, flexShrink: 1, flexBasis: 0
renders correctly (see screenshot below) whileflex: 1
doesn't (see previous screenshot).Same here. For me this happens when I set container to flex: 1 (everything OK) then to flexGrow: 1 (everything OK) then to flex:1 (container disappears - height: 0)
I'm not sure but I think it might be a react-native regression, if I recall correctly I've tried to downgrade several major versions and the issue disappeared. In the end I've decided to simply change my CSS because it was easier than debugging it.
Bump, seeing this as well!
exact same.
and this issue is closed without explanation
https://github.com/facebook/react-native/issues/11565
Can we move this issue to the yoga repo?
cc @NickGerleman
https://developer.mozilla.org/en-US/docs/Web/CSS/flex
So, on the web, the number should lead to:
n
if it is a number, or1
if it is a lengthn
if it is a length, or0
if it is a numberI confirmed this by looking at https://www.w3.org/TR/css-flexbox-1/#flex-common
The React Native/Yoga version of flex is documented here, and I checked that it is how the code works. The value for flex will contribute to
flexGrow
if positive, andflexShrink
if negative. https://reactnative.dev/docs/layout-props#flex62f47190fb
from a few years ago has Yoga doing the right thing when opted intouseWebDefaults
(but I think actually doing the wrong thing wrt flexbasis should be set to zero). But changing these defaults for existing RN styles would be pretty breaking.If this is indeed the case, nice catch! Breaking or not the current defaults make little sense and are pretty annoying and confusing.