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:
import {moderateScale} from 'react-native-size-matters'; // after installing custom fonts: export const FontFamily = { bold: 'Poppins-Bold', semibold: 'Poppins-SemiBold', medium: 'Poppins-Medium', regular: 'Poppins-Regular', thin: 'Poppins-Thin', }; const colors = { primary100: '#2E2C5F', primary80: '#524DA0', primary60: '#736DDF', primary40: '#A09BFF', primary20: '#DCDAFF', secondary100: '#484A22', secondary80: '#858945', secondary60: '#D9DF6D', secondary40: '#F8FCA1', secondary20: '#FDFFD4', neutral100: '#131218', neutral90: '#1D1C25', neutral80: '#272631', neutral70: '#343341', neutral60: '#3E3D4D', neutral50: '#53526A', neutral40: '#757494', neutral30: '#9C9AC1', neutral20: '#CBC9EF', neutral10: '#E8E7FF', white: '#fff', black: '#222', error: '#E7002A', success: '#3EC55F', warning: '#FECB2F', info: '#157EFB', }; const theme = { colors, fontSizes: { xxl: moderateScale(32), xl: moderateScale(28), lg: moderateScale(24), md: moderateScale(20), body: moderateScale(17), sm: moderateScale(14), xs: moderateScale(12), xxs: moderateScale(10), xxxs: moderateScale(8), }, spacing: { none: 0, xxs: moderateScale(4), xs: moderateScale(8), md: moderateScale(12), lg: moderateScale(16), xl: moderateScale(20), xxl: moderateScale(24), xxxl: moderateScale(28), }, }; export default theme;
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:
import { View, type ViewProps, type FlexAlignType, type ViewStyle, } from 'react-native'; import theme from '../styles/theme/theme'; export interface IBox extends ViewProps { backgroundColor?: keyof typeof theme.colors; p?: keyof typeof theme.spacing; pv?: keyof typeof theme.spacing; ph?: keyof typeof theme.spacing; pt?: keyof typeof theme.spacing; pb?: keyof typeof theme.spacing; pl?: keyof typeof theme.spacing; pr?: keyof typeof theme.spacing; m?: keyof typeof theme.spacing; mv?: keyof typeof theme.spacing; mh?: keyof typeof theme.spacing; mt?: keyof typeof theme.spacing; mb?: keyof typeof theme.spacing; ml?: keyof typeof theme.spacing; mr?: keyof typeof theme.spacing; gap?: number; flex?: number; flexDirection?: 'row' | 'column' | 'row-reverse' | 'column-reverse'; alignItems?: FlexAlignType; justifyContent?: | 'center' | 'flex-start' | 'flex-end' | 'space-between' | 'space-around' | 'space-evenly'; rounded?: boolean; } export default function Box({ backgroundColor, p, pv, ph, pt, pb, pr, pl, m, mv, mh, mt, mb, ml, mr, children, style, flex, alignItems, justifyContent, flexDirection = 'column', rounded = false, gap = undefined, ...rest }: IBox) { const getMargin = () => { const obj: any = {}; if (m) { obj.margin = theme.spacing[m]; return obj; } if (mt) obj.marginTop = mt ? theme.spacing[mt] : 0; if (mb) obj.marginBottom = mb ? theme.spacing[mb] : 0; if (ml) obj.marginLeft = ml ? theme.spacing[ml] : 0; if (mr) obj.marginRight = mr ? theme.spacing[mr] : 0; if (mv) obj.marginVertical = theme.spacing[mv]; if (mh) obj.marginHorizontal = theme.spacing[mh]; return obj; }; const getPadding = () => { const obj: any = {}; if (p) { obj.padding = theme.spacing[p]; return obj; } if (pt) obj.paddingTop = pt ? theme.spacing[pt] : 0; if (pb) obj.paddingBottom = pb ? theme.spacing[pb] : 0; if (pl) obj.paddingLeft = pl ? theme.spacing[pl] : 0; if (pr) obj.paddingRight = pr ? theme.spacing[pr] : 0; if (pv) obj.paddingVertical = theme.spacing[pv]; if (ph) obj.paddingHorizontal = theme.spacing[ph]; return obj; }; const boxStyles: ViewStyle[] = [ { backgroundColor: backgroundColor ? theme.colors[backgroundColor] : undefined, flex, justifyContent, alignItems, flexDirection, borderRadius: rounded ? 10 : 0, gap, }, getMargin(), getPadding(), style, ]; return ( <view style="{boxStyles}"> {children} </view> ); }
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:
import React from 'react'; import {Text, type TextProps} from 'react-native'; import theme, {FontFamily} from '../styles/theme/theme'; export interface ITypography extends TextProps { size?: keyof typeof theme.fontSizes; color?: keyof typeof theme.colors; textAlign?: 'center' | 'auto' | 'left' | 'right' | 'justify'; variant?: keyof typeof FontFamily; } export default function Typography({ size, color, textAlign, children, style, variant, ...rest }: ITypography) { return ( <text style="{[" color: color theme.colors : theme.colors.white textalign fontsize: size theme.fontsizes theme.fontsizes.body fontfamily: variant fontfamily fontfamily.regular> {children} </text> ); }
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:
import React, {type PropsWithChildren, createContext} from 'react'; import theme from './theme'; export const ThemeContext = createContext(theme); export default function ThemeProvider({children}: PropsWithChildren) { return ( <themecontext.provider value="{theme}">{children}</themecontext.provider> ); }
Then, inside my App component:
export default function App() { return ( <themeprovider> <appnavigation></appnavigation> </themeprovider> ); }
Now that my entire app has access to ThemeContext, I create my useTheme hook:
import {useContext} from 'react'; import {ThemeContext} from '../styles/theme/ThemeProvider'; export default function useTheme() { const theme = useContext(ThemeContext); return theme; }
Now I can access my theme anywhere by calling the useTheme hook like so:
const theme = useTheme(); // example usage: theme.colors.primary100; theme.spacing.md; theme.fontSizes.lg;
Dark Mode
To implement dark mode, in the theme.ts file, I add another color palette containing the colors for dark mode.
export const darkTheme = { // define dark mode colors here keeping the keys same as the light mode only changing the values. }
Then, in ThemeProvider, I simply check user settings and switch the theme like so:
<p>import {useColorScheme} from 'react-native';</p> <p>export default function ThemeProvider({children}: PropsWithChildren) {<br> const isDarkMode = useColorScheme() === 'dark';<br> return (<br> <themecontext.provider value="{isDarkMode" darktheme : theme>{children}</themecontext.provider><br> );<br> }</p>
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?
以上が開発を迅速化するために React Native プロジェクトのデザイン システムをセットアップする方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

Pythonは、スムーズな学習曲線と簡潔な構文を備えた初心者により適しています。 JavaScriptは、急な学習曲線と柔軟な構文を備えたフロントエンド開発に適しています。 1。Python構文は直感的で、データサイエンスやバックエンド開発に適しています。 2。JavaScriptは柔軟で、フロントエンドおよびサーバー側のプログラミングで広く使用されています。

PythonとJavaScriptには、コミュニティ、ライブラリ、リソースの観点から、独自の利点と短所があります。 1)Pythonコミュニティはフレンドリーで初心者に適していますが、フロントエンドの開発リソースはJavaScriptほど豊富ではありません。 2)Pythonはデータサイエンスおよび機械学習ライブラリで強力ですが、JavaScriptはフロントエンド開発ライブラリとフレームワークで優れています。 3)どちらも豊富な学習リソースを持っていますが、Pythonは公式文書から始めるのに適していますが、JavaScriptはMDNWebDocsにより優れています。選択は、プロジェクトのニーズと個人的な関心に基づいている必要があります。

C/CからJavaScriptへのシフトには、動的なタイピング、ゴミ収集、非同期プログラミングへの適応が必要です。 1)C/Cは、手動メモリ管理を必要とする静的に型付けられた言語であり、JavaScriptは動的に型付けされ、ごみ収集が自動的に処理されます。 2)C/Cはマシンコードにコンパイルする必要がありますが、JavaScriptは解釈言語です。 3)JavaScriptは、閉鎖、プロトタイプチェーン、約束などの概念を導入します。これにより、柔軟性と非同期プログラミング機能が向上します。

さまざまなJavaScriptエンジンは、各エンジンの実装原則と最適化戦略が異なるため、JavaScriptコードを解析および実行するときに異なる効果をもたらします。 1。語彙分析:ソースコードを語彙ユニットに変換します。 2。文法分析:抽象的な構文ツリーを生成します。 3。最適化とコンパイル:JITコンパイラを介してマシンコードを生成します。 4。実行:マシンコードを実行します。 V8エンジンはインスタントコンピレーションと非表示クラスを通じて最適化され、Spidermonkeyはタイプ推論システムを使用して、同じコードで異なるパフォーマンスパフォーマンスをもたらします。

現実世界におけるJavaScriptのアプリケーションには、サーバー側のプログラミング、モバイルアプリケーション開発、モノのインターネット制御が含まれます。 2。モバイルアプリケーションの開発は、ReactNativeを通じて実行され、クロスプラットフォームの展開をサポートします。 3.ハードウェアの相互作用に適したJohnny-Fiveライブラリを介したIoTデバイス制御に使用されます。

私はあなたの日常的な技術ツールを使用して機能的なマルチテナントSaaSアプリケーション(EDTECHアプリ)を作成しましたが、あなたは同じことをすることができます。 まず、マルチテナントSaaSアプリケーションとは何ですか? マルチテナントSaaSアプリケーションを使用すると、Singの複数の顧客にサービスを提供できます

この記事では、許可によって保護されたバックエンドとのフロントエンド統合を示し、next.jsを使用して機能的なedtech SaaSアプリケーションを構築します。 FrontEndはユーザーのアクセス許可を取得してUIの可視性を制御し、APIリクエストがロールベースに付着することを保証します

JavaScriptは、現代のWeb開発のコア言語であり、その多様性と柔軟性に広く使用されています。 1)フロントエンド開発:DOM操作と最新のフレームワーク(React、Vue.JS、Angularなど)を通じて、動的なWebページとシングルページアプリケーションを構築します。 2)サーバー側の開発:node.jsは、非ブロッキングI/Oモデルを使用して、高い並行性とリアルタイムアプリケーションを処理します。 3)モバイルおよびデスクトップアプリケーション開発:クロスプラットフォーム開発は、反応および電子を通じて実現され、開発効率を向上させます。


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境

PhpStorm Mac バージョン
最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール

SecLists
SecLists は、セキュリティ テスターの究極の相棒です。これは、セキュリティ評価中に頻繁に使用されるさまざまな種類のリストを 1 か所にまとめたものです。 SecLists は、セキュリティ テスターが必要とする可能性のあるすべてのリストを便利に提供することで、セキュリティ テストをより効率的かつ生産的にするのに役立ちます。リストの種類には、ユーザー名、パスワード、URL、ファジング ペイロード、機密データ パターン、Web シェルなどが含まれます。テスターはこのリポジトリを新しいテスト マシンにプルするだけで、必要なあらゆる種類のリストにアクセスできるようになります。

DVWA
Damn Vulnerable Web App (DVWA) は、非常に脆弱な PHP/MySQL Web アプリケーションです。その主な目的は、セキュリティ専門家が法的環境でスキルとツールをテストするのに役立ち、Web 開発者が Web アプリケーションを保護するプロセスをより深く理解できるようにし、教師/生徒が教室環境で Web アプリケーションを教え/学習できるようにすることです。安全。 DVWA の目標は、シンプルでわかりやすいインターフェイスを通じて、さまざまな難易度で最も一般的な Web 脆弱性のいくつかを実践することです。このソフトウェアは、

VSCode Windows 64 ビットのダウンロード
Microsoft によって発売された無料で強力な IDE エディター
