Code up a Figma Design in React Native
In this guide, weβll use React Native to recreate the design for a single todo item from Figma.
1. Consider the design
Section titled β1. Consider the designβThe first step in recreating a design is to consider the design itself.
With a partner, look carefully at the design below:
2. Create the components
Section titled β2. Create the componentsβWith this structure in mind, letβs take a look at how we might build the component in React Native code.
-
Open the project in your code editor and run the app with the command below:
Terminal window npm run dev -
Decide if you want to see the app on your phone or in the browser by following the instructions in your terminal.
-
Open
app/index.tsx
and replace all the code inside with the following:app/index.tsx import { View, Text } from "react-native";export default function HomeScreen() {return (<View className="flex flex-1 py-32 bg-background"><Text className="text-white text-center">Hello, world!</Text></View>);}This gives us a simple
View
component with aText
component inside it: -
Remind yourself how we said the component structure might look:
To recreate this, Iβm going to:
- delete the βHello, world!β placeholder text
- create a parent
View
component and give it an articfical height and border so that it matches the outlines above:
app/index.tsx import { View, Text } from "react-native";export default function HomeScreen() {return (<View className="flex flex-1 py-32 bg-background"><Text className="text-white text-center">Hello, world!</Text><View className="h-20 w-full border-2 border-cyan-400"></View></View>);} -
Next, Iβll add two
View
components inside the parent, and give these temporary borders that match the plan above:app/index.tsx import { Text, View } from "react-native";export default function HomeScreen() {return (<View className="flex flex-1 py-32 bg-background"><View className="flex flex-row h-20 w-full border-2 border-cyan-400"><View className="flex w-24 h-full border-2 border-pink-400"></View><View className="flex flex-1 h-full border-2 border-green-400"></View></View></View>);} -
Letβs add some text inside the green
View
component:app/index.tsx import { Text, View } from "react-native";export default function HomeScreen() {return (<View className="flex flex-1 py-32 bg-background"><View className="flex flex-row h-20 w-full border-2 border-cyan-400"><View className="flex w-24 h-full border-2 border-pink-400"><Text className="text-foreground">Feed the cat</Text></View></View></View>);}