-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Use StyleSheet.create
in React Native
#2060
Use StyleSheet.create
in React Native
#2060
Conversation
🦋 Changeset detectedLatest commit: 2404b39 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 2404b39:
|
@Andarist any ideas how we can handle tests? Because |
Is there any way to retrieve the styles from some global registry or smth (when dealing with React Native)? I don't see anything fancy used in Styled Component's Could you check if this sort of stuff works with SC? If yes then we could check how they do it. If we won't be able to figure it out then we'd probably just merge this in and worry about that later - I would like for some research to happen first though so we could assess what to do based on the results. |
@efoken friendly 🏓 would you be able to check the things mentioned in the comment above? I hope to release Emotion 11 in the upcoming week - it would be great if we could manage to merge this in before that. |
I've done a little bit of digging and it seems that:
Is not actually true - this has been changed over 2 years ago: facebook/react-native@a8e3c7f#diff-28f312824659b615c3d5dba1bca670c630afbb7490258d6d820b90ef3d0f0027R372 . We might however deal with RNW or smth in tests here and it might have not adhered to that change.
This is where SC renders styles: |
@Andarist I had a look on how styled-components is testing the styles, but what you must know is, that they are using the So maybe we can setup another jest script using an extra config, what you think? The config styled-components is using: https://github.com/styled-components/styled-components/blob/28b4c28f1ebd1ea5a34717df2fe49634461285b1/scripts/jest/config.native.js |
This actually is not true, it returns an object of numbers 😄 That why we use it like so: const styleSheet = StyleSheet.create({ generated: styles })
return styleSheet.generated |
3c46c7a
to
4fdd827
Compare
I'm working on fixing the tests for hours 😄 Because when I use Jest with react-native preset, some tests work fine. But when it comes to react-primitives, all native/primitives tests break...
The reason why this breaks is, because 'react-native-web' creates some "object" with |
BTW, I also committed one change to flatten the styles before passing on to |
@Andarist the issue definitely comes from 'react-native-web', because it always returns an object of numbers with |
@Andarist Sorry for spam 😄 Just fixed the primitive tests with wrapping the For the native tests I can set up a |
That's an awesome fix! We probably should provide a custom matcher for this so people wouldn't have to write this by hand but this is not a blocker for this PR and can be done after v11 gets released.
Could you describe shortly what's the current status of this? What's broken, why, and how the proposed solution might help here? |
From what I see the same hack with |
|
Ok, I see that this has only worked for I'm fine with updating snapshots with those numbers for now. The important thing is that it's doable to retrieve styles even if they get registered as numbers. This seems to be fixable at matchers/serializers level and can be tackled in followup PRs. I have pushed the snapshot update to your branch. Gonna look in a moment at fixing flow errors. Would you be so kind to create a changeset for this change? |
... too late 😄 |
Hehe, ye - I've managed to get to it sooner in the end :P Thank you for your work! |
What:
Change to
StyleSheet.create
for React NativeWhy:
StyleSheet.create
creates an instance for the given styles and we prevent re-creation of that instance when the same styles come in. Besides thatStyleSheet.flatten
which was used before, creates inline styles with React Native Web, whileStyleSheet.create
create atomic CSS classes.How:
Change
StyleSheet.flatten
toStyleSheet.create
with an extra check to prevent re-creation.Checklist: