From f240ecbd2b3e9c887137a170ef62e3ed26552c57 Mon Sep 17 00:00:00 2001 From: QQ Date: Sat, 14 Nov 2026 14:21:50 +0800 Subject: [PATCH] Import apps/android/src/ui/responsive.ts --- apps/android/src/ui/responsive.ts | 44 +++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 apps/android/src/ui/responsive.ts diff --git a/apps/android/src/ui/responsive.ts b/apps/android/src/ui/responsive.ts new file mode 100644 index 0000000..b04bb7b --- /dev/null +++ b/apps/android/src/ui/responsive.ts @@ -0,0 +1,44 @@ +import { useWindowDimensions } from 'react-native' + +/** + * Window heights below this are landscape phones (and other vertically + * constrained windows such as split screen), where bottom sheets and the + * composer compete with the IME for room. + */ +export const COMPACT_WINDOW_HEIGHT = 520 + +/** Reading width cap so chat content does not stretch across landscape tablets. */ +export const CONTENT_MAX_WIDTH = 760 + +/** + * Height a bottom sheet may occupy. Landscape phones use nearly the full + * window because a sheet capped at 70% would clip fixed, non-scrolling + * content (the composer "+" menu and workspace dialogs). + */ +export function modalSheetMaxHeight(windowHeight: number): number { + const ratio = windowHeight < COMPACT_WINDOW_HEIGHT ? 0.92 : 0.7 + return Math.min(windowHeight - 8, Math.max(200, Math.round(windowHeight * ratio))) +} + +export interface ResponsiveLayout { + width: number + height: number + /** True when the screen is wider than it is tall. */ + landscape: boolean + /** True for landscape phones and other short windows. */ + compactHeight: boolean + contentMaxWidth: number + sheetMaxHeight: number +} + +export function useResponsiveLayout(): ResponsiveLayout { + const { width, height } = useWindowDimensions() + return { + width, + height, + landscape: width > height, + compactHeight: height < COMPACT_WINDOW_HEIGHT, + contentMaxWidth: CONTENT_MAX_WIDTH, + sheetMaxHeight: modalSheetMaxHeight(height), + } +}