我想使用“expo-linear-gradient"
”中的LinearGradient
组件,该组件在我的所有屏幕堆栈中充当背景。如何实现这一点?
请参见App.tsx中的堆栈配置:
export default function App() {
const { t } = useTranslation("Titles");
return (
<Provider store={store}> // redux
<NativeBaseProvider theme={nativeBaseTheme}> // native base wrapper. maybe a solution here?
<NavigationContainer>
<Stack.Navigator>
// a possible wrapper as a background for all the screens?
<Stack.Screen
name="HomePage"
component={HomePage}
options={{ title: t("1") as string }} />
<Stack.Screen
name="Settings"
component={Settings}
options={{ title: t("2") as string }} />
<Stack.Screen
name="Sign Up"
component={SignUp}
options={{
title: t("3") as string
}} />
</Stack.Navigator>
</NavigationContainer>
</NativeBaseProvider>
</Provider>
);
}
- (函数
t
仅用于翻译,请忽略)*
我试图从"@react-navigation/native"
覆盖DefaultTheme
,但是那里的背景域只接受string
。所以它不起作用。
如果我用LinearGradient
Package 一个功能组件,比如SignUp
,它可以工作,但是这样我重复了我的代码,这是一个不好的做法,并且很难扩展应用程序。
我读了a similar question here,但我猜解决方案已经过时了,它对我不起作用。
我来自React背景,不是本地人,所以这对我来说真的很困惑。我很高兴得到任何帮助,提前感谢。
1条答案
按热度按时间zbwhf8kr1#
好吧,解决办法很简单: