Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for React Native- Theming made easy(2022)
Karam Jammal
Karam Jammal

Posted on • Edited on

     

React Native- Theming made easy(2022)

GitHub Link:

https://github.com/KJ-GM/theme-csx


A React Native theming framework that makes it easy to create themeable components.

Features

  • Similar to standard react native styling, but with additional props that can be added to make it themeable.
  • Can be implemented for Views + Texts + Images + Icons...
  • Light & Fast
  • Expo & ReactNative
  • Typescript & JavaScript

Installation

npminstalltheme-csx
Enter fullscreen modeExit fullscreen mode
yarn add theme-csx
Enter fullscreen modeExit fullscreen mode

Get Started -Three Steps:

StyleSheet

  • Is used in the usual styling format, but now you have additional props to make style themeable.

T() Function

  • Applyonly your themed styles using the T() function wrapper.

appearanceHook

  • Use the appearanceHook to switch theme from anywhere in your app.

Usage

// Stylesimport{StyleSheet,T,appearanceHook}from"theme-csx";// Componentsimport{Text,View}from'react-native';import{Button}from'@components/atoms';constDemoComponent=()=>{// Theme switchconstswitchTheme=()=>{appearanceHook.switch(appearanceHook.activeTheme==='dark'?'light':'dark')}return(<Viewstyle={T(styles.THEMED_CONTAINER)}><Textstyle={styles.NORMAL_TEXT}>Hey,Iamnormaltext</Text><Textstyle={T(styles.THEMED_TEXT)}>Hey,Iamthemedtext</Text><Buttontext={'Switch theme'}onPress={switchTheme}/></View>)}conststyles=StyleSheet.create({THEMED_CONTAINER:{flex:1,backgroundColor:'white',backgroundDark:'gray',// backgroundDark porp was added to make it themeablealignItems:'center',justifyContent:'center',},NORMAL_TEXT:{fontWeight:'bold',fontSize:14,color:'green',},THEMED_TEXT:{fontWeight:'bold',fontSize:14,color:'black',colorDark:'white'// colorDark porp was added to make it themeable},})
Enter fullscreen modeExit fullscreen mode

Theme 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

appearanceHook.switch():

  • Has the following options:system,light,dark

Contributing

See thecontributing guide to learn how to contribute to the repository and the development workflow.

License

Apache-2.0 License

Top comments(8)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
ginisamoha profile image
giniSamoha
  • Joined

Thank you, very useful library!

CollapseExpand
 
kjgm profile image
Karam Jammal
Mobile Developer 🚀

I am glad to hear.

CollapseExpand
 
mashivili profile image
Misha Ashivili
  • Joined

awesome project!

CollapseExpand
 
kjgm profile image
Karam Jammal
Mobile Developer 🚀

Thank you 🙏

CollapseExpand
 
samwinberg1999 profile image
Sam Winberg
React Native learner! Happy to work with everybody :)
  • Joined

Very cool man thanks for sharing!

CollapseExpand
 
kjgm profile image
Karam Jammal
Mobile Developer 🚀

You're welcome body.

CollapseExpand
 
argam234 profile image
argam234
  • Joined

Hello, I believe this library should have been created a long time ago, thank you! Also, if you can make a YouTube video about the library, that would be fantastic.

CollapseExpand
 
kjgm profile image
Karam Jammal
Mobile Developer 🚀

Sure, A demo will be made soon!

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Mobile Developer 🚀
  • Location
    Georgia
  • Education
    GHIS
  • Work
    KJA
  • Joined

More fromKaram Jammal

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp