feat: 启用新架构支持,更新 App 组件以检测 Fabric 和 TurboModules 状态,并优化缓存清理逻辑

This commit is contained in:
xudan 2025-07-24 09:16:02 +08:00
parent cdffc19db1
commit da8646156b
3 changed files with 40 additions and 9 deletions

41
App.tsx
View File

@ -1,17 +1,42 @@
import React, { useEffect } from 'react';
import { NavigationContainer } from '@react-navigation/native';
import AppNavigator from './src/navigation/AppNavigator';
import { TasksProvider } from './src/context/TasksContext';
import { ThemeProvider } from '@rneui/themed';
import { TasksProvider } from './src/context/TasksContext';
import AppNavigator from './src/navigation/AppNavigator';
import { clearCachedConfig } from './src/services/configService';
export default function App() {
function App(): React.JSX.Element {
// 检测新架构
useEffect(() => {
const globalAny = global as any;
const isFabricEnabled = globalAny.nativeFabricUIManager != null;
const isTurboModuleEnabled = globalAny.__turboModuleProxy != null;
console.log('🏗️ 架构检测结果:');
console.log(
'Fabric (新渲染器):',
isFabricEnabled ? '✅ 已启用' : '❌ 未启用',
);
console.log(
'TurboModules (新模块系统):',
isTurboModuleEnabled ? '✅ 已启用' : '❌ 未启用',
);
console.log(
'新架构状态:',
isFabricEnabled && isTurboModuleEnabled
? '🎉 完全启用'
: '⚠️ 部分启用或未启用',
);
}, []);
useEffect(() => {
const clearCacheOnStart = async () => {
console.log('正在清除缓存的配置文件...');
await clearCachedConfig();
console.log('缓存已清除,将使用最新的 config.json。');
try {
await clearCachedConfig();
console.log('配置缓存已清理');
} catch (error) {
console.error('清理配置缓存失败:', error);
}
};
clearCacheOnStart();
@ -27,3 +52,5 @@ export default function App() {
</ThemeProvider>
);
}
export default App;

View File

@ -32,7 +32,7 @@ reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
# your application. You should enable this flag either if you want
# to write custom TurboModules/Fabric components OR use libraries that
# are providing them.
newArchEnabled=false
newArchEnabled=true
# Use this property to enable or disable the Hermes JS engine.
# If set to false, you will be using JSC instead.

View File

@ -20,7 +20,11 @@ target 'MyReactNativeApp' do
use_react_native!(
:path => config[:reactNativePath],
# An absolute path to your application root.
:app_path => "#{Pod::Config.instance.installation_root}/.."
:app_path => "#{Pod::Config.instance.installation_root}/..",
# Enables Fabric renderer
:fabric_enabled => true,
# Enables the new architecture for iOS
:new_arch_enabled => true
)
post_install do |installer|