-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Allow usage of "className" #7238
Comments
Hi! |
@kohver No, I don't want real css, I just want classnames I can assign to React's CSS-subset and then use. @satya164 I know that presentation. I used this ( |
@fab1an There is no reason you shouldn't be able to have a |
No, but the classnames don't seem to be applied to react-native? |
@fab1an What do you mean by they are not applied? You've to handle the prop in your component if you want to. React Native doesn't support CSS. |
I'm not talking about supporting CSS. I'm taking about being able to create a var styles = StyleSheet.create({
w100: {
width: 100
},
h100: {
height: 100
},
bg-black: {
backgroundColor: '#000000',
},
bg-white: {
backgroundColor: '#FFFFFF',
},
}); and then use it like so: <View className="h100 w100 bg-black">
<Text className="w100 bg-white"/>
</View> This way I have my styles at the place where the are being applied, which makes development faster AND I don't need to find a name for every css component, which is good since they rarely have a proper semantic meaning. I can implement this myself with a |
@fab1an No. React Native doesn't support this pattern. To support this at runtime, you'll have to implement a Why not just use this? It doesn't look that different to me. Also this is more flexible. <View style={[ s.h100, s.w100, dark ? s.bgBlack : null ]}>
<Text style={[ s.w100, s.bgWhite ]} />
</View> BTW, you can't use |
For conditional styles I tend to use the I didn't know you could pass an array to style. Maybe I'll write the babel-transform, but this should work for me in the meantime, thank you. |
You can write that as a 3rd party plugin and it will just work. What to do:
|
What do you mean by "HOC"? That sounds good, but i think it's too much clutter to wrap every JSX tag in an extra parent. |
@fab1an Higher order components - https://medium.com/@franleplant/react-higher-order-components-in-depth-cf9032ee6c3e |
More or less this -> https://gist.github.com/grabbou/cec8608d7dbb54ec8cb4080134a997e5 Note - it probably does not work, but shows the concepts :) |
Great! Thanks. |
I build this into a library: https://github.com/fab1an/react-native-tachyons |
Hi, I use tachyons [0] to style react for web, so I'd like to use the
className
property in react-native as well.It allows me to use "mini"-css classes and write code like this, instead of using the
styles
property, which I find way better (after having tried both approaches).[0] http://tachyons.io/docs/
The text was updated successfully, but these errors were encountered: