mirror of
https://github.com/makecindy/cindy.git
synced 2026-12-05 11:51:09 +08:00
深色系统模糊材质比 #121212 页面亮,顶栏和输入框的磨砂在背后没有内容时也显出一条灰带。在同一遮罩内叠一层压暗(edgeBlurShade / edgeBlurShadeLayered),空白处保持页面色,只有内容经过时才看到磨砂;浅色不变。 Assisted-by: Cindy (https://cindy.app) Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>
289 lines
8.9 KiB
TypeScript
289 lines
8.9 KiB
TypeScript
import { useNativeGlassGroupStyle } from "@/platform/chrome/nativeGlassButtonStyle.ios";
|
|
import { NativeChromeBackButton } from "@/platform/chrome/NativeChromeBackButton.ios";
|
|
import { navigationChrome } from "@/theme/tokens";
|
|
import { Host } from "@expo/ui";
|
|
import {
|
|
Button,
|
|
HStack,
|
|
Mask,
|
|
Rectangle,
|
|
RNHostView,
|
|
VStack,
|
|
} from "@expo/ui/swift-ui";
|
|
import { Folder, Monitor, Pin, Smartphone, type LucideIcon } from "lucide-react-native";
|
|
import { Pressable, StyleSheet, View } from "react-native";
|
|
import { Text } from "@/components/AppText";
|
|
import { QuietSyncIndicator } from "@/components/QuietSyncIndicator";
|
|
import { TaskTagDots } from './TaskTags';
|
|
import { useDoubleTap } from './useDoubleTap';
|
|
import {
|
|
accessibilityHint,
|
|
accessibilityElement,
|
|
accessibilityLabel,
|
|
background,
|
|
buttonStyle,
|
|
contentShape,
|
|
disabled,
|
|
frame,
|
|
foregroundStyle,
|
|
labelStyle,
|
|
shapes,
|
|
} from "@expo/ui/swift-ui/modifiers";
|
|
import {
|
|
iconSize,
|
|
iconStroke,
|
|
lineHeight,
|
|
spacing,
|
|
typeScale,
|
|
fontWeight,
|
|
useTheme,
|
|
} from "@/theme";
|
|
import { BlurBackdrop, FLOATING_CHROME_BLUR_INTENSITY } from "./BlurBackdrop";
|
|
import { edgeBlurMask, headerBlurLayers, HEADER_BLUR_LAYER_INTENSITY, type EdgeBlurMask } from "./edgeBlurMask";
|
|
import type {
|
|
SessionHeaderNativeActionsProps,
|
|
SessionHeaderNativeBackProps,
|
|
SessionHeaderNativeTitleProps,
|
|
} from "./SessionHeaderNativeControls";
|
|
|
|
/**
|
|
* A stationary, feathered backdrop: scrolling content passes beneath it.
|
|
* `height` is the chrome area; the blur is solid over most of it and eases out
|
|
* across its content-side edge. Headers use the progressive layers of
|
|
* headerBlurLayers; the composer keeps one layer (see edgeBlurMask).
|
|
*/
|
|
export function SessionHeaderNativeBlur({ height: chromeHeight, edge = 'top', inset = 0, fadeInside }: { height: number; edge?: 'top' | 'bottom'; inset?: number; fadeInside?: number }) {
|
|
const { colors } = useTheme();
|
|
const layers = edge === 'top'
|
|
? headerBlurLayers(chromeHeight, fadeInside).map((mask) => ({ mask, intensity: HEADER_BLUR_LAYER_INTENSITY, shade: colors.edgeBlurShadeLayered }))
|
|
: [{ mask: edgeBlurMask(chromeHeight, edge, fadeInside), intensity: FLOATING_CHROME_BLUR_INTENSITY, shade: colors.edgeBlurShade }];
|
|
return (
|
|
<View
|
|
pointerEvents="none"
|
|
accessibilityElementsHidden
|
|
style={{
|
|
position: "absolute",
|
|
...(edge === 'top' ? { top: inset } : { bottom: inset }),
|
|
left: 0,
|
|
right: 0,
|
|
height: layers[0]!.mask.height,
|
|
zIndex: 9,
|
|
}}
|
|
>
|
|
{layers.map(({ mask, intensity, shade }, index) => <MaskedBlur key={index} mask={mask} intensity={intensity} shade={shade} />)}
|
|
</View>
|
|
);
|
|
}
|
|
|
|
/** `shade` sits on the blur under the same mask, see edgeBlurShade. */
|
|
function MaskedBlur({ mask, intensity, shade }: { mask: EdgeBlurMask; intensity: number; shade: string }) {
|
|
const { mode } = useTheme();
|
|
return (
|
|
<Host colorScheme={mode} ignoreSafeArea="all" style={StyleSheet.absoluteFill}>
|
|
<Mask modifiers={[frame({ maxWidth: Infinity, maxHeight: Infinity })]}>
|
|
<RNHostView>
|
|
<View style={{ flex: 1 }}>
|
|
<BlurBackdrop intensity={intensity} overlayColor={shade} />
|
|
</View>
|
|
</RNHostView>
|
|
<Mask.Content>
|
|
<Rectangle
|
|
modifiers={[
|
|
foregroundStyle({
|
|
type: "linearGradient",
|
|
colors: mask.colors,
|
|
startPoint: mask.startPoint,
|
|
endPoint: mask.endPoint,
|
|
}),
|
|
]}
|
|
/>
|
|
</Mask.Content>
|
|
</Mask>
|
|
</Host>
|
|
);
|
|
}
|
|
|
|
export function SessionHeaderNativeTitle({ title,
|
|
tags,
|
|
onTagsPress,
|
|
onTitleDoubleTap,
|
|
pinned, syncing, syncingImmediately, notice }: SessionHeaderNativeTitleProps) {
|
|
const { colors } = useTheme();
|
|
const handleTitlePress = useDoubleTap(onTitleDoubleTap);
|
|
const style = {
|
|
alignSelf: 'center' as const,
|
|
maxWidth: '100%' as const,
|
|
minHeight: 44,
|
|
justifyContent: "center" as const,
|
|
paddingHorizontal: spacing.xs / 2,
|
|
};
|
|
const label = (
|
|
<Text
|
|
numberOfLines={1}
|
|
accessibilityRole="header"
|
|
style={{
|
|
color: colors.textPrimary,
|
|
fontSize: typeScale.body,
|
|
lineHeight: lineHeight.body,
|
|
fontWeight: fontWeight.semibold,
|
|
textAlign: "center",
|
|
flexShrink: 1,
|
|
minWidth: 0,
|
|
}}
|
|
testID="session.title"
|
|
>
|
|
{title}
|
|
</Text>
|
|
);
|
|
return (
|
|
<View style={{ flex: 1, minWidth: 0, justifyContent: 'center' }}>
|
|
{/* 双击标题改名;不参与读屏焦点,读屏用户从「任务详情」进入重命名。 */}
|
|
<Pressable accessible={false} disabled={!onTitleDoubleTap} onPress={handleTitlePress}
|
|
style={style} testID="session.titleArea">
|
|
{/* The title sits directly on the bar: no capsule material behind it. */}
|
|
<View style={{ flexDirection: "row", minWidth: 0, alignItems: "center", justifyContent: "center", gap: spacing.xs }}>
|
|
{pinned ? <Pin color={colors.textTertiary} size={iconSize.sm} strokeWidth={iconStroke.regular} /> : null}
|
|
{label}
|
|
<TaskTagDots
|
|
tags={tags}
|
|
maxVisible={7}
|
|
surfaceColor={colors.surface}
|
|
onPress={onTagsPress}
|
|
/>
|
|
<QuietSyncIndicator active={syncing} immediate={syncingImmediately} />
|
|
</View>
|
|
{notice ? (
|
|
<Text numberOfLines={1} testID="session.headerNotice"
|
|
style={{ color: colors.textSecondary, fontSize: typeScale.micro, lineHeight: lineHeight.micro, textAlign: "center" }}>
|
|
{notice}
|
|
</Text>
|
|
) : null}
|
|
</Pressable>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
export function SessionHeaderNativeBack({
|
|
label,
|
|
onPress,
|
|
}: SessionHeaderNativeBackProps) {
|
|
return <NativeChromeBackButton label={label} onPress={onPress} testID="session.backButton" />;
|
|
}
|
|
|
|
/** Native SwiftUI buttons share one system capsule. */
|
|
export function SessionHeaderNativeActions({
|
|
available,
|
|
desktopLabel,
|
|
filesLabel,
|
|
moreLabel,
|
|
files,
|
|
onDetails,
|
|
onDesktop,
|
|
onAction,
|
|
detailsOnly = false,
|
|
screen,
|
|
}: SessionHeaderNativeActionsProps) {
|
|
const { colors, mode } = useTheme();
|
|
const groupStyle = useNativeGlassGroupStyle();
|
|
const iconModifiers = [
|
|
labelStyle("iconOnly"),
|
|
buttonStyle("borderless"),
|
|
frame({ width: navigationChrome.target, height: navigationChrome.target }),
|
|
];
|
|
return (
|
|
<Host
|
|
colorScheme={mode}
|
|
seedColor={colors.textPrimary}
|
|
ignoreSafeArea="all"
|
|
style={{ width: navigationChrome.target * (detailsOnly ? 1 : 3), height: navigationChrome.target }}
|
|
>
|
|
<HStack
|
|
spacing={0}
|
|
modifiers={groupStyle}
|
|
>
|
|
{detailsOnly ? null : <>
|
|
<Button
|
|
onPress={onDesktop}
|
|
testID="session.remoteDesktop"
|
|
modifiers={[
|
|
...iconModifiers,
|
|
disabled(!available),
|
|
accessibilityElement("ignore"),
|
|
accessibilityLabel(desktopLabel),
|
|
]}
|
|
>
|
|
<SessionHeaderIcon icon={Monitor} color={colors.textPrimary} />
|
|
</Button>
|
|
{screen ? (
|
|
<Button
|
|
onPress={screen.onPress}
|
|
testID="session.liveScreen"
|
|
modifiers={[
|
|
...iconModifiers,
|
|
disabled(!available),
|
|
accessibilityElement("ignore"),
|
|
accessibilityLabel(screen.label),
|
|
]}
|
|
>
|
|
<SessionHeaderIcon icon={Smartphone} color={colors.textPrimary} />
|
|
</Button>
|
|
) : (
|
|
<Button
|
|
onPress={() => onAction("files")}
|
|
testID="session.filesButton"
|
|
modifiers={[
|
|
...iconModifiers,
|
|
disabled(!available || !files || files.disabled),
|
|
accessibilityElement("ignore"),
|
|
accessibilityLabel(filesLabel),
|
|
accessibilityHint(files?.disabledReason ?? ""),
|
|
]}
|
|
>
|
|
<SessionHeaderIcon icon={Folder} color={colors.textPrimary} />
|
|
</Button>
|
|
)}
|
|
</>}
|
|
<Button
|
|
label={moreLabel}
|
|
systemImage="ellipsis"
|
|
testID="session.controlsToggle"
|
|
onPress={onDetails}
|
|
modifiers={[...iconModifiers, disabled(!available)]}
|
|
/>
|
|
</HStack>
|
|
</Host>
|
|
);
|
|
}
|
|
|
|
/** Keep the existing Lucide artwork inside the native button's 44pt hit area. */
|
|
function SessionHeaderIcon({
|
|
icon: Icon,
|
|
color,
|
|
}: {
|
|
icon: LucideIcon;
|
|
color: string;
|
|
}) {
|
|
return (
|
|
<VStack
|
|
spacing={0}
|
|
modifiers={[
|
|
frame({ width: navigationChrome.target, height: navigationChrome.target }),
|
|
contentShape(shapes.rectangle()),
|
|
]}
|
|
>
|
|
<RNHostView>
|
|
<View
|
|
pointerEvents="none"
|
|
style={{ flex: 1, alignItems: "center", justifyContent: "center" }}
|
|
>
|
|
<Icon
|
|
color={color}
|
|
size={iconSize.action}
|
|
strokeWidth={iconStroke.regular}
|
|
/>
|
|
</View>
|
|
</RNHostView>
|
|
</VStack>
|
|
);
|
|
}
|