Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(mobile): safe area improvements (#4372)

Peter Chinman7dfc46ec246d
diff --git a/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx b/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx
index 7ea4ec69ed..4cd24d03a2 100644
--- a/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx
@@ -56,10 +56,7 @@ import {
SplitHeaderRight,
} from '@app/component/split-layout/components/SplitHeader';
import { SplitPanelContext } from '@app/component/split-layout/context';
-import {
- useSplitPanel,
- useSplitPanelOrThrow,
-} from '@app/component/split-layout/layoutUtils';
+import { useSplitPanelOrThrow } from '@app/component/split-layout/layoutUtils';
import { LIST_VIEW_DOCS_URL } from '@app/constants/docs-links';
import { isListViewID, type ListView } from '@app/constants/list-views';
import { DEBUG_SETTING_KEYS, useDebugSetting } from '@app/lib/debugSettings';
@@ -1519,7 +1516,6 @@ interface SoupListProps {
const SoupList = (props: SoupListProps) => {
const [virtualizerHandle, setVirtualizerHandle] =
createSignal<VirtualizerHandle>();
- const splitPanel = useSplitPanel();
const itemSize = createMemo(() => props.itemSize ?? DEFAULT_ITEM_SIZE);
const overscan = createMemo(() => props.overscan ?? DEFAULT_OVERSCAN);
@@ -1528,10 +1524,7 @@ const SoupList = (props: SoupListProps) => {
// Full-frame mobile: rows under-scroll the status bar; this in-scroll
// spacer is their resting inset (safe-top — list views have no header).
- const topInset = () =>
- isMobile()
- ? (topSpacerSize.height ?? splitPanel?.contentOffsetTop() ?? 0)
- : 0;
+ const topInset = () => (isMobile() ? (topSpacerSize.height ?? 0) : 0);
const handleScroll = (offset: number) => {
const handle = virtualizerHandle();
diff --git a/js/app/packages/app/component/split-layout/components/SplitDrawer.tsx b/js/app/packages/app/component/split-layout/components/SplitDrawer.tsx
index 0c125845f2..599412330b 100644
--- a/js/app/packages/app/component/split-layout/components/SplitDrawer.tsx
+++ b/js/app/packages/app/component/split-layout/components/SplitDrawer.tsx
@@ -51,9 +51,11 @@ export function SplitDrawer(
title?: JSX.Element;
}>
) {
- const { panelSize, contentOffsetTop } = useDrawerGroup();
+ const { panelSize } = useDrawerGroup();
+ const splitPanel = useSplitPanel();
const drawerControl = useDrawerControl(props.id);
const isHorizontal = () => props.side === 'left' || props.side === 'right';
+ const contentOffsetTop = () => splitPanel?.contentOffsetTop() ?? 0;
const getConstrainedSize = () => {
const size = isHorizontal() ? panelSize.width : panelSize.height;
@@ -90,9 +92,15 @@ export function SplitDrawer(
const constrainedSize = getConstrainedSize();
if (isHorizontal()) {
- return { width: constrainedSize, top: `${contentOffsetTop()}px` };
+ return {
+ width: constrainedSize,
+ top: `${contentOffsetTop()}px`,
+ };
} else {
- return { height: constrainedSize, top: `${contentOffsetTop()}px` };
+ return {
+ height: constrainedSize,
+ top: `${contentOffsetTop()}px`,
+ };
}
};
diff --git a/js/app/packages/app/component/split-layout/components/SplitDrawerContext.tsx b/js/app/packages/app/component/split-layout/components/SplitDrawerContext.tsx
index abe8e7ff07..30d831c86c 100644
--- a/js/app/packages/app/component/split-layout/components/SplitDrawerContext.tsx
+++ b/js/app/packages/app/component/split-layout/components/SplitDrawerContext.tsx
@@ -16,7 +16,6 @@ interface ISplitDrawerContext {
closeDrawer: (id: string) => boolean;
isDrawerOpen: (id: string) => boolean;
panelSize: NullableSize;
- contentOffsetTop: Accessor<number>;
}
const SplitDrawerContext = createContext<ISplitDrawerContext>();
@@ -24,7 +23,6 @@ const SplitDrawerContext = createContext<ISplitDrawerContext>();
export function SplitDrawerGroup(
props: ParentProps<{
panelSize: NullableSize;
- contentOffsetTop: Accessor<number>;
}>
) {
const [currentDrawer, setCurrentDrawer] = createSignal<string | null>(null);
@@ -63,7 +61,6 @@ export function SplitDrawerGroup(
closeDrawer,
isDrawerOpen,
panelSize: props.panelSize,
- contentOffsetTop: props.contentOffsetTop,
}}
>
{props.children}
diff --git a/js/app/packages/app/component/split-layout/components/SplitPanel.tsx b/js/app/packages/app/component/split-layout/components/SplitPanel.tsx
index 7a4ec05117..96a04b9ad6 100644
--- a/js/app/packages/app/component/split-layout/components/SplitPanel.tsx
+++ b/js/app/packages/app/component/split-layout/components/SplitPanel.tsx
@@ -128,15 +128,11 @@ export function SplitPanel(props: SplitPanelProps) {
onCleanup(() => observer.disconnect());
});
- const offsetTop = createMemo(() => {
- // Full-frame mobile: panels start at the screen edge, so anything that
- // offsets from the panel top (drawers, content insets) must clear the
- // status bar as well as the header.
+ createEffect(() => {
const safeTop = isMobile() ? getSafeAreaInset('top') : 0;
const offset =
safeTop + (headerSize.height ?? 0) + (toolbarSize.height ?? 0);
setContentOffsetTop(offset);
- return offset;
});
function multipleSplits() {
@@ -179,7 +175,7 @@ export function SplitPanel(props: SplitPanelProps) {
panelRef,
}}
>
- <SplitDrawerGroup contentOffsetTop={offsetTop} panelSize={panelSize}>
+ <SplitDrawerGroup panelSize={panelSize}>
<Show when={props.handle.isSpotLight()}>
<div
class="fixed inset-0 w-screen h-screen z-modal-overlay bg-modal-overlay pattern-diagonal-4 pattern-edge-muted"
diff --git a/js/app/packages/app/index.css b/js/app/packages/app/index.css
index 5cea50e6d5..689cc7b76e 100644
--- a/js/app/packages/app/index.css
+++ b/js/app/packages/app/index.css
@@ -54,6 +54,11 @@
@property --c4c { syntax: "<number>"; inherits: true; initial-value: 0; }
@property --c4h { syntax: "<angle>"; inherits: true; initial-value: 14deg; }
+@property --safe-bottom { syntax: "<length>"; inherits: true; initial-value: 0px; }
+@property --safe-right { syntax: "<length>"; inherits: true; initial-value: 0px; }
+@property --safe-left { syntax: "<length>"; inherits: true; initial-value: 0px; }
+@property --safe-top { syntax: "<length>"; inherits: true; initial-value: 0px; }
+
:root {
/* mobile safe areas */
--safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tauri-inset-bottom, 0px));
diff --git a/js/app/packages/core/mobile/safeAreaInsets.ts b/js/app/packages/core/mobile/safeAreaInsets.ts
index 2c13bc7b5f..0d3aad131b 100644
--- a/js/app/packages/core/mobile/safeAreaInsets.ts
+++ b/js/app/packages/core/mobile/safeAreaInsets.ts
@@ -1,31 +1,9 @@
-import { isIOS } from '@solid-primitives/platform';
-
type SafeAreaInsetSide = 'top' | 'right' | 'bottom' | 'left';
-const cache: Record<SafeAreaInsetSide, number | null> = {
- top: null,
- right: null,
- bottom: null,
- left: null,
-};
-
-window.addEventListener('resize', () => {
- cache.top = null;
- cache.right = null;
- cache.bottom = null;
- cache.left = null;
-});
-
export function getSafeAreaInset(side: SafeAreaInsetSide): number {
- if (!isIOS) return 0;
- if (cache[side] !== null) return cache[side];
- const el = document.createElement('div');
- el.style.setProperty(`padding-${side}`, `env(safe-area-inset-${side}, 0px)`);
- document.body.appendChild(el);
- cache[side] =
- Number.parseFloat(
- getComputedStyle(el).getPropertyValue(`padding-${side}`)
- ) || 0;
- el.remove();
- return cache[side];
+ const value = getComputedStyle(document.documentElement).getPropertyValue(
+ `--safe-${side}`
+ );
+ const pixels = Number.parseFloat(value);
+ return Number.isFinite(pixels) ? pixels : 0;
}