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

React native support? #26

Open
iRoachie opened this issue Sep 6, 2017 · 10 comments
Open

React native support? #26

iRoachie opened this issue Sep 6, 2017 · 10 comments

Comments

@iRoachie
Copy link

iRoachie commented Sep 6, 2017

Does this plugin support react native?

export const Shadow = styled.View`
  shadowColor: #000;
  shadowOpacity: .2;
  shadowOffset: 0px -1px;
  shadowRadius: 1;
  marginBottom: -1px;
`

All show as errors currently

@daedlock
Copy link
Member

daedlock commented Sep 7, 2017

Can't reproduce.

webprobe-frontend 2017-09-07 13-15-31

@daedlock
Copy link
Member

daedlock commented Sep 7, 2017

@iRoachie please include your plugin/IDE versions

@undeadcat
Copy link
Contributor

@iRoachie, Hi!
Could you clarify what you're seeing?
I'm guessing that ios-specific properties are highlighted as unknown.
image

But could you confirm?

There is nothing in this plugin currently that is aware of react-native props, it just assumes it is plain CSS. As a workaround, you can mark them as custom properties (Alt+Enter, 'Add to custom properties')

@undeadcat
Copy link
Contributor

If someone wants to contribute proper support for react-native style properties, seems like the way to go would be to implement com.intellij.psi.css.CssElementDescriptorProvider (some samples here and here) and override getAllPropertyDescriptors and findPropertyDescriptors to provide React Native-specific properties.

It could be used to:

  1. Add React-only props like shadowOffset
  2. Transform existing css props to their React Native counterparts (e.g. margin-left -> marginLeft). One would need to take care of the fact that many props, e.g top allow different values than their CSS counterparts. ("Ems and other units are not supported").
    com.intellij.psi.css.descriptor.value.CssValueDescriptor are used to configure what strings should be accepted as values (highlighted/available in completion).
  3. Filter out any CSS properties that are not accepted by css-to-react-native.

Seems like the main issue would be to figure out what properties and values should be accepted and where to get that information without hardcoding a list (.d.ts files?).

If anyone wants to try this — I'll be happy to answer questions re: Intellij IDEA APIs.

@iRoachie
Copy link
Author

iRoachie commented Sep 7, 2017

@daedlock The snippet you posted isn't actually valid react native code. background isn't a style property on the View model like you'd expect on the web.

Thanks @undeadcat, I don't have any experience with Java or Kotlin but I guess I could answer any questions you have with react native, that would help.

A roadmap for this so far would look like:

  • React native property styles e.g (flexWrap instead of flex-wrap)
    • Error is Unknown css property
  • Support non-unit values e.g (height: 120)
    • Error is Mismatched property value
  • Don't enforce semi-colons
const Content = styled.View`
  flexDirection: row
  marginRight: 24 
`
"; expected"

@daedlock
Copy link
Member

daedlock commented Sep 7, 2017

@iRoachie I blindly forgot about that as I thought the issue was with the styled.View and not the styling properties itself. 👍

@yordis
Copy link

yordis commented Dec 8, 2017

I am getting some complains about margin: -5 because it doesn't have the unit ...

@nenti
Copy link

nenti commented Jul 12, 2018

@yordis just add px and you are fine. I migrated successfully all my styled to meet requirements. Only one that I can't get around with this plugin is:

const Container = styled.View`
    elevation: 10;
`
Error:(95, 14) Mismatched property value (<angle> | below | level | above | higher | lower | [initial | inherit | unset | revert])

@hamidfzm
Copy link

hamidfzm commented May 9, 2020

It's sad this issue is open from 2017. Hope maintainers pay more attention to styled-components React Native development

@baba43
Copy link

baba43 commented Nov 9, 2020

Would be awesome to see this fixed.

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

No branches or pull requests

7 participants