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.tsxand 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
Viewcomponent with aTextcomponent 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
Viewcomponent 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
Viewcomponents 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
Viewcomponent: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>);}