BikeApp_demo/App.tsx
2024-12-17 16:39:34 +08:00

50 lines
1.3 KiB
TypeScript

import React, { useEffect } from 'react';
import { ApplicationProvider, IconRegistry, Layout } from '@ui-kitten/components';
import { EvaIconsPack } from '@ui-kitten/eva-icons';
import * as eva from '@eva-design/eva';
import AppNavigator from './src/navigation';
import Toast from 'react-native-toast-message';
import { Platform } from 'react-native';
import { AuthProvider, useAuth } from './src/context/AuthContext';
import { setToastFunction, setLogoutFunction } from './src/utils/api';
const AppContent = () => {
const { logout } = useAuth();
useEffect(() => {
// 设置全局 Toast 函数
setToastFunction((message) => {
Toast.show({
type: 'error',
text1: '提示',
text2: message,
position: 'top',
topOffset: Platform.OS === 'ios' ? 60 : 20,
visibilityTime: 2000,
});
});
// 设置全局 logout 函数
setLogoutFunction(logout);
}, [logout]);
return (
<Layout style={{ flex: 1 }}>
<AppNavigator />
</Layout>
);
};
export default function App() {
return (
<>
<IconRegistry icons={EvaIconsPack} />
<ApplicationProvider {...eva} theme={eva.light}>
<AuthProvider>
<AppContent />
</AuthProvider>
</ApplicationProvider>
<Toast />
</>
);
}