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

Display: contents #348

Open
natew opened this issue May 11, 2021 · 3 comments
Open

Display: contents #348

natew opened this issue May 11, 2021 · 3 comments

Comments

@natew
Copy link

natew commented May 11, 2021

Introduction

I've run into an issue trying to compose without breaking parent styles. One way to fix that is exporting the hook, but that does require quite a bit of cajoling on my end to collect props and pass them around properly.

Another solution is having display: contents work on react native. This would be a real help actually in a few areas, and to me is preferable.

@kelset
Copy link
Member

kelset commented May 12, 2021

👋 there - as stated in the README and the issue template, this repo is for long-form discussions. Yours seems more a question for StackOverflow instead.

@kelset kelset closed this as completed May 12, 2021
@natew
Copy link
Author

natew commented May 16, 2021

@kelset, isn't StackOverflow more for figuring out workarounds or getting code examples?

Display contents would have to be implemented on the layout/flexbox level, so it would need to be supported by the React Native engine itself. Seems like discussing support for that would be best at home here, as this is a proposal for changing and adding a feature to React Native itself and not anything to do with existing features.

It's also a pretty cool feature as it would probably save a lot of hassle in terms of composablity. For example using around a view you have today breaks composability:

function MyButton(props: ViewProps) {
   return (
      <Pressable style={{  ...grabJustLayoutAffectingProps(props.style) }}>
        <MyIcon />
        <View style={[{ ...myCustomStyles }, grabNonLayoutAffectingProps(props.style)]}>
           {props.children}
        </View>
     </Pressable>
   )
}

As you can see in this example, you have quite a weird problem now with composability. You'd have to implement grabJustLayoutAffectingProps and grabNonLayoutAffectingProps which is quite a challenge. Meanwhile with display: contents you could do:

function MyButton(props: ViewProps) {
   return (
      <Pressable style={{ display: 'contents' }}>
        <MyIcon />
        <View style={[{ ...myCustomStyles }, props.style]}>
           {props.children}
        </View>
     </Pressable>
   )
}

And no longer have to worry that your position absolute, or shadow, or margin, etc, will break.

@kelset
Copy link
Member

kelset commented May 17, 2021

I hope that you can understand that by reading your original comment it looked more like that you were asking for a workaround to fix your "issue trying to compose without breaking parent styles".

I'll reopen, maybe the FB team can give you feedback

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

No branches or pull requests

2 participants