@loudpacks/theme-native
v0.2.0
Published
React Native theme picker modal with live theme previews
Maintainers
Readme
@loudpacks/theme-native
React Native theme picker modal with live theme previews.
Installation
npm install @loudpacks/theme-native @loudpacks/theme-core
# or
pnpm add @loudpacks/theme-native @loudpacks/theme-core
# or
yarn add @loudpacks/theme-native @loudpacks/theme-coreRequirements
- React ≥18.0.0
- React Native ≥0.72.0
Features
- 🎨 Live theme previews with light/dark mode toggle
- 📱 Native Modal with slide animation
- 🎯 Auto-derives modal colors from current theme
- 🔄 Pressable theme cards with visual feedback
- 📐 Safe area handling for iOS notches
- ♿ Full accessibility support with native components
- ✅ Fully tested with 25+ test cases
Usage
import { ThemePickerModal } from '@loudpacks/theme-native';
import type { ThemeDefinitions } from '@loudpacks/theme-core';
const themes: ThemeDefinitions = {
monochrome: {
displayName: 'Monochrome',
description: 'Clean monochrome design',
light: {
background: '#fafafa',
surface: '#ffffff',
text: '#1a1a1a',
// ... other color definitions
},
dark: {
background: '#121212',
surface: '#1e1e1e',
text: '#f5f5f5',
// ... other color definitions
},
},
// ... more themes
};
function App() {
const [showPicker, setShowPicker] = useState(false);
const [currentTheme, setCurrentTheme] = useState('monochrome');
const [colorScheme, setColorScheme] = useState<'light' | 'dark'>('light');
const currentColors = themes[currentTheme][colorScheme];
return (
<>
<Button
title="Change Theme"
onPress={() => setShowPicker(true)}
/>
<ThemePickerModal
visible={showPicker}
onClose={() => setShowPicker(false)}
currentTheme={currentTheme}
onSelectTheme={setCurrentTheme}
themes={themes}
initialPreviewMode={colorScheme}
currentColors={{
background: currentColors.background,
text: currentColors.text,
border: currentColors.border,
tint: currentColors.tint,
}}
config={{
showPreviewToggle: true,
closeOnSelect: true,
}}
/>
</>
);
}Components
ThemePickerModal
The main modal component for selecting themes.
Props:
visible(boolean): Controls modal visibilityonClose(() => void): Callback when modal is closedcurrentTheme(string): Currently selected theme keyonSelectTheme((themeKey: string) => void): Callback when theme is selectedthemes(ThemeDefinitions): Object containing all available themesinitialPreviewMode('light' | 'dark', optional): Initial preview modeheaderTitle(string, optional): Modal header textcurrentColors(object): Current theme colors for styling the modalconfig(object, optional): Configuration options
ThemeCard
Individual theme preview card component.
Props:
themeKey(string): Theme identifiertheme(ThemeMetadata): Theme dataisSelected(boolean): Whether this theme is currently selectedpreviewMode('light' | 'dark'): Which color scheme to previewonSelect(() => void): Callback when card is pressed
Configuration Options
{
showPreviewToggle: boolean; // Show light/dark toggle (default: true)
closeOnSelect: boolean; // Close modal after selection (default: false)
gridColumns: number; // Number of columns (default: 2)
}Examples
See the examples directory for complete working examples including:
- Basic theme picker setup
- Persistent theme storage with AsyncStorage
- System color scheme detection
License
MIT
