React Native AppConfig Context Provider
This provider puts the application under one roof and prepares a suitable environment for both language and theme control.
Installation
$ npm install --save react-native-appconfig-providerOR$ yarn add react-native-appconfig-provider
This provider is using AsyncStorage to store theme or dictionary mode that is using in App. So,
$ npm install --save @react-native-community/async-storageOR$ yarn add @react-native-community/async-storage
Usage
Use AppConfigContextProvider
to wrap your app container:
;; <AppConfigContextProvider /* Default: { colors: { primary: '#333333', background: '#fff', } } */ lightMode=Object /* Default: { colors: { primary: '#fff', background: '#333333', } } */ darkMode=Object /* Default: (theme) => ( { textCenter: { color: theme.colors.primary, textAlign: 'center', textAlignVertical: 'center', }, } ) */ styles=Function /* Default: [ { "name": "Türkçe", "short": "TR", "words": { "helloWorld": "Merhaba Dünya !" } }, { "name": "English", "short": "EN", "words": { "helloWorld": "Hello World !" } } ] */ dictionary=Array > <YourApp /> </AppConfigContextProvider>;
And use AppConfigContext
for each component, if you want to use theme and dictionary constant, or change theme and dictionary:
;;; { const theme dictionary dictionaryMode mode onToggleMode updateDict = ; return <View style= backgroundColor: themecolorsbackground > <TouchableOpacity onPress= { ; } > <Text style= color: themecolorsprimary > ENGLISH </Text> </TouchableOpacity> <TouchableOpacity onPress= { ; } > <Text style= color: themecolorsprimary > TURKISH </Text> </TouchableOpacity> <TouchableOpacity onPress= { ; } > <Text style= color: themecolorsprimary > DARK / LIGHT MODE </Text> </TouchableOpacity> <Text style=themestylestextCenter> dictionaryhelloWorld </Text> </View> };