Skip to content

Instantly share code, notes, and snippets.

@MahbbRah
Created December 12, 2018 02:07
Show Gist options
  • Save MahbbRah/8e40082176b822687ee2222b3e72ffd1 to your computer and use it in GitHub Desktop.
Save MahbbRah/8e40082176b822687ee2222b3e72ffd1 to your computer and use it in GitHub Desktop.
Centering react native elements/contents from all the way, With Flex/Flexbox
// This example has been collected from react-Native official Project. :)


//Markup example
<View style={styles.container}>
  <Text style={styles.welcome}>Welcome to React Native!</Text>
  <Text style={styles.instructions}>To get started, edit App.js</Text>
  <Text style={styles.instructions}>{instructions}</Text>
</View>

//Here is the styles
const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

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