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 | 2x 2x 2x 2x 2x | /**
* DialogHeader - 弹窗头部组件
* 支持两种布局:居中式和左对齐式
*/
import React from 'react';
import { TouchableOpacity } from 'react-native';
import { Text, XStack, YStack } from 'tamagui';
import { IconSymbol, type SymbolName } from '@/src/components/ui/IconSymbol';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import {
DIALOG_COLORS,
BORDER_RADIUS,
SPACING,
FONT_SIZE,
SF_SYMBOLS,
TYPE_COLORS,
} from './constants';
import type { DialogType } from './types';
interface DialogHeaderProps {
title: string;
description?: string;
type?: DialogType;
icon?: string;
sfSymbol?: SymbolName;
layout?: 'center' | 'left';
gradient?: boolean;
onClose?: () => void;
actions?: React.ReactNode;
includeSafeArea?: boolean;
}
export function DialogHeader({
title,
description,
type = 'default',
icon,
sfSymbol,
layout = 'center',
gradient = false,
onClose,
actions,
includeSafeArea = false,
}: DialogHeaderProps) {
const insets = useSafeAreaInsets();
const colors = TYPE_COLORS[type];
const defaultSfSymbol = SF_SYMBOLS[type];
Iif (layout === 'left' && gradient) {
// 左对齐渐变头部(类似 AddPetModal)
return (
<YStack
paddingHorizontal={SPACING.lg}
paddingTop={includeSafeArea ? Math.max(insets.top, SPACING.lg) : SPACING.lg}
paddingBottom={SPACING.xl}
backgroundColor={DIALOG_COLORS.primary}
position="relative"
>
<XStack alignItems="center" gap={SPACING.md} marginBottom={SPACING.xs}>
{/* 图标容器 */}
<YStack
width={56}
height={56}
borderRadius={BORDER_RADIUS.medium}
backgroundColor="rgba(255, 255, 255, 0.25)"
alignItems="center"
justifyContent="center"
>
{icon ? (
<Text fontSize={32}>{icon}</Text>
) : (
<IconSymbol name={sfSymbol || defaultSfSymbol} size={28} color="white" />
)}
</YStack>
{/* 标题和描述 */}
<YStack flex={1}>
<Text fontSize={FONT_SIZE['3xl']} fontWeight="bold" color="white" letterSpacing={0.5}>
{title}
</Text>
{description && (
<Text
fontSize={FONT_SIZE.sm}
color="rgba(255, 255, 255, 0.95)"
marginTop={SPACING.xs}
>
{description}
</Text>
)}
</YStack>
{/* 关闭按钮 */}
{onClose && (
<TouchableOpacity onPress={onClose} activeOpacity={0.7} testID="close-button">
<YStack
width={36}
height={36}
borderRadius={BORDER_RADIUS.medium}
backgroundColor="rgba(255, 255, 255, 0.2)"
alignItems="center"
justifyContent="center"
>
<IconSymbol name="xmark" size={18} color="white" />
</YStack>
</TouchableOpacity>
)}
{/* 自定义操作 */}
{actions}
</XStack>
</YStack>
);
}
// 居中布局(默认)
return (
<YStack
alignItems="center"
gap={SPACING.md}
paddingHorizontal={SPACING.lg}
paddingTop={SPACING.lg}
paddingBottom={SPACING.md}
position="relative"
>
{/* 关闭按钮(右上角) */}
{onClose && (
<TouchableOpacity
onPress={onClose}
activeOpacity={0.7}
testID="close-button"
style={{
position: 'absolute',
top: SPACING.md,
right: SPACING.md,
zIndex: 10,
}}
>
<YStack
width={32}
height={32}
borderRadius={BORDER_RADIUS.full}
backgroundColor={DIALOG_COLORS.neutral[100]}
alignItems="center"
justifyContent="center"
>
<IconSymbol name="xmark" size={16} color={DIALOG_COLORS.neutral[600]} />
</YStack>
</TouchableOpacity>
)}
{/* 图标 */}
<YStack
width={64}
height={64}
borderRadius={BORDER_RADIUS.full}
backgroundColor={colors.bg as any}
alignItems="center"
justifyContent="center"
borderWidth={3}
borderColor={colors.border as any}
>
{icon ? (
<Text fontSize={32}>{icon}</Text>
) : (
<IconSymbol name={sfSymbol || defaultSfSymbol} size={32} color={colors.icon} />
)}
</YStack>
{/* 标题 */}
<Text
fontSize={FONT_SIZE['2xl']}
fontWeight="700"
color={DIALOG_COLORS.text}
textAlign="center"
letterSpacing={0.3}
>
{title}
</Text>
{/* 描述 */}
{description && (
<Text
fontSize={FONT_SIZE.sm}
color={DIALOG_COLORS.textLight}
textAlign="center"
lineHeight={20}
paddingHorizontal={SPACING.md}
>
{description}
</Text>
)}
{/* 自定义操作 */}
{actions && (
<XStack gap={SPACING.sm} marginTop={SPACING.xs}>
{actions}
</XStack>
)}
</YStack>
);
}
|