Files
JKVideo/components/LoginModal.tsx
Developer 3f82646496 init
2026-03-26 12:15:40 +08:00

117 lines
3.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React, { useRef } from "react";
import {
Modal,
View,
Text,
StyleSheet,
TouchableOpacity,
Animated,
} from "react-native";
import { Ionicons } from "@expo/vector-icons";
import { pollQRCode } from "../services/api";
import { useAuthStore } from "../store/authStore";
import { useTheme } from "../utils/theme";
interface Props {
visible: boolean;
onClose: () => void;
}
export function LoginModal({ visible, onClose }: Props) {
const login = useAuthStore((s) => s.login);
const theme = useTheme();
const slideY = useRef(new Animated.Value(300)).current;
React.useEffect(() => {
if (visible) {
Animated.spring(slideY, {
toValue: 0,
useNativeDriver: true,
bounciness: 4,
}).start();
} else {
slideY.setValue(300);
}
}, [visible]);
async function handleLogin() {
const result = await pollQRCode('mock-key');
if (result.code === 0 && result.cookie) {
await login(result.cookie, '', '');
onClose();
}
}
return (
<Modal
visible={visible}
transparent
animationType="none"
onRequestClose={onClose}
>
<View style={styles.overlay} pointerEvents="box-none" />
<Animated.View
style={[styles.sheetWrapper, { transform: [{ translateY: slideY }] }]}
>
<View style={[styles.sheet, { backgroundColor: theme.sheetBg }]}>
<Text style={[styles.title, { color: theme.modalText }]}></Text>
<View style={styles.iconWrap}>
<Ionicons name="person-circle-outline" size={72} color="#00AEEC" />
</View>
<Text style={[styles.hint, { color: theme.modalTextSub }]}>
</Text>
<TouchableOpacity
style={styles.loginBtn}
onPress={handleLogin}
activeOpacity={0.85}
>
<Text style={styles.loginBtnText}></Text>
</TouchableOpacity>
<TouchableOpacity style={styles.closeBtn} onPress={onClose}>
<Text style={[styles.closeTxt, { color: "#00AEEC" }]}></Text>
</TouchableOpacity>
</View>
</Animated.View>
</Modal>
);
}
const styles = StyleSheet.create({
overlay: {
...StyleSheet.absoluteFillObject,
backgroundColor: "rgba(0,0,0,0.5)",
},
sheetWrapper: {
position: "absolute",
bottom: 0,
left: 0,
right: 0,
},
sheet: {
borderTopLeftRadius: 16,
borderTopRightRadius: 16,
padding: 24,
alignItems: "center",
},
title: { fontSize: 18, fontWeight: "600", marginBottom: 20 },
iconWrap: { marginBottom: 16 },
hint: { fontSize: 13, marginBottom: 24, textAlign: "center" },
loginBtn: {
backgroundColor: "#00AEEC",
borderRadius: 24,
paddingVertical: 12,
paddingHorizontal: 48,
marginBottom: 8,
},
loginBtnText: { color: "#fff", fontSize: 16, fontWeight: "600" },
closeBtn: { padding: 12 },
closeTxt: { fontSize: 14 },
});