33
loading...
This website collects cookies to deliver better user experience
styled-components
to style View
, Text
, TouchableOpacity
and other native components was very cumbersome. css
, and remember to put ;
at the end of each line, etc.. styled-components
will generate the React Native styles from your template string and will pass them to the component. Yeah, cool...styled-rn
package was born :)styled-components/native
?styled-rn
gives you access to ALL React Native style propsstyled-rn
is faster because it does not do tedious string template processingstyled-rn
is easier to use (again, no messy string templates)styled-rn
is fully typed and has a nice APIstyled-rn
supports component attributes, custom props, theme via ThemeProvider
, multiple style objects and more..styled-rn
has a shorter name ;)npm i styled-rn
styled-rn
API is almost one-to-one with the styled-components
API, but everything happens in Javascript with full Typescript support:import { styled } from "styled-rn";
export const Container = styled.View({
flexDirection: "row",
backgroundColor: "cyan",
});
// Use with any component
export const CoolAndBoldComponent = styled(CoolComponent, {
fontWeight: "bold",
});
attrs
key:// Pass props to the styled component (attrs)
export const NonWrappingText = styled.Text({
color: "blue",
}, {
attrs: {
numberOfLines: 1,
ellipsizeMode: 'tail',
}
});
styled-rn
is a very small library, but it provides robust functionality and smart typings for all the styles, props and attributes.styled-rn
! :)