我的应用程序中有一个自定义主题。它工作正常。当我更改主题时,它将应用于整个应用程序,但是当重新启动应用程序时,它将变为“最初”主题或默认主题。 我的问题是,更改自定义主题时可以将其设置为“初始”主题吗? 重新启动应用程序后,该应用程序应使用上一个应用的自定义主题,而不是初始主题。
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;
}
}
答案 0 :(得分:1)
您需要从存储中获取主题并设置新主题。
// add this to your main screen
getTheme = async () => {
const theme = await AsyncStorage.getItem('theme);
this.props.switchTheme(theme);
}