An Interest In:
Web News this Week
- April 2, 2024
- April 1, 2024
- March 31, 2024
- March 30, 2024
- March 29, 2024
- March 28, 2024
- March 27, 2024
January 9, 2022 12:37 pm GMT
Original Link: https://dev.to/toras123/react-native-theming-made-easy2022-479c
React Native- Theming made easy(2022)
GitHub Link:
https://github.com/KJA-CSX/theme-csx
theme-csx
A utility React Native theming framework for rapidly building themeable components.
Features
- Similar to standard react native styling, but with additional props that can be added to make it themeable.
- Behind the scenes, memoization has been optimized for maximum performance.
- Can be implemented for Views + Texts + Images + Icons...
- Light & Fast
Installation
npm install theme-csx
yarn add theme-csx
Usage
import { useState } from 'react';// Stylesimport { StyleSheet, appearanceHook, t} from "theme-csx";// Components import { Text, View } from 'react-native';import { Button } from '@components/atoms';const DemoComponent = () => {// Theme stateconst [theme, setTheme] = useState(appearanceHook.activeTheme)// Theme switchconst switchTheme = () => { appearanceHook.switch(appearanceHook.activeTheme === 'dark' ? 'light' : 'dark') setTheme(theme === 'dark' ? 'light' : 'dark')}return ( <View style={t(styles.THEMED_CONTAINER)}> <Text style={styles.NORMAL_TEXT}>Hey, I am normal text</Text> <Text style={t(styles.THEMED_TEXT)}>Hey, I am themed text</Text> <Button text={'Switch theme'} onPress={switchTheme} /> </View>)}const styles = StyleSheet.create({ THEMED_CONTAINER: { flex: 1, backgroundColor: 'white', backgroundDark: 'gray', alignItems: 'center', justifyContent: 'center', }, NORMAL_TEXT: { fontWeight: 'bold', fontSize: 14, color: 'green', }, THEMED_TEXT: { fontWeight: 'bold', fontSize: 14, color: 'black', colorDark: 'white' },})
Configuration
Imports Usage:
StyleSheet:
- StyleSheet can be used as the normal styling way, but now you can have extra props to make it themeable if you wish.
t() Function
- t() function should be used to apply themed styles only
appearanceHook
- appearanceHook is used to toggle and switch the theme: system, light, dark
Themed Style types:
TViewStyle:
- Has the following extra props: backgroundDark, borderDark
TTextStyle:
- Has the following extra props: colorDark, backgroundDark, borderDark
TImageStyle:
- Has the following extra props: tintColorDark, backgroundDark, borderDark
Original Link: https://dev.to/toras123/react-native-theming-made-easy2022-479c
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To