Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | 2x 2x 2x 2x 6x 2x 2x 2x 2x 2x 2x 6x 2x 2x 6x 6x | /**
* Scanner 初始欢迎页面
*/
import React, { useEffect, useRef } from 'react';
import { Animated, Easing, ScrollView, TouchableOpacity, View } from 'react-native';
import { LinearGradient } from 'expo-linear-gradient';
import type { EdgeInsets } from 'react-native-safe-area-context';
import { Text, XStack, YStack } from 'tamagui';
import { AppHeader } from '@/src/components/AppHeader';
import { IconSymbol } from '@/src/components/ui/IconSymbol';
import { LottieAnimation } from '@/src/components/LottieAnimation';
import { useThemeColors, useIsDarkMode } from '@/src/hooks/useThemeColors';
interface InitialScreenProps {
insets: EdgeInsets;
onStartScan: () => void;
}
export function InitialScreen({ insets, onStartScan }: InitialScreenProps) {
const colors = useThemeColors();
const isDark = useIsDarkMode();
// 功能步骤数据
const SCAN_STEPS = [
{
icon: 'camera.fill' as const,
title: '拍摄成分表',
desc: '对准猫粮包装上的配料表',
bgColor: isDark ? '#3D2A1F' : colors.primaryLight,
iconColor: colors.primary,
},
{
icon: 'doc.text.viewfinder' as const,
title: '智能识别',
desc: 'AI 自动提取成分信息',
bgColor: isDark ? '#2D1F0A' : colors.warningMuted,
iconColor: colors.warning,
},
{
icon: 'chart.bar.doc.horizontal.fill' as const,
title: '生成报告',
desc: '获得专业的分析结果',
bgColor: isDark ? '#0D2818' : colors.successMuted,
iconColor: colors.success,
},
];
// 动画值
const pulseAnim = useRef(new Animated.Value(1)).current;
const stepAnims = useRef(SCAN_STEPS.map(() => new Animated.Value(0))).current;
// 主图标脉冲动画
useEffect(() => {
const pulse = Animated.loop(
Animated.sequence([
Animated.timing(pulseAnim, {
toValue: 1.05,
duration: 1500,
easing: Easing.inOut(Easing.ease),
useNativeDriver: true,
}),
Animated.timing(pulseAnim, {
toValue: 1,
duration: 1500,
easing: Easing.inOut(Easing.ease),
useNativeDriver: true,
}),
])
);
pulse.start();
return () => pulse.stop();
}, [pulseAnim]);
// 步骤卡片依次进入动画
useEffect(() => {
const animations = stepAnims.map((anim, index) =>
Animated.timing(anim, {
toValue: 1,
duration: 400,
delay: 200 + index * 150,
easing: Easing.out(Easing.back(1.5)),
useNativeDriver: true,
})
);
Animated.stagger(100, animations).start();
}, [stepAnims]);
return (
<YStack flex={1} backgroundColor={colors.background as any}>
{/* Header 区域 */}
<AppHeader title="智能扫描" insets={insets} />
{/* 内容区域 */}
<ScrollView
style={{ flex: 1 }}
showsVerticalScrollIndicator={false}
contentContainerStyle={{
flexGrow: 1,
paddingHorizontal: 20,
paddingTop: 16,
paddingBottom: Math.max(32, insets.bottom + 24),
}}
>
<YStack alignItems="center" gap="$4" maxWidth={400} width="100%" alignSelf="center">
{/* 顶部动画图标区域 */}
<Animated.View
style={{
transform: [{ scale: pulseAnim }],
shadowColor: colors.primary,
shadowOffset: { width: 0, height: 8 },
shadowOpacity: 0.3,
shadowRadius: 16,
elevation: 8,
}}
>
<YStack
width={120}
height={120}
borderRadius={60}
overflow="hidden"
alignItems="center"
justifyContent="center"
>
<LinearGradient
colors={isDark ? ['#3D2A1F', '#2D1F1A'] : [colors.primaryLight, colors.primary]}
start={{ x: 0, y: 0 }}
end={{ x: 1, y: 1 }}
style={{
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
}}
/>
<LottieAnimation
source={require('@/assets/animations/scan_face.json')}
autoPlay
loop
width={80}
height={80}
/>
</YStack>
</Animated.View>
{/* 主标题和描述 */}
<YStack alignItems="center" gap="$2" paddingHorizontal="$2">
<Text
fontSize={26}
fontWeight="900"
textAlign="center"
color={colors.text as any}
letterSpacing={0.5}
>
猫粮成分智能分析
</Text>
<Text
fontSize={14}
color={colors.textSecondary as any}
textAlign="center"
fontWeight="500"
lineHeight={20}
>
拍照即可获得专业的添加剂成分分析报告
</Text>
</YStack>
{/* 功能步骤卡片 */}
<YStack width="100%" gap="$3" marginTop="$2">
{SCAN_STEPS.map((step, index) => {
const translateY = stepAnims[index].interpolate({
inputRange: [0, 1],
outputRange: [30, 0],
});
return (
<Animated.View
key={index}
style={{
opacity: stepAnims[index],
transform: [{ translateY }],
}}
>
<XStack
backgroundColor={colors.cardBackground as any}
borderRadius="$5"
padding="$3.5"
alignItems="center"
gap="$3"
borderWidth={1.5}
borderColor={colors.borderMuted as any}
>
{/* 步骤序号 */}
<YStack
width={28}
height={28}
borderRadius={14}
backgroundColor={colors.primary as any}
alignItems="center"
justifyContent="center"
>
<Text
fontSize={14}
fontWeight="800"
color={(isDark ? colors.background : 'white') as any}
>
{index + 1}
</Text>
</YStack>
{/* 图标 */}
<YStack
width={44}
height={44}
borderRadius={12}
backgroundColor={step.bgColor as any}
alignItems="center"
justifyContent="center"
>
<IconSymbol name={step.icon} size={22} color={step.iconColor} />
</YStack>
{/* 文字内容 */}
<YStack flex={1} gap="$0.5">
<Text fontSize={15} fontWeight="700" color={colors.text as any}>
{step.title}
</Text>
<Text fontSize={12} color={colors.textSecondary as any} fontWeight="500">
{step.desc}
</Text>
</YStack>
{/* 箭头指示 */}
{index < SCAN_STEPS.length - 1 && (
<View
style={{
position: 'absolute',
bottom: -14,
left: '50%',
marginLeft: -8,
zIndex: 1,
}}
>
<IconSymbol name="chevron.down" size={16} color={colors.textTertiary} />
</View>
)}
</XStack>
</Animated.View>
);
})}
</YStack>
{/* 提示信息 */}
<XStack
backgroundColor={colors.selected as any}
borderRadius="$4"
paddingHorizontal="$3"
paddingVertical="$2.5"
alignItems="center"
gap="$2"
width="100%"
borderWidth={1}
borderColor={colors.primaryLight as any}
>
<IconSymbol name="lightbulb.fill" size={18} color={colors.primary} />
<Text fontSize={12} color={colors.textSecondary as any} fontWeight="600" flex={1}>
建议在光线充足的环境下拍摄,确保文字清晰可见
</Text>
</XStack>
{/* 开始按钮 */}
<YStack width="100%" marginTop="$2">
<TouchableOpacity onPress={onStartScan} activeOpacity={0.9} style={{ width: '100%' }}>
<LinearGradient
colors={[colors.primaryLight, colors.primary, colors.primaryDark]}
start={{ x: 0, y: 0 }}
end={{ x: 1, y: 1 }}
style={{
height: 56,
borderRadius: 16,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
gap: 10,
}}
>
<IconSymbol name="camera.viewfinder" size={24} color="white" />
<Text fontSize={17} fontWeight="800" color="white" letterSpacing={0.5}>
开始扫描
</Text>
</LinearGradient>
</TouchableOpacity>
</YStack>
</YStack>
</ScrollView>
</YStack>
);
}
|