Initial commit
This commit is contained in:
41
components/AuthContext/index.jsx
Normal file
41
components/AuthContext/index.jsx
Normal file
@@ -0,0 +1,41 @@
|
||||
import { createContext, useState, useContext } from 'react';
|
||||
import { getColor } from '@/assets/styles/css';
|
||||
import { Provider } from '@ant-design/react-native';
|
||||
|
||||
import { SafeAreaView } from 'react-native-safe-area-context';
|
||||
import { StatusBar } from 'react-native';
|
||||
|
||||
StatusBar.setHidden(true);
|
||||
|
||||
// 创建一个上下文
|
||||
const AuthContext = createContext();
|
||||
|
||||
export const AuthProvider = ({ children }) => {
|
||||
const [user, setUser] = useState(null);
|
||||
const hasPerm = (roles = []) => {
|
||||
if (user && user.roles) {
|
||||
return (user.roles || []).some(role => {
|
||||
return (roles || []).includes(role);
|
||||
});
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
const currentLocale = 'zh-CN';
|
||||
const themeColor = getColor();
|
||||
|
||||
return (
|
||||
<Provider locale={currentLocale} theme={themeColor}>
|
||||
<SafeAreaView style={{ flex: 1}}>
|
||||
<AuthContext.Provider value={{ user, setUser, hasPerm, themeColor, currentLocale }}>
|
||||
{children}
|
||||
</AuthContext.Provider>
|
||||
</SafeAreaView>
|
||||
</Provider>
|
||||
);
|
||||
};
|
||||
|
||||
// 自定义 Hook 来使用 AuthContext
|
||||
export const useContextHook = () => {
|
||||
return useContext(AuthContext);
|
||||
};
|
||||
32
components/RotatingIcon/index.jsx
Normal file
32
components/RotatingIcon/index.jsx
Normal file
@@ -0,0 +1,32 @@
|
||||
import React, { useEffect, useRef } from 'react';
|
||||
import { Animated, View } from 'react-native';
|
||||
import { Icon } from '@ant-design/react-native'
|
||||
|
||||
const RotatingIcon = () => {
|
||||
const spinAnim = useRef(new Animated.Value(0)).current; // 创建一个新的 Animated.Value 实例
|
||||
|
||||
useEffect(() => {
|
||||
Animated.loop(
|
||||
Animated.timing(spinAnim, {
|
||||
toValue: 1,
|
||||
duration: 800,
|
||||
useNativeDriver: true, // 这是推荐的做法
|
||||
})
|
||||
).start();
|
||||
}, [spinAnim]);
|
||||
|
||||
const spin = spinAnim.interpolate({
|
||||
inputRange: [0, 1],
|
||||
outputRange: ['0deg', '360deg'],
|
||||
});
|
||||
|
||||
return (
|
||||
<View style={{ alignItems: 'center', justifyContent: 'center', flex: 1 }}>
|
||||
<Animated.View style={{ transform: [{ rotate: spin }] }}>
|
||||
<Icon name="loading-3-quarters" size={24} color="#999999" />
|
||||
</Animated.View>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
export default RotatingIcon;
|
||||
Reference in New Issue
Block a user