1.0.5 • Published 5 years ago
react-native-use-unit v1.0.5
The package contains only one function that is a hook. The creates unit convter.
That converts css units as string (the supported units are, px, rem, vh, vw, vmin and vmax) value to pixels representing numbers.
The rem value can be set with a RemProvider Component, the default value is 16px.
import { useInitUnitConverter, RemProvider } from "react-native-use-unit";
const App: React.FC = () => {
const unit = useInitUnitConverter();
return (
<>
<View
style={{
backgroundColor: "red",
width: unit("50vw"),
height: unit("50vh"),
marginLeft: unit("25vw"),
marginTop: unit("25vh"),
paddingBottom: unit("8rem")
}}/>
<RemProvider
value={8}>
<View
style={{
padding: unit("16rem")
}}/>
</RemProvider>
</>
);
};