Skip to content

Instantly share code, notes, and snippets.

@kashishgrover
Created November 30, 2018 19:12
Show Gist options
  • Save kashishgrover/b932095c774395680f2d30abd3f12f27 to your computer and use it in GitHub Desktop.
Save kashishgrover/b932095c774395680f2d30abd3f12f27 to your computer and use it in GitHub Desktop.
React Native Component Scaling Example
const styles = StyleSheet.create({
container: {
borderRadius: scale(4),
borderWidth: scale(0.5),
borderColor: '#d6d7da',
paddingHorizontal: scale(16),
},
title: {
fontSize: scale(19),
fontWeight: 'bold',
},
activeTitle: {
color: 'red',
},
});
// Do you use styled components?
const Button = styled.TouchableOpacity`
backgroundColor: #d6d7da;
paddingHorizontal: scale(14);
paddingVertical: scale(8);
`;
@shubhang93
Copy link

Hey, I am using this and it works great, but suppose I want to set predefined widths and heights to a Button, if I pass 200 as the input to the scale function, for example:- scalePx(200) BTW I am using styled Components, it appears too big on bigger devices and too small on smaller devices. Any suggestions please.

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