Overview
The RIS Gran Chimú app uses themed components that automatically adapt to light and dark mode. The two primary components are ThemedText and ThemedView, which provide consistent styling across the application.
ThemedText
A text component that automatically adapts to the current color scheme.
Implementation
src/components/ThemedText.tsx
import { StyleSheet , Text , type TextProps } from 'react-native' ;
import { useThemeColor } from '@/src/hooks/useThemeColor' ;
export type ThemedTextProps = TextProps & {
lightColor ?: string ;
darkColor ?: string ;
type ?: 'default' | 'title' | 'defaultSemiBold' | 'subtitle' | 'link' ;
};
export function ThemedText ({
style ,
lightColor ,
darkColor ,
type = 'default' ,
... rest
} : ThemedTextProps ) {
const color = useThemeColor ({ light: lightColor , dark: darkColor }, 'text' );
return (
< Text
style = { [
{ color },
type === 'default' ? styles . default : undefined ,
type === 'title' ? styles . title : undefined ,
type === 'defaultSemiBold' ? styles . defaultSemiBold : undefined ,
type === 'subtitle' ? styles . subtitle : undefined ,
type === 'link' ? styles . link : undefined ,
style ,
] }
{ ... rest }
/>
);
}
const styles = StyleSheet . create ({
default: {
fontSize: 16 ,
lineHeight: 24 ,
},
defaultSemiBold: {
fontSize: 16 ,
lineHeight: 24 ,
fontWeight: '600' ,
},
title: {
fontSize: 32 ,
fontWeight: 'bold' ,
lineHeight: 32 ,
},
subtitle: {
fontSize: 20 ,
fontWeight: 'bold' ,
},
link: {
lineHeight: 30 ,
fontSize: 16 ,
color: '#0a7ea4' ,
},
});
Props
Override color for light mode
Override color for dark mode
type
'default' | 'title' | 'defaultSemiBold' | 'subtitle' | 'link'
default: "default"
Text variant with predefined styles
Text Types
Type Font Size Font Weight Line Height Use Case default16px normal 24px Body text defaultSemiBold16px 600 24px Emphasized body text title32px bold 32px Page titles subtitle20px bold - Section headings link16px normal 30px Clickable links (#0a7ea4)
Usage Examples
Basic Usage
Title
Subtitle
Custom Colors
Link Style
import { ThemedText } from '@/src/components/ThemedText' ;
export default function Screen () {
return (
< ThemedText > This is regular text </ ThemedText >
);
}
ThemedView
A view container that automatically adapts its background color to the current color scheme.
Implementation
src/components/ThemedView.tsx
import { View , type ViewProps } from 'react-native' ;
import { useThemeColor } from '@/src/hooks/useThemeColor' ;
export type ThemedViewProps = ViewProps & {
lightColor ?: string ;
darkColor ?: string ;
};
export function ThemedView ({
style ,
lightColor ,
darkColor ,
... otherProps
} : ThemedViewProps ) {
const backgroundColor = useThemeColor (
{ light: lightColor , dark: darkColor },
'background'
);
return < View style = { [{ backgroundColor }, style ] } { ... otherProps } /> ;
}
Props
Override background color for light mode
Override background color for dark mode
Usage Examples
Basic Container
Custom Background Colors
Nested Themed Components
import { ThemedView } from '@/src/components/ThemedView' ;
import { ThemedText } from '@/src/components/ThemedText' ;
export default function Screen () {
return (
< ThemedView style = { { flex: 1 , padding: 20 } } >
< ThemedText type = "title" > Welcome </ ThemedText >
< ThemedText > This view adapts to light/dark mode </ ThemedText >
</ ThemedView >
);
}
Color Theme System
Both components use the useThemeColor hook which references the Colors constant:
export const Colors = {
light: {
text: '#11181C' ,
background: '#fff' ,
tint: '#0a7ea4' ,
icon: '#687076' ,
tabIconDefault: '#687076' ,
tabIconSelected: '#0a7ea4' ,
},
dark: {
text: '#ECEDEE' ,
background: '#151718' ,
tint: '#fff' ,
icon: '#9BA1A6' ,
tabIconDefault: '#9BA1A6' ,
tabIconSelected: '#fff' ,
},
};
The theme automatically switches based on the device’s system preference. Users can also override this in the app settings.
Best Practices
Use Themed Components Consistently Always use ThemedText and ThemedView instead of raw Text and View components to ensure proper theme support.
Leverage Type Variants Use the predefined type prop on ThemedText for consistent typography instead of custom styles.
Override Colors Sparingly Only use lightColor and darkColor props when you need specific branding colors that differ from the theme.
Test Both Themes Always test your UI in both light and dark modes to ensure readability and proper contrast.