简体   繁体   English

app.js 中的 Expo 自定义 fonts 和 BottomTabNavigator

[英]Expo Custom fonts and BottomTabNavigator in app.js

I'm trying to currently load custom fonts using Expo's method foundhere我正在尝试使用此处找到的 Expo 方法加载自定义 fonts

As the link suggests, it wants me to add the following code to my app.js file正如链接所暗示的,它希望我将以下代码添加到我的 app.js 文件中

 export default class App extends React.Component { componentDidMount() { Font.loadAsync({ 'open-sans-bold': require('./assets/fonts/OpenSans-Bold.ttf'), }); }

However, I'm having difficulty adding that code to my existing app.js code, which includes a CreateBottomTabNaviagator, shown below:但是,我很难将该代码添加到我现有的 app.js 代码中,其中包括一个 CreateBottomTabNaviagator,如下所示:

 import { createStackNavigator, createAppContainer } from 'react-navigation'; import HomeScreen from './src/screens/HomeScreen'; import SavedCollapsibleScreen from "./src/screens/SavedCollapsibleScreen"; import { createBottomTabNavigator, } from 'react-navigation-tabs'; import { Ionicons } from '@expo/vector-icons'; import React, {Component} from "react"; import View from "react-native-web/dist/exports/View"; const Navigator = createBottomTabNavigator( { Home: HomeScreen, SavedPlaces: SavedCollapsibleScreen, }, { initialRouteName: 'SavedPlaces', //headerMode: 'none', defaultNavigationOptions: ({ navigation }) => ({ tabBarIcon: ({ focused, horizontal, tintColor }) => { const { routeName } = navigation.state; let IconComponent = Ionicons; let iconName; if (routeName === 'Home') { iconName = `ios-information-circle${focused? '': '-outline'}`; // Sometimes we want to add badges to some icons. // You can check the implementation below. //IconComponent = HomeIconWithBadge; } else if (routeName === 'SavedPlaces') { iconName = `ios-add-circle${focused? '': '-outline'}`; } // You can return any component that you like here; return <IconComponent name={iconName} size={25} color={tintColor} />, }, }): tabBarOptions: { activeTintColor, 'tomato': inactiveTintColor, 'gray': showLabel,false, }, }; ); export default createAppContainer(Navigator);

How do I go about adding the custom font code into my already existing app.js?如何将自定义字体代码添加到我已经存在的 app.js 中?

I've been trying for 3 hours and couldn't get it to work.我已经尝试了 3 个小时,但无法正常工作。

Thank you in advance!先感谢您!

Created example: https://snack.expo.io/@djalik/test创建示例: https://snack.expo.io/@djalik/test

By using dynamically createAppContainer method in render of Main App Container when font will be loaded:通过在加载字体时在 Main App Container 的渲染中动态使用 createAppContainer 方法:

render()
  {
    const MainApp = !this.state.isLoading? createAppContainer(Navigator):<></>;
     return this.state.isLoading?<AppLoading/>:<MainApp/>;
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM