在使用Switch Navigator时在react native中导入Google字体



所以我正在编写一个应用程序,在这个应用程序中,我使用了react native和react Expo的Switch Navigator。所有的导入说明都建议在App.js中导入字体并在

上使用它
export default function App() {...}

问题是,通过使用切换导航器,我现在有

export default createAppContainer(
createSwitchNavigator(
{
Loading: LoadingScreen,
App: AppStack,
Auth: AuthStack,
},
{
initialRouteName: "Loading"
}
)
)

,我找不到一种方法来应用我在这里找到的指令,例如:https://docs.expo.dev/guides/using-custom-fonts/因为我从App.js的默认导出使用了一个Switch Navigator函数。我是否需要在每个屏幕上分别导入字体,或者切换到自定义字体加载方法,因为我使用的是这样的切换导航器?

找到了这样做的方法,以防有人偶然发现。

所以我不得不像这样重构导出默认函数:

const RootApp = createAppContainer(
createSwitchNavigator(
{
Loading: LoadingScreen,
App: AppStack,
Auth: AuthStack,
},
{
initialRouteName: "Loading"
}
)
)
export default function App() {
let [fontsLoaded] = useFonts({
Lobster_400Regular,
});

if (!fontsLoaded) {
return <AppLoading />;
}
// from the custom App we return the component we assigned to RootApp.
return <RootApp />;
}

最新更新