From 4651796ee0a0aba72ee306a030b9ce0e39881a1f Mon Sep 17 00:00:00 2001 From: QQ Date: Sat, 14 Nov 2026 14:14:38 +0800 Subject: [PATCH] Import apps/android/src/screens/chat/modal.tsx --- apps/android/src/screens/chat/modal.tsx | 88 +++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 apps/android/src/screens/chat/modal.tsx diff --git a/apps/android/src/screens/chat/modal.tsx b/apps/android/src/screens/chat/modal.tsx new file mode 100644 index 0000000..3f5fb4e --- /dev/null +++ b/apps/android/src/screens/chat/modal.tsx @@ -0,0 +1,88 @@ +import { useEffect, useRef, type ReactNode } from 'react' +import { Animated, Easing, Pressable, StyleSheet, View } from 'react-native' +import { useSafeAreaInsets } from 'react-native-safe-area-context' +import { strings as zhCN } from '../../locales/i18n' +import { easingCurve, resolveMotion } from '../../ui/motion' +import { useResponsiveLayout } from '../../ui/responsive' +import { spacing } from '../../ui/theme' +import { useReduceMotion } from '../../ui/use-reduce-motion' +import { useThemedStyles } from '../../ui/use-themed-styles' +import { createStyles } from './styles' + +/** + * Keep the dismiss target behind the sheet instead of nesting Pressables. + * Android's responder negotiation can otherwise let the backdrop consume a + * child press, which makes every option in a transparent modal look inert. + * + * The sheet follows the live window height: nearly full-height in landscape + * phones, ~70% otherwise. Content that is taller than the sheet must scroll + * (pickers use `usePickerListMaxHeight`). + * + * Sheets that own their `` should use `ui/sheet.tsx`'s `SheetModal`, + * which also animates the exit. This surface animates on mount only, for + * callers that keep a native modal wrapper. + */ +export function ModalSurface({ onClose, children }: { onClose: () => void; children: ReactNode }) { + const styles = useThemedStyles(createStyles) + const insets = useSafeAreaInsets() + const { sheetMaxHeight } = useResponsiveLayout() + const reduceMotion = useReduceMotion() + const progress = useRef(new Animated.Value(0)).current + + useEffect(() => { + const motion = resolveMotion('sheet', reduceMotion) + const animation = Animated.timing(progress, { + toValue: 1, + duration: motion.duration, + easing: Easing.bezier(...easingCurve('expand')), + useNativeDriver: true, + }) + animation.start() + return () => animation.stop() + }, [progress, reduceMotion]) + + const translateY = progress.interpolate({ + inputRange: [0, 1], + outputRange: [resolveMotion('sheet', reduceMotion).translate, 0], + }) + + return ( + + + + {children} + + + ) +} + +/** + * Height a picker list may use inside a `ModalSurface`. The sheet header, + * margins and padding take ~120dp, so the list is capped by what remains of + * the sheet instead of a separate screen-height ratio (which clipped content + * in landscape). + */ +export function usePickerListMaxHeight(): number { + const { sheetMaxHeight } = useResponsiveLayout() + return Math.max(140, sheetMaxHeight - 120) +}