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 | 5x 5x 5x 2x 3x 1x 2x | /**
* 空状态组件 - 根据情况显示不同空状态
*/
import { Pressable } from 'react-native';
import { Text, XStack, YStack } from 'tamagui';
import { IconSymbol } from '@/src/components/ui/IconSymbol';
import { useThemeColors, useIsDarkMode } from '@/src/hooks/useThemeColors';
interface EmptyStateProps {
type: 'search' | 'complete' | 'default';
searchQuery?: string;
onReset?: () => void;
onRefresh?: () => void;
}
export function EmptyState({ type, onReset, onRefresh }: EmptyStateProps) {
const colors = useThemeColors();
const isDark = useIsDarkMode();
// 搜索结果为空
if (type === 'search') {
return (
<YStack
flex={1}
alignItems="center"
justifyContent="center"
padding="$8"
minHeight={400}
backgroundColor={colors.background as any}
>
<YStack
width={140}
height={140}
borderRadius="$12"
backgroundColor={(isDark ? '#3D2A1F' : colors.primaryLight) as any}
alignItems="center"
justifyContent="center"
marginBottom="$5"
borderWidth={3}
borderColor={(isDark ? '#4D3A2F' : colors.primaryLight) as any}
>
<IconSymbol name="magnifyingglass" size={64} color={colors.primary} />
</YStack>
<Text
fontSize={24}
fontWeight="900"
color={colors.text as any}
marginBottom="$2.5"
letterSpacing={0.5}
>
未找到相关猫粮
</Text>
<Text
fontSize={15}
color={colors.textSecondary as any}
textAlign="center"
lineHeight={24}
marginBottom="$5"
fontWeight="500"
>
试试搜索其他品牌或关键词
</Text>
<Pressable onPress={onReset}>
<XStack
paddingHorizontal="$5"
paddingVertical="$3.5"
borderRadius="$12"
backgroundColor={colors.primary as any}
gap="$2.5"
alignItems="center"
borderWidth={2}
borderColor={colors.primaryDark as any}
>
<IconSymbol name="arrow.counterclockwise" size={18} color="white" />
<Text fontSize={16} color="white" fontWeight="800" letterSpacing={0.3}>
重置筛选
</Text>
</XStack>
</Pressable>
</YStack>
);
}
// 列表为空但有轮播图
if (type === 'complete') {
return (
<YStack
flex={1}
alignItems="center"
justifyContent="center"
padding="$8"
minHeight={300}
backgroundColor={colors.background as any}
>
<YStack
width={120}
height={120}
borderRadius="$12"
backgroundColor={(isDark ? '#0D2818' : colors.successMuted) as any}
alignItems="center"
justifyContent="center"
marginBottom="$4"
borderWidth={3}
borderColor={(isDark ? '#143D20' : colors.successMuted) as any}
>
<IconSymbol name="checkmark.circle.fill" size={64} color={colors.success} />
</YStack>
<Text
fontSize={22}
fontWeight="900"
color={colors.text as any}
marginBottom="$2.5"
letterSpacing={0.5}
>
已显示全部猫粮
</Text>
<Text
fontSize={15}
color={colors.textSecondary as any}
textAlign="center"
lineHeight={24}
fontWeight="500"
>
以上是为您精选的热门推荐
</Text>
</YStack>
);
}
// 原始空状态
return (
<YStack
flex={1}
alignItems="center"
justifyContent="center"
padding="$8"
minHeight={400}
backgroundColor={colors.background as any}
>
<YStack
width={140}
height={140}
borderRadius="$12"
backgroundColor={colors.backgroundMuted as any}
alignItems="center"
justifyContent="center"
marginBottom="$5"
borderWidth={3}
borderColor={colors.border as any}
>
<IconSymbol name="tray.fill" size={64} color={colors.textTertiary} />
</YStack>
<Text
fontSize={24}
fontWeight="900"
color={colors.text as any}
marginBottom="$2.5"
letterSpacing={0.5}
>
暂无猫粮数据
</Text>
<Text
fontSize={15}
color={colors.textSecondary as any}
textAlign="center"
lineHeight={24}
marginBottom="$5"
fontWeight="500"
>
还没有猫粮信息,敬请期待
</Text>
<Pressable onPress={onRefresh}>
<XStack
paddingHorizontal="$5"
paddingVertical="$3.5"
borderRadius="$12"
backgroundColor={colors.primary as any}
gap="$2.5"
alignItems="center"
borderWidth={2}
borderColor={colors.primaryDark as any}
>
<IconSymbol name="arrow.clockwise" size={18} color="white" />
<Text fontSize={16} color="white" fontWeight="800" letterSpacing={0.3}>
刷新页面
</Text>
</XStack>
</Pressable>
</YStack>
);
}
|