From 342dba7ba04eaaba21113ba72c0550992c8c05db Mon Sep 17 00:00:00 2001 From: btobab Date: Fri, 4 Jul 2025 15:16:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9B=BE=E6=A0=87=E6=98=BE?= =?UTF-8?q?=E7=A4=BAbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.tsx | 95 +++++++++++++++++++++++++++++++++++++++- android/app/build.gradle | 1 + 2 files changed, 94 insertions(+), 2 deletions(-) diff --git a/App.tsx b/App.tsx index 81428f7..7f4fb4c 100644 --- a/App.tsx +++ b/App.tsx @@ -1,3 +1,25 @@ +// /** +// * Sample React Native App +// * https://github.com/facebook/react-native +// * +// * @format +// */ +// +// import React from 'react'; +// import Navigation from './src/navigation'; +// import {ThemeProvider} from './src/contexts/ThemeContext'; +// +// function App(): JSX.Element { +// return ( +// +// +// +// ); +// } +// +// export default App; + + /** * Sample React Native App * https://github.com/facebook/react-native @@ -5,11 +27,60 @@ * @format */ -import React from 'react'; +import React, { useState, useEffect } from 'react'; import Navigation from './src/navigation'; import {ThemeProvider} from './src/contexts/ThemeContext'; +import MaterialIcons from 'react-native-vector-icons/MaterialIcons'; +import { View, Text, ActivityIndicator, StyleSheet } from 'react-native'; function App(): JSX.Element { + const [fontLoaded, setFontLoaded] = useState(false); + const [fontError, setFontError] = useState(null); + + useEffect(() => { + const loadFont = async () => { + try { + // 先检查字体是否已加载 + const isLoaded = await MaterialIcons.hasIcon('home'); + + if (!isLoaded) { + console.log('Material Icons not loaded. Loading now...'); + await MaterialIcons.loadFont(); + } + + // 确认字体是否加载成功 + const fontName = MaterialIcons.getFontFamily(); + console.log(`Font loaded successfully: ${fontName}`); + setFontLoaded(true); + } catch (error) { + console.error('Font loading failed:', error); + setFontError('Failed to load icon fonts'); + } + }; + + // 加入延迟以解决模拟器启动时的问题 + const timeout = setTimeout(() => { + loadFont(); + }, 500); + + return () => clearTimeout(timeout); + }, []); + + // 显示加载状态或错误信息 + if (!fontLoaded || fontError) { + return ( + + + + {fontError || 'Loading icons...'} + + + Using MaterialIcons font family: {MaterialIcons.getFontFamily()} + + + ); + } + return ( @@ -17,4 +88,24 @@ function App(): JSX.Element { ); } -export default App; +const styles = StyleSheet.create({ + container: { + flex: 1, + justifyContent: 'center', + alignItems: 'center', + backgroundColor: '#f5f5f5', + }, + statusText: { + marginTop: 20, + fontSize: 16, + color: '#333', + }, + debugText: { + marginTop: 10, + fontSize: 12, + color: '#666', + fontFamily: 'monospace', + }, +}); + +export default App; \ No newline at end of file diff --git a/android/app/build.gradle b/android/app/build.gradle index fc8699d..dcb6a16 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: "com.android.application" apply plugin: "org.jetbrains.kotlin.android" apply plugin: "com.facebook.react" +apply from: "../../node_modules/react-native-vector-icons/fonts.gradle" /** * This is the configuration block to customize your React Native Android app.