Making Your App Look Great with Various React Native Styling Techniques

Khusni Ja'far
Tulisan Khusni
Published in
2 min readJul 19, 2023

In app development, appearance and UX (User Experience) play a crucial role in determining whether your app will be well-received by users or not. For this purpose, React Native provides various ways to apply styling to your app. Let's learn about some styling techniques in React Native.

Inline Styling

The easiest way to add style to React Native components is with inline styling. This method is similar to how we add style directly to HTML elements. Here's an example of inline styling usage:

import React from 'react';
import { Text, View } from 'react-native';

const InlineStyleExample = () => (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text style={{ color: 'blue', fontSize: 20 }}>Hello, React Native!</Text>
</View>
);

export default InlineStyleExample;

StyleSheet

Although inline styling is relatively easy to use, it is not efficient for larger applications. To handle this, React Native provides StyleSheet, an abstraction similar to CSS Stylesheets. Here's an example of StyleSheet usage:

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
text: {
color: 'blue',
fontSize: 20,
},
});

const StyleSheetExample = () => (
<View style={styles.container}>
<Text style={styles.text}>Hello, React Native!</Text>
</View>
);

export default StyleSheetExample;

Styled Components

If you are already familiar with Styled Components in React, you'll be happy to know that you can also use them in React Native. With styled-components, you can create components that have built-in styles. This helps to make your code cleaner and easier to read.

import React from 'react';
import styled from 'styled-components/native';

const Container = styled.View`
flex: 1;
justify-content: center;
align-items: center;
`;

const BlueText = styled.Text`
color: blue;
font-size: 20px;
`;

const StyledComponentsExample = () => (
<Container>
<BlueText>Hello, React Native!</BlueText>
</Container>
);

export default StyledComponentsExample;

Remember, the look of your app has a massive impact on the user experience. Using these techniques, you can make your React Native app not only function well but also look great and professional. Happy coding!

--

--