From 4fc04ebb9ca9a0764cffdda630c0c6872e2b24b6 Mon Sep 17 00:00:00 2001 From: QQ Date: Sat, 14 Nov 2026 14:13:13 +0800 Subject: [PATCH] Import apps/android/src/screens/bot/popover-menu.tsx --- apps/android/src/screens/bot/popover-menu.tsx | 166 ++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 apps/android/src/screens/bot/popover-menu.tsx diff --git a/apps/android/src/screens/bot/popover-menu.tsx b/apps/android/src/screens/bot/popover-menu.tsx new file mode 100644 index 0000000..104e188 --- /dev/null +++ b/apps/android/src/screens/bot/popover-menu.tsx @@ -0,0 +1,166 @@ +import { useEffect, useRef } from 'react' +import { Animated, Easing, Modal, Pressable, StyleSheet, Text, View } from 'react-native' +import type { LucideIcon } from 'lucide-react-native' +import { useSafeAreaInsets } from 'react-native-safe-area-context' +import { useTheme, type ThemeColors } from '../../ui/theme-context' +import { useThemedStyles } from '../../ui/use-themed-styles' + +export interface BotPopoverAction { + key: string + label: string + icon?: LucideIcon + danger?: boolean + selected?: boolean + disabled?: boolean + onPress: () => void +} + +/** + * Floating iOS-style frosted popover card anchored near a top/bottom corner, + * with a clean borderless row layout and invisible tap-outside backdrop. + */ +export function BotFloatingPopover({ + visible, + actions, + onClose, + anchor = 'top-right', + topOffset = 54, + bottomOffset = 72, +}: { + visible: boolean + actions: BotPopoverAction[] + onClose: () => void + anchor?: 'top-right' | 'top-left' | 'bottom-left' + topOffset?: number + bottomOffset?: number +}) { + const insets = useSafeAreaInsets() + const { colors, scheme } = useTheme() + const styles = useThemedStyles(createPopoverStyles) + const anim = useRef(new Animated.Value(0)).current + + useEffect(() => { + if (!visible) { + anim.setValue(0) + return + } + Animated.timing(anim, { + toValue: 1, + duration: 160, + easing: Easing.out(Easing.cubic), + useNativeDriver: true, + }).start() + }, [anim, visible]) + + if (!visible || actions.length === 0) return null + + const positionStyle = + anchor === 'top-left' + ? { top: insets.top + topOffset, left: 16 } + : anchor === 'bottom-left' + ? { bottom: insets.bottom + bottomOffset, left: 16 } + : { top: insets.top + topOffset, right: 16 } + + const scale = anim.interpolate({ inputRange: [0, 1], outputRange: [0.92, 1] }) + + return ( + + + + + {actions.map(action => { + const Icon = action.icon + const inkColor = action.danger ? colors.danger : colors.ink + return ( + { + onClose() + setTimeout(() => action.onPress(), 32) + }} + style={({ pressed }) => [ + styles.row, + action.selected && styles.rowSelected, + pressed && styles.rowPressed, + action.disabled && styles.rowDisabled, + ]} + > + {Icon && } + + {action.label} + + + ) + })} + + + + ) +} + +const createPopoverStyles = (colors: ThemeColors) => + StyleSheet.create({ + overlay: { + flex: 1, + }, + card: { + position: 'absolute', + minWidth: 224, + maxWidth: 276, + borderRadius: 24, + paddingVertical: 8, + paddingHorizontal: 6, + shadowColor: '#000', + shadowOpacity: 0.14, + shadowRadius: 24, + shadowOffset: { width: 0, height: 10 }, + elevation: 12, + }, + cardLight: { + backgroundColor: 'rgba(255, 255, 255, 0.96)', + borderWidth: StyleSheet.hairlineWidth, + borderColor: 'rgba(0, 0, 0, 0.05)', + }, + cardDark: { + backgroundColor: colors.surface, + borderWidth: StyleSheet.hairlineWidth, + borderColor: colors.border, + }, + row: { + flexDirection: 'row', + alignItems: 'center', + gap: 12, + minHeight: 46, + paddingHorizontal: 14, + paddingVertical: 8, + borderRadius: 16, + }, + rowSelected: { + backgroundColor: colors.primarySoft, + }, + rowPressed: { + backgroundColor: colors.grouped, + }, + rowDisabled: { + opacity: 0.4, + }, + label: { + flex: 1, + fontSize: 16, + fontWeight: '400', + color: colors.ink, + }, + labelDanger: { + color: colors.danger, + }, + })