


How I set up Design System for my React Native Projects for Faster Development
Ever built apps that you wouldn't want to use yourself?
When I was a junior app developer, I used to build chaotic user interfaces.
Sometimes when looking at those UIs, I used to think "who in the world would even want to use this? It looks awful".
Other times, there was just "something off" that I just couldn't point out.
While I used to get amazing polished designs from design team, my apps would not look even 20% as good.
I was aware of this problem, and to fix it I went down on a rabbit hole of research in which I came across concept of having a design system which transformed the way I build apps.
What is this amazing thing called Design System?
It's crucial to understand what a design system is to be able to understand why do we need it.
Design system is basically a centralized source of truth for yours and your teams design decisions. It tells you what colours to use and where? How many types of buttons the app will have? Will the cards in your list have shadows? All answers comes from a design system.
Here are some of the benefits of having a design system:
Consistent UIs: Your interface will not have those weird gaps here and there for no reason. It will look and feel uniform across all devices.
Rapid decisions: Design systems enforces a certain set of constraints to make your decisions easier, not harder. The more options you have, the more analysis-paralysis you encounter.
Scalable Apps: As the app grows, a design system helps in reusing components rather than building from scratch.
Focus on development: You no longer have to stress whether the button should be green or blue. Instead, you'll focus on what matters.
Tools & Libraries
While there are tons of React Native UI libraries out there, I use custom approach as I've had horrible experiences with most of them regarding performance and bugs.
The only library I rely on for my approach is react-native-size-matters.
Now before you scream "size doesn't matter!", let me assure you it does. Especially, when it comes to mobile apps.
You don't want your users opening your app, seeing a giant logo covering everything, and think "What in the ugly..." before they delete without even trying because your logo hid the button.
That's where react-native-size-matters helps. It makes your apps responsive by scaling your components to fit the device. So, no matter which device users have, your logo stays exactly where you put it.
Set up theme
One of the first thing I define is my core design tokens. These are the building blocks of my design system. These include color palettes, typography, spacings, and font sizes.
I do this by creating a theme.ts file with the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
Creating Reusable Components
Once my design tokens are in place, I define some reusable components such as Box, Typography, and Input. These components adhere to the design tokens, ensuring consistency across the app.
For example here's how I create Box component:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
I use this newly created Box component as a replacement of View. It allows me to quickly style it through props (and give suggestions if you're using typescript) like so:
Here's an example of how I create Typography component which I use instead of React Native's Text component:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
Here's a preview of how quickly I am able to add styles to my custom Typography component:
Custom useTheme hook
Instead of importing theme again and again, I make my code more readable by creating a custom useTheme hook which I call anywhere in the app to add styles that adhere with my theme.
In order to do this, I leverage React's Context API to pass my theme in the app.
I create a ThemeProvider.tsx file and inside define the ThemeContext and ThemeProvider to wrap my app component inside it. Here's the code:
1 2 3 4 5 6 7 8 9 10 |
|
Then, inside my App component:
1 2 3 4 5 6 7 |
|
Now that my entire app has access to ThemeContext, I create my useTheme hook:
1 2 3 4 5 6 7 |
|
Now I can access my theme anywhere by calling the useTheme hook like so:
1 2 3 4 5 |
|
Dark Mode
To implement dark mode, in the theme.ts file, I add another color palette containing the colors for dark mode.
1 2 3 |
|
Then, in ThemeProvider, I simply check user settings and switch the theme like so:
1 2 3 4 5 6 7 8 |
|
Conclusion
Following this clear structured approach has brought much needed clarity, consistency, and aesthetics in my app while also sped up my development speed by at least 10x since I no longer have to dwell over design decisions.
I encourage you to try this approach and let me know what you guys think in the comments. Maybe improve it a little bit eh?
The above is the detailed content of How I set up Design System for my React Native Projects for Faster Development. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing
