Examples
Settings
The settings screen every app ends up with: the account at the top, grouped rows with icons, switches (the ones under Push notifications turn off with it), language and appearance as rows that open a picker, and Sign out in red at the bottom.
Loading…
import { useState } from 'react'; import { ScrollView, StyleSheet, View } from 'react-native'; import { Avatar, Header, List, ListItem, Select, Switch, useTheme } from 'patine-ui'; import { Icon } from '@patine-ui/icons'; import type { IconName } from '@patine-ui/icons'; const LANGUAGES = [ { label: 'English', value: 'en' }, { label: 'Español', value: 'es' }, { label: 'Français', value: 'fr' }, { label: 'Português', value: 'pt' }, { label: 'עברית', value: 'he' }, ]; const APPEARANCES = [ { label: 'System', value: 'system' }, { label: 'Light', value: 'light' }, { label: 'Dark', value: 'dark' }, ]; /** A row's icon on a tinted square, like the system settings. */ const RowIcon = ({ name, color }: { name: IconName; color: string }) => ( <View style={[styles.rowIcon, { backgroundColor: color }]}> <Icon name={name} size="sm" color="#fff" /> </View> ); export default function Settings() { const { colors } = useTheme(); const [push, setPush] = useState(true); const [mentions, setMentions] = useState(true); const [digest, setDigest] = useState(false); const [faceId, setFaceId] = useState(true); const [language, setLanguage] = useState('en'); const [appearance, setAppearance] = useState('system'); return ( <View style={[styles.screen, { backgroundColor: colors.background }]}> <Header title="Settings" /> <ScrollView contentContainerStyle={styles.content}> <List> <ListItem title="Ana Ribeiro" description="[email protected] · Family plan" leading={<Avatar name="Ana Ribeiro" src="https://picsum.photos/id/64/160/160" size="lg" />} onPress={() => {}} /> </List> <List title="Notifications" footer="Quiet hours still apply to everything above."> <ListItem title="Push notifications" leading={<RowIcon name="bell" color="#E5484D" />} trailing={<Switch accessibilityLabel="Push notifications" checked={push} onCheckedChange={setPush} />} /> <ListItem title="Replies and mentions" leading={<RowIcon name="at" color="#3E63DD" />} disabled={!push} trailing={ <Switch accessibilityLabel="Replies and mentions" checked={push && mentions} onCheckedChange={setMentions} disabled={!push} /> } /> <ListItem title="Weekly digest" description="Mondays at 9:00" leading={<RowIcon name="mail" color="#8E4EC6" />} trailing={<Switch accessibilityLabel="Weekly digest" checked={digest} onCheckedChange={setDigest} />} /> </List> <List title="Preferences"> <Select sheetTitle="Language" options={LANGUAGES} value={language} onValueChange={setLanguage} renderTrigger={({ open, selected }) => ( <ListItem title="Language" value={selected[0]?.label} leading={<RowIcon name="globe" color="#0090FF" />} onPress={open} /> )} /> <Select sheetTitle="Appearance" options={APPEARANCES} value={appearance} onValueChange={setAppearance} renderTrigger={({ open, selected }) => ( <ListItem title="Appearance" value={selected[0]?.label} leading={<RowIcon name="moon" color="#5B5BD6" />} onPress={open} /> )} /> </List> <List title="Privacy & security"> <ListItem title="Unlock with Face ID" leading={<RowIcon name="fingerprint" color="#30A46C" />} trailing={<Switch accessibilityLabel="Unlock with Face ID" checked={faceId} onCheckedChange={setFaceId} />} /> <ListItem title="Connected devices" value="3" leading={<RowIcon name="smartphone" color="#F76B15" />} onPress={() => {}} /> <ListItem title="Download my data" leading={<RowIcon name="download" color="#687076" />} onPress={() => {}} /> </List> <List> <ListItem title="Sign out" destructive showChevron={false} onPress={() => {}} /> </List> </ScrollView> </View> ); } const styles = StyleSheet.create({ screen: { flex: 1 }, content: { gap: 24, paddingVertical: 16 }, rowIcon: { width: 28, height: 28, borderRadius: 7, alignItems: 'center', justifyContent: 'center' }, });
Components used
- Header: the screen's title bar
- List, ListItem: grouped rows with
leading,trailing,value,description,disabledanddestructive - Switch: each toggle, with an
accessibilityLabelsince the row holds the visible label - Select:
renderTriggerturns the field into a list row that opens the options - Avatar: the account's photo, with initials while it loads
- Patine Icons
How it works
- A select as a row.
renderTriggergetsopenand theselectedoptions, so the row shows the current language and opens the same sheet (or dropdown on the web) a field would. - Dependent switches. The rows under Push notifications read
push: off greys them out and shows them off, without forgetting what they were set to.