Reputation: 61
I have a custom theme in my app. it is working fine. when I changing the theme it's applied on the whole app but when restarting the app, it goes for Initially theme or default theme. my question is when changing the custom theme can it be set for as the Initial theme? after restarting the app, the app should go for the last applied custom theme, not the Initial theme.
action function
export const switchTheme = (BaseTheme) => {
return (dispatch) => {
dispatch({
type : 'SWITCH_THEME',
baseTheme : BaseTheme
});
};
};
export const switchLang = (BaseLang) => {
return (dispatch) => {
dispatch({
type : 'SWITCH_LANGUAGE',
baseLang : BaseLang
});
};
};
Reducer function
export const initialState = {
theme : { ...Faded_Jade },
language : en
};
export default function(state = initialState, action) {
switch (action.type) {
case 'SWITCH_THEME':
let newState = {
...state,
theme : { ...state.theme, ...action.baseTheme }
};
return newState;
case 'SWITCH_LANGUAGE':
let newlangState = {
...state,
language : { ...state.language, ...action.baseLang }
};
return newlangState;
default:
return state;
}
}
Upvotes: 0
Views: 106
Reputation: 16132
You need to get the theme from storage and set the new theme.
// add this to your main screen
getTheme = async () => {
const theme = await AsyncStorage.getItem('theme);
this.props.switchTheme(theme);
}
Upvotes: 1