react-native - 无法在应用程序的其他部分通过 expo 使用谷歌自定义字体
问题描述
我正在我的文件中加载带有 expo 的谷歌自定义字体,App.js
如下所示:
;
import {
useFonts,
Poppins_300Light,
Poppins_400Regular,
Poppins_400Regular_Italic
} from "@expo-google-fonts/poppins";
export default function App() {
const [auth, setAuth] = useState(false);
const [loading, setLoading] = useState(true);
let [fontsLoaded] = useFonts({
"Poppins-Light": Poppins_300Light,
"Poppins-Regular": Poppins_400Regular,
"Poppins-Regular-Italic": Poppins_400Regular_Italic,
});
useEffect(() => {
(async () => {
// Check if user is logged in
const token = await getKey("access_token");
if (token) {
setAuth(true);
}
})();
setLoading(false);
}, []);
if (loading || !fontsLoaded) {
return <AppLoading />;
}
return (
<NavigationContainer>
<Stack.Navigator
initialRouteName="Camera"
>
{!auth ? (
<>
<Stack.Screen
name="Analytics"
component={Analytics}
/>
<Stack.Screen
name="Settings"
component={Settings}
/>
</>
) : (
<>
<Stack.Screen
name="Login"
component={Login}
/>
</>
)}
</Stack.Navigator>
</NavigationContainer>
);
}
现在,当我尝试font-family: Poppins-Light
在我的Login.js
文件中使用时,我得到了错误Unrecognized font family "Poppins-Light"
不知道发生了什么。我认为我加载的方式可能有问题,此外,我如何将字体导入到我的Login
文件中。
我也在使用样式化的组件,所以我不确定这是否有任何影响。
这是我的包 JSON
"dependencies": {
"@expo-google-fonts/inter": "^0.1.0",
"@expo-google-fonts/poppins": "^0.1.0",
"@react-native-community/masked-view": "0.1.10",
"@react-navigation/bottom-tabs": "^5.11.8",
"@react-navigation/native": "^5.9.3",
"@react-navigation/stack": "^5.14.3",
"expo": "~40.0.1",
"expo-app-loading": "^1.0.1",
"expo-camera": "~9.1.0",
"expo-constants": "~9.3.3",
"expo-font": "~8.4.0",
"expo-haptics": "~8.4.0",
"expo-jwt": "^1.4.0",
"expo-linear-gradient": "~8.4.0",
"expo-secure-store": "~9.3.0",
"expo-sqlite": "~8.5.0",
"expo-status-bar": "~1.0.3",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-40.0.1.tar.gz",
"react-native-dotenv": "^2.5.3",
"react-native-gesture-handler": "~1.8.0",
"react-native-global-props": "^1.1.5",
"react-native-reanimated": "~1.13.0",
"react-native-safe-area-context": "3.1.9",
"react-native-screens": "~2.15.2",
"react-native-svg": "^12.1.0",
"react-native-svg-transformer": "^0.14.3",
"react-native-unimodules": "^0.12.0",
"react-native-web": "~0.13.12",
"react-swipeable-views-native": "^0.13.2",
"styled-components": "^5.2.1"
},
这就是我在Channels.js
文件中使用它的方式
<HeaderTitle style={{ fontFamily: "Poppins-Light" }}>
Channels
</HeaderTitle>
这是我尝试访问该页面时的错误:
知道我做错了什么吗?
您的帮助将不胜感激。
解决方案
看这里,小吃。根据规律。
如果问题仍然存在,请提供更多带有文件结构的代码片段,然后我们可以查明您的问题。
推荐阅读
- c++ - 使用 C++ 的双变量 Gurobi
- jboss - 来自 ActiveMQ Artemis 主题的消息不会传递到所有订阅的 MDB
- php - MYSQL / PHP - 如何检查第二个查询以检查复选框
- quarkus - Quarkus:如何与 Artemis 使用点对点消息传递?
- r - 我可以根据同一 tibble 中另一列的值过滤一列吗?
- c# - 替换正则表达式匹配
- javascript - 从字符串 JavaScript 创建嵌套对象
- r - 在 r 中创建一个带有布尔选项的函数:如果在调用函数时没有提供布尔选项,我如何返回数据帧?
- php - Laravel 只搜索完全匹配
- python - Lstrip 和 Rstrip 不起作用,需要帮助从 Python 3 的输出中删除文本