2026-04-01 02:17:36 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 聊天设置页 ChatSettingsScreen
|
|
|
|
|
|
* 胡萝卜BBS - 聊天个性化设置
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2026-04-04 08:01:45 +08:00
|
|
|
|
import React, { useMemo, useCallback, useRef } from 'react';
|
2026-04-01 02:17:36 +08:00
|
|
|
|
import {
|
|
|
|
|
|
View,
|
|
|
|
|
|
StyleSheet,
|
|
|
|
|
|
TouchableOpacity,
|
|
|
|
|
|
ScrollView,
|
|
|
|
|
|
Dimensions,
|
2026-04-04 08:01:45 +08:00
|
|
|
|
PanResponder,
|
2026-04-01 02:17:36 +08:00
|
|
|
|
} from 'react-native';
|
|
|
|
|
|
import { SafeAreaView } from 'react-native-safe-area-context';
|
|
|
|
|
|
import {
|
|
|
|
|
|
useAppColors,
|
|
|
|
|
|
spacing,
|
|
|
|
|
|
fontSizes,
|
|
|
|
|
|
borderRadius,
|
|
|
|
|
|
type AppColors,
|
|
|
|
|
|
} from '../../theme';
|
|
|
|
|
|
import { Text } from '../../components/common';
|
|
|
|
|
|
import { useResponsiveSpacing } from '../../hooks';
|
2026-04-01 16:30:44 +08:00
|
|
|
|
import {
|
|
|
|
|
|
useChatSettingsStore,
|
|
|
|
|
|
useChatSettingsActions,
|
|
|
|
|
|
CHAT_THEMES,
|
|
|
|
|
|
} from '../../stores/chatSettingsStore';
|
2026-04-01 02:17:36 +08:00
|
|
|
|
|
|
|
|
|
|
const { width: SCREEN_WIDTH } = Dimensions.get('window');
|
|
|
|
|
|
const CARD_MAX_WIDTH = 720;
|
|
|
|
|
|
|
|
|
|
|
|
interface SliderProps {
|
|
|
|
|
|
value: number;
|
|
|
|
|
|
min: number;
|
|
|
|
|
|
max: number;
|
|
|
|
|
|
onValueChange: (value: number) => void;
|
|
|
|
|
|
leftLabel?: string;
|
|
|
|
|
|
rightLabel?: string;
|
|
|
|
|
|
showValue?: boolean;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-04 08:01:45 +08:00
|
|
|
|
// 自定义滑块组件(支持拖动)
|
2026-04-01 02:17:36 +08:00
|
|
|
|
const Slider: React.FC<SliderProps> = ({
|
|
|
|
|
|
value,
|
|
|
|
|
|
min,
|
|
|
|
|
|
max,
|
|
|
|
|
|
onValueChange,
|
|
|
|
|
|
leftLabel,
|
|
|
|
|
|
rightLabel,
|
|
|
|
|
|
showValue = true,
|
|
|
|
|
|
}) => {
|
|
|
|
|
|
const colors = useAppColors();
|
|
|
|
|
|
const styles = useMemo(() => createSliderStyles(colors), [colors]);
|
2026-04-04 08:01:45 +08:00
|
|
|
|
const trackWidthRef = useRef(0);
|
2026-04-01 02:17:36 +08:00
|
|
|
|
|
2026-04-04 08:01:45 +08:00
|
|
|
|
const percentage = isNaN(value) ? 0 : ((value - min) / (max - min)) * 100;
|
|
|
|
|
|
|
|
|
|
|
|
const updateValue = useCallback((locationX: number) => {
|
|
|
|
|
|
const width = trackWidthRef.current;
|
|
|
|
|
|
if (width <= 0) return;
|
|
|
|
|
|
|
|
|
|
|
|
const newPercentage = Math.max(0, Math.min(100, (locationX / width) * 100));
|
2026-04-01 02:17:36 +08:00
|
|
|
|
const newValue = Math.round(min + (newPercentage / 100) * (max - min));
|
|
|
|
|
|
onValueChange(newValue);
|
|
|
|
|
|
}, [min, max, onValueChange]);
|
|
|
|
|
|
|
2026-04-04 08:01:45 +08:00
|
|
|
|
const panResponder = useMemo(() => PanResponder.create({
|
|
|
|
|
|
onStartShouldSetPanResponder: () => true,
|
|
|
|
|
|
onMoveShouldSetPanResponder: () => true,
|
|
|
|
|
|
onPanResponderGrant: (evt) => {
|
|
|
|
|
|
updateValue(evt.nativeEvent.locationX);
|
|
|
|
|
|
},
|
|
|
|
|
|
onPanResponderMove: (evt) => {
|
|
|
|
|
|
updateValue(evt.nativeEvent.locationX);
|
|
|
|
|
|
},
|
|
|
|
|
|
}), [updateValue]);
|
|
|
|
|
|
|
|
|
|
|
|
const handleLayout = useCallback((event: any) => {
|
|
|
|
|
|
trackWidthRef.current = event.nativeEvent.layout.width;
|
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
2026-04-01 02:17:36 +08:00
|
|
|
|
return (
|
|
|
|
|
|
<View style={styles.container}>
|
|
|
|
|
|
<View style={styles.labelRow}>
|
|
|
|
|
|
{leftLabel && <Text style={styles.label}>{leftLabel}</Text>}
|
2026-04-04 08:01:45 +08:00
|
|
|
|
{showValue && <Text style={styles.value}>{isNaN(value) ? 0 : value}</Text>}
|
2026-04-01 02:17:36 +08:00
|
|
|
|
{rightLabel && <Text style={styles.label}>{rightLabel}</Text>}
|
|
|
|
|
|
</View>
|
2026-04-04 08:01:45 +08:00
|
|
|
|
<View
|
2026-04-01 02:17:36 +08:00
|
|
|
|
style={styles.trackContainer}
|
2026-04-04 08:01:45 +08:00
|
|
|
|
onLayout={handleLayout}
|
|
|
|
|
|
{...panResponder.panHandlers}
|
2026-04-01 02:17:36 +08:00
|
|
|
|
>
|
|
|
|
|
|
<View style={styles.track}>
|
|
|
|
|
|
<View style={[styles.fill, { width: `${percentage}%`, backgroundColor: colors.primary.main }]} />
|
|
|
|
|
|
</View>
|
|
|
|
|
|
<View style={[styles.thumb, { left: `${percentage}%`, backgroundColor: colors.primary.main }]} />
|
2026-04-04 08:01:45 +08:00
|
|
|
|
</View>
|
2026-04-01 02:17:36 +08:00
|
|
|
|
</View>
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function createSliderStyles(colors: AppColors) {
|
|
|
|
|
|
return StyleSheet.create({
|
|
|
|
|
|
container: {
|
|
|
|
|
|
marginVertical: spacing.sm,
|
|
|
|
|
|
},
|
|
|
|
|
|
labelRow: {
|
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
|
marginBottom: spacing.xs,
|
|
|
|
|
|
},
|
|
|
|
|
|
label: {
|
|
|
|
|
|
fontSize: fontSizes.sm,
|
|
|
|
|
|
color: colors.text.secondary,
|
|
|
|
|
|
},
|
|
|
|
|
|
value: {
|
|
|
|
|
|
fontSize: fontSizes.md,
|
|
|
|
|
|
fontWeight: '600',
|
|
|
|
|
|
color: colors.primary.main,
|
|
|
|
|
|
},
|
|
|
|
|
|
trackContainer: {
|
|
|
|
|
|
height: 24,
|
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
|
},
|
|
|
|
|
|
track: {
|
|
|
|
|
|
height: 4,
|
|
|
|
|
|
backgroundColor: colors.divider,
|
|
|
|
|
|
borderRadius: 2,
|
|
|
|
|
|
},
|
|
|
|
|
|
fill: {
|
|
|
|
|
|
height: '100%',
|
|
|
|
|
|
borderRadius: 2,
|
|
|
|
|
|
},
|
|
|
|
|
|
thumb: {
|
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
|
width: 20,
|
|
|
|
|
|
height: 20,
|
|
|
|
|
|
borderRadius: 10,
|
|
|
|
|
|
marginLeft: -10,
|
|
|
|
|
|
shadowColor: '#000',
|
|
|
|
|
|
shadowOffset: { width: 0, height: 2 },
|
|
|
|
|
|
shadowOpacity: 0.2,
|
|
|
|
|
|
shadowRadius: 2,
|
|
|
|
|
|
elevation: 3,
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function createStyles(colors: AppColors) {
|
|
|
|
|
|
return StyleSheet.create({
|
|
|
|
|
|
container: {
|
|
|
|
|
|
flex: 1,
|
2026-04-02 17:55:56 +08:00
|
|
|
|
backgroundColor: colors.background.paper,
|
2026-04-01 02:17:36 +08:00
|
|
|
|
},
|
|
|
|
|
|
scrollContent: {
|
2026-04-02 17:55:56 +08:00
|
|
|
|
paddingVertical: spacing.lg,
|
2026-04-01 02:17:36 +08:00
|
|
|
|
},
|
|
|
|
|
|
section: {
|
2026-04-02 17:55:56 +08:00
|
|
|
|
marginBottom: spacing['2xl'],
|
2026-04-01 02:17:36 +08:00
|
|
|
|
maxWidth: CARD_MAX_WIDTH,
|
|
|
|
|
|
alignSelf: 'center',
|
|
|
|
|
|
width: '100%',
|
2026-04-02 17:55:56 +08:00
|
|
|
|
paddingHorizontal: spacing['2xl'],
|
2026-04-01 02:17:36 +08:00
|
|
|
|
},
|
|
|
|
|
|
sectionTitle: {
|
|
|
|
|
|
fontSize: fontSizes.sm,
|
|
|
|
|
|
fontWeight: '600',
|
|
|
|
|
|
color: colors.text.secondary,
|
|
|
|
|
|
marginBottom: spacing.sm,
|
2026-04-02 17:55:56 +08:00
|
|
|
|
marginTop: spacing.sm,
|
|
|
|
|
|
textTransform: 'uppercase',
|
|
|
|
|
|
letterSpacing: 0.5,
|
2026-04-01 02:17:36 +08:00
|
|
|
|
},
|
|
|
|
|
|
// 聊天预览样式
|
|
|
|
|
|
previewContainer: {
|
2026-04-02 17:55:56 +08:00
|
|
|
|
backgroundColor: colors.primary.light + '20',
|
|
|
|
|
|
borderRadius: 14,
|
2026-04-01 02:17:36 +08:00
|
|
|
|
padding: spacing.md,
|
|
|
|
|
|
minHeight: 140,
|
|
|
|
|
|
},
|
|
|
|
|
|
previewMessage: {
|
2026-04-04 08:01:45 +08:00
|
|
|
|
backgroundColor: '#FFFFFF',
|
2026-04-01 02:17:36 +08:00
|
|
|
|
padding: spacing.sm,
|
|
|
|
|
|
marginBottom: spacing.sm,
|
|
|
|
|
|
maxWidth: '80%',
|
|
|
|
|
|
alignSelf: 'flex-start',
|
2026-04-04 08:01:45 +08:00
|
|
|
|
minWidth: 44,
|
|
|
|
|
|
shadowColor: '#000',
|
|
|
|
|
|
shadowOffset: { width: 0, height: 1 },
|
|
|
|
|
|
shadowOpacity: 0.06,
|
|
|
|
|
|
shadowRadius: 2,
|
|
|
|
|
|
elevation: 1,
|
2026-04-01 02:17:36 +08:00
|
|
|
|
},
|
|
|
|
|
|
previewReply: {
|
|
|
|
|
|
padding: spacing.sm,
|
|
|
|
|
|
maxWidth: '80%',
|
|
|
|
|
|
alignSelf: 'flex-end',
|
2026-04-04 08:01:45 +08:00
|
|
|
|
minWidth: 44,
|
|
|
|
|
|
shadowColor: '#000',
|
|
|
|
|
|
shadowOffset: { width: 0, height: 1 },
|
|
|
|
|
|
shadowOpacity: 0.06,
|
|
|
|
|
|
shadowRadius: 2,
|
|
|
|
|
|
elevation: 1,
|
2026-04-01 02:17:36 +08:00
|
|
|
|
},
|
|
|
|
|
|
previewText: {
|
2026-04-02 17:55:56 +08:00
|
|
|
|
color: colors.text.primary,
|
2026-04-01 02:17:36 +08:00
|
|
|
|
},
|
|
|
|
|
|
// 主题选择样式
|
|
|
|
|
|
themeList: {
|
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
|
gap: spacing.sm,
|
|
|
|
|
|
},
|
|
|
|
|
|
themeItem: {
|
|
|
|
|
|
width: 70,
|
|
|
|
|
|
height: 90,
|
|
|
|
|
|
borderRadius: borderRadius.md,
|
|
|
|
|
|
borderWidth: 2,
|
|
|
|
|
|
borderColor: 'transparent',
|
|
|
|
|
|
overflow: 'hidden',
|
|
|
|
|
|
padding: spacing.xs,
|
|
|
|
|
|
},
|
|
|
|
|
|
themeItemActive: {
|
|
|
|
|
|
borderColor: colors.primary.main,
|
|
|
|
|
|
},
|
|
|
|
|
|
themePreview: {
|
|
|
|
|
|
flex: 1,
|
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
|
gap: 4,
|
|
|
|
|
|
},
|
|
|
|
|
|
themeBubble1: {
|
|
|
|
|
|
height: 12,
|
|
|
|
|
|
borderRadius: 6,
|
|
|
|
|
|
width: '70%',
|
|
|
|
|
|
},
|
|
|
|
|
|
themeBubble2: {
|
|
|
|
|
|
height: 12,
|
|
|
|
|
|
borderRadius: 6,
|
|
|
|
|
|
width: '50%',
|
|
|
|
|
|
alignSelf: 'flex-end',
|
|
|
|
|
|
},
|
|
|
|
|
|
themeIcon: {
|
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
|
bottom: 4,
|
|
|
|
|
|
right: 4,
|
|
|
|
|
|
width: 18,
|
|
|
|
|
|
height: 18,
|
|
|
|
|
|
borderRadius: 9,
|
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
|
},
|
|
|
|
|
|
themeName: {
|
|
|
|
|
|
fontSize: fontSizes.xs,
|
|
|
|
|
|
textAlign: 'center',
|
|
|
|
|
|
marginTop: 4,
|
|
|
|
|
|
color: colors.text.secondary,
|
|
|
|
|
|
},
|
2026-04-02 17:55:56 +08:00
|
|
|
|
sliderContainer: {
|
|
|
|
|
|
paddingVertical: 8,
|
|
|
|
|
|
},
|
2026-04-01 02:17:36 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export const ChatSettingsScreen: React.FC = () => {
|
|
|
|
|
|
const colors = useAppColors();
|
|
|
|
|
|
const styles = useMemo(() => createStyles(colors), [colors]);
|
|
|
|
|
|
const responsivePadding = useResponsiveSpacing({ xs: 8, sm: 12, md: 16, lg: 24, xl: 32 });
|
|
|
|
|
|
|
2026-04-01 16:30:44 +08:00
|
|
|
|
// 从 store 获取状态
|
|
|
|
|
|
const fontSize = useChatSettingsStore((s) => s.fontSize);
|
|
|
|
|
|
const messageRadius = useChatSettingsStore((s) => s.messageRadius);
|
|
|
|
|
|
const themeIndex = useChatSettingsStore((s) => s.themeIndex);
|
|
|
|
|
|
|
2026-04-04 08:01:45 +08:00
|
|
|
|
const { setFontSize, setMessageRadius, setTheme } = useChatSettingsActions();
|
2026-04-01 16:30:44 +08:00
|
|
|
|
|
|
|
|
|
|
const currentTheme = CHAT_THEMES[themeIndex];
|
2026-04-01 02:17:36 +08:00
|
|
|
|
|
|
|
|
|
|
// 渲染聊天预览
|
|
|
|
|
|
const renderChatPreview = () => (
|
|
|
|
|
|
<View style={styles.section}>
|
|
|
|
|
|
<Text style={styles.sectionTitle}>预览</Text>
|
|
|
|
|
|
<View style={[styles.previewContainer, { backgroundColor: currentTheme.secondary }]}>
|
2026-04-04 08:01:45 +08:00
|
|
|
|
<View style={[
|
|
|
|
|
|
styles.previewMessage,
|
|
|
|
|
|
{
|
|
|
|
|
|
borderRadius: messageRadius,
|
|
|
|
|
|
borderTopLeftRadius: Math.max(4, messageRadius * 0.3),
|
|
|
|
|
|
}
|
|
|
|
|
|
]}>
|
|
|
|
|
|
<Text style={[styles.previewText, { fontSize }]}>
|
2026-04-01 02:17:36 +08:00
|
|
|
|
早上好!👋
|
|
|
|
|
|
</Text>
|
2026-04-04 08:01:45 +08:00
|
|
|
|
<Text style={[styles.previewText, { fontSize }]}>
|
2026-04-01 02:17:36 +08:00
|
|
|
|
你知道现在几点吗?
|
|
|
|
|
|
</Text>
|
|
|
|
|
|
</View>
|
2026-04-04 08:01:45 +08:00
|
|
|
|
<View style={[
|
|
|
|
|
|
styles.previewReply,
|
|
|
|
|
|
{
|
|
|
|
|
|
borderRadius: messageRadius,
|
|
|
|
|
|
borderBottomRightRadius: Math.max(4, messageRadius * 0.3),
|
|
|
|
|
|
backgroundColor: currentTheme.bubble
|
|
|
|
|
|
}
|
|
|
|
|
|
]}>
|
2026-04-01 02:17:36 +08:00
|
|
|
|
<Text style={[styles.previewText, { fontSize }]}>
|
2026-04-01 16:30:44 +08:00
|
|
|
|
现在是威海的早晨😎
|
2026-04-01 02:17:36 +08:00
|
|
|
|
</Text>
|
|
|
|
|
|
</View>
|
|
|
|
|
|
</View>
|
|
|
|
|
|
</View>
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// 渲染字号滑块
|
|
|
|
|
|
const renderFontSizeSlider = () => (
|
|
|
|
|
|
<View style={styles.section}>
|
|
|
|
|
|
<Text style={styles.sectionTitle}>消息字号</Text>
|
2026-04-02 17:55:56 +08:00
|
|
|
|
<View style={styles.sliderContainer}>
|
2026-04-01 02:17:36 +08:00
|
|
|
|
<Slider
|
|
|
|
|
|
value={fontSize}
|
|
|
|
|
|
min={12}
|
|
|
|
|
|
max={24}
|
|
|
|
|
|
onValueChange={setFontSize}
|
|
|
|
|
|
leftLabel="A"
|
|
|
|
|
|
rightLabel="A"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</View>
|
|
|
|
|
|
</View>
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// 渲染主题颜色选择
|
|
|
|
|
|
const renderThemeColors = () => (
|
|
|
|
|
|
<View style={styles.section}>
|
|
|
|
|
|
<Text style={styles.sectionTitle}>主题颜色</Text>
|
|
|
|
|
|
<ScrollView
|
|
|
|
|
|
horizontal
|
|
|
|
|
|
showsHorizontalScrollIndicator={false}
|
|
|
|
|
|
contentContainerStyle={styles.themeList}
|
|
|
|
|
|
>
|
2026-04-01 16:30:44 +08:00
|
|
|
|
{CHAT_THEMES.map((theme, index) => (
|
2026-04-01 02:17:36 +08:00
|
|
|
|
<TouchableOpacity
|
|
|
|
|
|
key={theme.id}
|
|
|
|
|
|
style={[
|
|
|
|
|
|
styles.themeItem,
|
2026-04-01 16:30:44 +08:00
|
|
|
|
themeIndex === index && styles.themeItemActive,
|
2026-04-01 02:17:36 +08:00
|
|
|
|
{ backgroundColor: theme.secondary },
|
|
|
|
|
|
]}
|
2026-04-01 16:30:44 +08:00
|
|
|
|
onPress={() => setTheme(index)}
|
2026-04-01 02:17:36 +08:00
|
|
|
|
activeOpacity={0.8}
|
|
|
|
|
|
>
|
|
|
|
|
|
<View style={styles.themePreview}>
|
|
|
|
|
|
<View style={[styles.themeBubble1, { backgroundColor: '#FFFFFF' }]} />
|
|
|
|
|
|
<View style={[styles.themeBubble2, { backgroundColor: theme.bubble }]} />
|
|
|
|
|
|
</View>
|
|
|
|
|
|
<View style={[styles.themeIcon, { backgroundColor: theme.primary }]}>
|
|
|
|
|
|
<Text style={{ fontSize: 10 }}>{theme.icon}</Text>
|
|
|
|
|
|
</View>
|
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</ScrollView>
|
|
|
|
|
|
</View>
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// 渲染圆角滑块
|
|
|
|
|
|
const renderRadiusSlider = () => (
|
|
|
|
|
|
<View style={styles.section}>
|
|
|
|
|
|
<Text style={styles.sectionTitle}>消息圆角</Text>
|
2026-04-02 17:55:56 +08:00
|
|
|
|
<View style={styles.sliderContainer}>
|
2026-04-01 02:17:36 +08:00
|
|
|
|
<Slider
|
|
|
|
|
|
value={messageRadius}
|
|
|
|
|
|
min={0}
|
|
|
|
|
|
max={30}
|
|
|
|
|
|
onValueChange={setMessageRadius}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</View>
|
|
|
|
|
|
</View>
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<SafeAreaView style={styles.container} edges={['bottom']}>
|
|
|
|
|
|
<ScrollView
|
|
|
|
|
|
contentContainerStyle={[
|
|
|
|
|
|
styles.scrollContent,
|
2026-04-04 08:01:45 +08:00
|
|
|
|
{ paddingHorizontal: responsivePadding, paddingBottom: 80 }
|
2026-04-01 02:17:36 +08:00
|
|
|
|
]}
|
|
|
|
|
|
>
|
|
|
|
|
|
{renderFontSizeSlider()}
|
|
|
|
|
|
{renderChatPreview()}
|
|
|
|
|
|
{renderThemeColors()}
|
|
|
|
|
|
{renderRadiusSlider()}
|
|
|
|
|
|
</ScrollView>
|
|
|
|
|
|
</SafeAreaView>
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export default ChatSettingsScreen;
|