Skip to content

feat: support react-native#382

Open
igorwessel wants to merge 23 commits into
styled-components:mainfrom
igorwessel:feat/support-react-native
Open

feat: support react-native#382
igorwessel wants to merge 23 commits into
styled-components:mainfrom
igorwessel:feat/support-react-native

Conversation

@igorwessel

@igorwessel igorwessel commented Aug 21, 2022

Copy link
Copy Markdown

Summary

Hello guys! basically I'm trying to finalize a PR that was adding support for react-native.
Can find out a little more about it here: #273, thanks @diegotsi

My idea is basically the same as this PR except that I'll be adding the default use without utility props and the x function with utility props.

Test plan

const WithoutUtilityProps = styled.View`
  background-color: cool-gray-500;
  padding: 2;
`;

const WithConfig = styled.View.withConfig({})`
  background-color: rose-900;
  padding: 2;
`;

const StyledSomeComponent = styled(View)`
  background-color: teal-900;
  padding: 2;
`;

const WithUtilityProps = styled.ViewBox``;

const UsingAS = styled.View``;

const Test = () => {
  return (
    <ThemeProvider theme={defaultTheme}>
      <x.View p={2} bg="blue-gray-900">
        <x.Text color="blue-gray-500">Text X elements</x.Text>
      </x.View>
      <UsingAS as={x.Text} p={2} bg="emerald-500">
        Now is a x.Text with all props from Text (RN) + utility props from
        xstyled
      </UsingAS>
      <WithUtilityProps p={2}>
        <x.Text>With Utility Props</x.Text>
      </WithUtilityProps>
      <WithConfig>
        <x.Text color="white">With Config</x.Text>
      </WithConfig>
      {/*@ts-expect-error */}
      <WithoutUtilityProps bg="black">
        <x.Text>Without Utility Props</x.Text>
      </WithoutUtilityProps>
      <StyledSomeComponent>
        <x.Text color="white">Styled(SomeComponent)</x.Text>
      </StyledSomeComponent>
    </ThemeProvider>
  );
};

Working with the latest react-native template:

Captura de Tela 2022-08-21 às 08 32 37

types

working

@igorwessel igorwessel force-pushed the feat/support-react-native branch from df24a9f to 1eda12a Compare August 21, 2022 13:26
@igorwessel igorwessel marked this pull request as ready for review August 22, 2022 12:22
@JulioCVaz

Copy link
Copy Markdown

Thanks for this @igorwessel 🚀

This will help us a lot

@felipefialho

Copy link
Copy Markdown

Nice @igorwessel! 😄

@jguddas

jguddas commented Aug 22, 2022

Copy link
Copy Markdown
Contributor

I prefer @xstyled/styled-components/native over @xstyled/styled-components-native due to all the duplication.

Maybe there is a way to trim this down and get rid of the dependency for react-native itself?

@igorwessel

igorwessel commented Aug 22, 2022

Copy link
Copy Markdown
Author

I prefer @xstyled/styled-components/native over @xstyled/styled-components-native due to all the duplication.

We can maybe install as a dependency in @xstyled/styled-components and export all this guy

Maybe there is a way to trim this down and get rid of the dependency for react-native itself?

The react-native package is in the development dependencies, without it there is no way to perform the tests

@igorwessel

Copy link
Copy Markdown
Author

I realized that a lot of the code is duplication that is not worth it to move in new package. I made some changes in the functions that create the styled, xstyled, css to receive as parameters the dependencies of the styled, css function that will be used. We were able to have these functions with greater flexibility, which allows us to reuse them both for native/web.

I have separated the responsibilities of defining an interface into new functions so that we can use the functions that create styled,xstyled without an interface and then define from those returned values. e.g:

const { scStyled, styled, xstyled } = createStyled(scStyled, css, generator)

Object.keys(scStyled).forEach(key => styled[key] = styled(key))

Which allows us to reuse them both for native/web.

Finally I created a package inside styled-components so we can use @xstyled/styled-components/native

Captura de Tela 2022-08-24 às 06 48 40

We can still have them as a separate package, and just put it as a styled-components dependency.
With separate package allow people to just install the native package.

@rbalves

rbalves commented Aug 30, 2022

Copy link
Copy Markdown

🚀

@igorwessel

Copy link
Copy Markdown
Author

@gregberge When you have time, can you take a look?

@gregberge

Copy link
Copy Markdown
Collaborator

@igorwessel CI fails, could you try to fix it?

@igorwessel

igorwessel commented Sep 22, 2022

Copy link
Copy Markdown
Author

@gregberge I needed to update the react-simple-editor dependency to @0.11.3 as it doesn't exactly include react@^16 peer-deps. So the NPM can resolve the dependencies without needing to set the flag --legacy-peer-deps.
I'll be sure to find some time this weekend to write something in the docs about react-native.

@gregberge

Copy link
Copy Markdown
Collaborator

@igorwessel after the doc, I could merge it.

@gregberge

Copy link
Copy Markdown
Collaborator

Thanks @igorwessel can you rebase please?

@igorwessel igorwessel force-pushed the feat/support-react-native branch 2 times, most recently from 2830fed to df438d4 Compare November 3, 2022 12:11
@igorwessel

Copy link
Copy Markdown
Author

@gregberge Sorry for the delay, I had some problems but the rebase is done. 👍

@JulioCVaz

Copy link
Copy Markdown

@gregberge Hey Greg, how you doing?

Have a any expectation to includes this support to the RN? It's will be help us a lot.

@sciotta

sciotta commented May 2, 2023

Copy link
Copy Markdown

@igorwessel can you rebase it again? It's a nice feature and an awesome improvement for this library.

@igorwessel igorwessel force-pushed the feat/support-react-native branch from df438d4 to cb0162f Compare May 3, 2023 21:43
@igorwessel

Copy link
Copy Markdown
Author

@thiagog3 done! 😄

@igorwessel

Copy link
Copy Markdown
Author

@probablyup @gregberge Is it ok for merge?

@D1no

D1no commented Jun 15, 2023

Copy link
Copy Markdown

@gregberge 🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏

@quantizor quantizor self-assigned this Jun 23, 2023
@quantizor

Copy link
Copy Markdown
Collaborator

Will review this weekend :)

@D1no

D1no commented Apr 23, 2024

Copy link
Copy Markdown

Any progress here? 👀 Is there something similar to xstyled out there (that is not tailwind) that supports also React Native?

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

Successfully merging this pull request may close these issues.