轻松聘
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

177 lines
4.8 KiB

import { Ionicons } from '@expo/vector-icons';
import { useRouter } from 'expo-router';
import { ActivityIndicator, Pressable, ScrollView, StyleSheet, Switch, Text, View } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { useNotificationSettings } from '../../src/hooks';
import { colors } from '../../src/theme';
/* ===================== 子组件:顶部导航 ===================== */
function Header({ onBack }: { onBack: () => void }) {
return (
<View style={styles.header}>
<Pressable style={styles.headerBtn} onPress={onBack} hitSlop={8}>
<Ionicons name="chevron-back" size={24} color={colors.textPrimary} />
</Pressable>
<Text style={styles.headerTitle}>消息通知</Text>
<View style={styles.headerBtn} />
</View>
);
}
/* ===================== 页面 ===================== */
export default function NotificationSettingsScreen() {
const router = useRouter();
const { settings, loading, error, refresh, toggle, updatingId } = useNotificationSettings();
return (
<SafeAreaView style={styles.safeArea} edges={['top']}>
<Header onBack={() => router.back()} />
{loading ? (
<View style={styles.stateBox}>
<ActivityIndicator size="large" color={colors.primary} />
</View>
) : error ? (
<View style={styles.stateBox}>
<Text style={styles.stateText}>加载失败,请重试</Text>
<Pressable style={styles.retryBtn} onPress={refresh}>
<Text style={styles.retryText}>重试</Text>
</Pressable>
</View>
) : settings.length === 0 ? (
<View style={styles.stateBox}>
<Ionicons name="notifications-off-outline" size={48} color={colors.textHint} />
<Text style={styles.stateText}>暂无通知设置项</Text>
</View>
) : (
<ScrollView
style={styles.scroll}
contentContainerStyle={styles.content}
showsVerticalScrollIndicator={false}
>
<Text style={styles.tip}>
选择你希望接收的通知类型,重要通知建议保持开启。
</Text>
<View style={styles.card}>
{settings.map((item, index) => {
const isLast = index === settings.length - 1;
return (
<View key={item.id} style={[styles.row, isLast && styles.rowLast]}>
<View style={styles.rowBody}>
<Text style={styles.rowTitle}>{item.title}</Text>
<Text style={styles.rowDesc}>{item.description}</Text>
</View>
<Switch
value={item.enabled}
onValueChange={(next) => toggle(item.id, next)}
disabled={updatingId === item.id}
trackColor={{ false: colors.border, true: colors.primaryBorder }}
thumbColor={item.enabled ? colors.primary : colors.white}
/>
</View>
);
})}
</View>
</ScrollView>
)}
</SafeAreaView>
);
}
const styles = StyleSheet.create({
safeArea: {
flex: 1,
backgroundColor: colors.pageBg,
},
header: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
paddingHorizontal: 8,
height: 48,
backgroundColor: colors.white,
borderBottomWidth: 1,
borderBottomColor: colors.borderLight,
},
headerBtn: {
width: 40,
height: 40,
alignItems: 'center',
justifyContent: 'center',
},
headerTitle: {
fontSize: 17,
fontWeight: '700',
color: colors.textPrimary,
},
scroll: {
flex: 1,
},
content: {
padding: 8,
paddingBottom: 24,
},
tip: {
fontSize: 12,
lineHeight: 17,
color: colors.textSecondary,
marginBottom: 10,
paddingHorizontal: 4,
},
card: {
backgroundColor: colors.white,
borderRadius: 8,
paddingHorizontal: 8,
},
row: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
paddingVertical: 14,
borderBottomWidth: 1,
borderBottomColor: colors.borderLight,
},
rowLast: {
borderBottomWidth: 0,
},
rowBody: {
flex: 1,
marginRight: 12,
},
rowTitle: {
fontSize: 15,
fontWeight: '600',
color: colors.textPrimary,
},
rowDesc: {
marginTop: 3,
fontSize: 12,
lineHeight: 16,
color: colors.textSecondary,
},
stateBox: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
stateText: {
marginTop: 12,
fontSize: 14,
color: colors.textSecondary,
},
retryBtn: {
marginTop: 16,
paddingHorizontal: 24,
paddingVertical: 8,
borderRadius: 18,
backgroundColor: colors.primaryBtn,
},
retryText: {
fontSize: 13,
fontWeight: '600',
color: colors.white,
},
});