Coder Social home page Coder Social logo

flex: 1 does not set flexGrow: 1 about yoga HOT 9 OPEN

darkbasic avatar darkbasic commented on June 10, 2024 2
flex: 1 does not set flexGrow: 1

from yoga.

Comments (9)

ecreeth avatar ecreeth commented on June 10, 2024

Setting the style flex: 1 is supposed to set flexGrow: 1, flexShrink: 1 and flexBasis: "auto".

image

from yoga.

darkbasic avatar darkbasic commented on June 10, 2024

@ecreeth flex: 1 doesn't set flexGrow: 1, flexShrink: 1, flexBasis: 0 either, because flexGrow: 1, flexShrink: 1, flexBasis: 0 renders correctly (see screenshot below) while flex: 1 doesn't (see previous screenshot).

react native flex basis 0

from yoga.

mxcihak avatar mxcihak commented on June 10, 2024

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)

from yoga.

darkbasic avatar darkbasic commented on June 10, 2024

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.

from yoga.

dharit-tan avatar dharit-tan commented on June 10, 2024

Bump, seeing this as well!

from yoga.

matart15 avatar matart15 commented on June 10, 2024

exact same.
and this issue is closed without explanation
facebook/react-native#11565

from yoga.

lunaleaps avatar lunaleaps commented on June 10, 2024

Can we move this issue to the yoga repo?
cc @NickGerleman

from yoga.

NickGerleman avatar NickGerleman commented on June 10, 2024

https://developer.mozilla.org/en-US/docs/Web/CSS/flex

One-value syntax: the value must be one of:

  1. a valid value for : then the shorthand expands to flex: <flex-grow> 1 0.
  2. a valid value for : then the shorthand expands to flex: 1 1 <flex-basis>.

So, on the web, the number should lead to:

  1. Flex shrink being set to 1
  2. Flex grow getting set to n if it is a number, or 1 if it is a length
  3. Flex basis is set to n if it is a length, or 0 if it is a number

I 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, and flexShrink if negative. https://reactnative.dev/docs/layout-props#flex

62f4719 from a few years ago has Yoga doing the right thing when opted into useWebDefaults (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.

from yoga.

darkbasic avatar darkbasic commented on June 10, 2024

If this is indeed the case, nice catch! Breaking or not the current defaults make little sense and are pretty annoying and confusing.

from yoga.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.