emotion: Number in @emotion/native does not work
Current behavior:
If I pass a number to styled, it doesn’t work. I need to use toString()
styled.View`
height: ${{ paddingTop }: { paddingTop: number }) => props.paddingTop.toString()}px;
`
Expected behavior:
styled.View`
height: ${{ paddingTop }: { paddingTop: number }) => props.paddingTop}px;
`
Environment information:
reactversion: 16.9.0react-nativeversion: 0.61.2emotionversion: 10.0.20
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 8
- Comments: 20 (9 by maintainers)
Ok, so I’ve debugged this a little bit and it seems that
StyleSheet.createoutputs an object with numbers as values and currently, we allow for interpolating those values (numbers) - so it’s hard to differentiate between those special numbers and regular ones (like in your case).The native library was developed by @nitin42 , maybe he could take a look at this or at least clarify if this is intended, how he believes it should work etc.
Yeah, but it diverges from web code where putting a number works directly. You’re right, it does work on
styled-components!The problem with that is that it makes migrating from
styled-componentstoemotiontrickier 😉This prettiest way I found to write it was this:
Hi @nitin42, do you have any update for this problem?
Thank you!
Both are workarounds though. Could you describe complexity of implementing a “proper” solution? I suspect it would require tracking more information about already parsed~ stuff to differentiate regular numbers from special StyleSheet IDs, right?
@Andarist thanks for looping in!
It’s been a while since I last looked at the
@emotion/primitives-coreimplementation so not sure about the issue exactly. Let me have a look at it this week and I’ll post an update @imcvampireNo workaround - somebody from the community has to step up to implement a fix for this as our team do not have resources to handle issues related to the React Native.
Yes, that’s what I was thinking. I’ll give it a go 👍
It shouldn’t matter - because JS should automatically stringify this if you really are passing a number there.
Could you prepare repro case? Without such, we’ll have to close the issue as not actionable.