Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(mobile): clean up forward transition state machine (#3608)
Peter Chinman193d5e2ce995
diff --git a/js/app/packages/app/component/split-layout/SplitLayout.tsx b/js/app/packages/app/component/split-layout/SplitLayout.tsxindex d4ada279ed..18f2880171 100644--- a/js/app/packages/app/component/split-layout/SplitLayout.tsx+++ b/js/app/packages/app/component/split-layout/SplitLayout.tsx@@ -36,7 +36,7 @@ import {createMobileSwipeLayout,type MobileSwipeLayout,} from './mobile/createMobileSwipeLayout';-import { MobileSwipeBackContainer } from './mobile/MobileSwipeBackContainer';+import { MobileSplitContainer } from './mobile/MobileSplitContainer';type SplitLayoutContainerProps = {pairs: string[];@@ -349,7 +349,7 @@ export function SplitLayoutContainer(props: SplitLayoutContainerProps) {}>{/* Mobile: stacked FG/BG layout with swipe-back gesture. */}- <MobileSwipeBackContainer+ <MobileSplitContainersplitManager={splitManager}mobileSwipeLayout={mobileSwipeLayout!}splits={splits}diff --git a/js/app/packages/app/component/split-layout/mobile/MobileSwipeBackContainer.tsx b/js/app/packages/app/component/split-layout/mobile/MobileSplitContainer.tsxsimilarity index 86%rename from js/app/packages/app/component/split-layout/mobile/MobileSwipeBackContainer.tsxrename to js/app/packages/app/component/split-layout/mobile/MobileSplitContainer.tsxindex 2b87bb6153..dda9a0109f 100644--- a/js/app/packages/app/component/split-layout/mobile/MobileSwipeBackContainer.tsx+++ b/js/app/packages/app/component/split-layout/mobile/MobileSplitContainer.tsx@@ -9,19 +9,18 @@ import type {import { createMobileSplitMotion } from './createMobileSplitMotion';import type { MobileSwipeLayout } from './createMobileSwipeLayout';-export type MobileSwipeBackContainerProps = {+export type MobileSplitContainerProps = {splitManager: SplitManager;mobileSwipeLayout: MobileSwipeLayout;splits: Accessor<ReadonlyArray<SplitState>>;panelRefs: Map<SplitId, HTMLDivElement>;};-export function MobileSwipeBackContainer(props: MobileSwipeBackContainerProps) {+export function MobileSplitContainer(props: MobileSplitContainerProps) {const { splitManager, mobileSwipeLayout } = props;const motion = createMobileSplitMotion({mobileSwipeLayout,- panelRefs: props.panelRefs,});const slotDataFor = (slotSplitId: Accessor<SplitId | undefined>) =>@@ -74,11 +73,7 @@ export function MobileSwipeBackContainer(props: MobileSwipeBackContainerProps) {handle={a().handle}active={mobileSwipeLayout.fgIsSlotA()}setPanelRef={(ref) =>- motion.handlePanelRef(- a().split.id,- ref,- mobileSwipeLayout.fgIsSlotA()- )+ props.panelRefs.set(a().split.id, ref)}index={0}/>@@ -106,11 +101,7 @@ export function MobileSwipeBackContainer(props: MobileSwipeBackContainerProps) {handle={b().handle}active={!mobileSwipeLayout.fgIsSlotA()}setPanelRef={(ref) =>- motion.handlePanelRef(- b().split.id,- ref,- !mobileSwipeLayout.fgIsSlotA()- )+ props.panelRefs.set(b().split.id, ref)}index={1}/>diff --git a/js/app/packages/app/component/split-layout/mobile/createMobileForwardAnimation.ts b/js/app/packages/app/component/split-layout/mobile/createMobileForwardAnimation.tsindex 3bf3024eed..7958348b70 100644--- a/js/app/packages/app/component/split-layout/mobile/createMobileForwardAnimation.ts+++ b/js/app/packages/app/component/split-layout/mobile/createMobileForwardAnimation.ts@@ -1,5 +1,4 @@import { batch, createSignal, onCleanup } from 'solid-js';-import type { SplitId } from '../layoutManager';import type { MobileSwipeLayout } from './createMobileSwipeLayout';type ForwardAnimationPhase = 'idle' | 'preparing' | 'animating';@@ -14,7 +13,6 @@ type MobileForwardAnimationOptions = {animationMs: number;bgPeekOffset: number;mobileSwipeLayout: MobileSwipeLayout;- panelRefs: Map<SplitId, HTMLDivElement>;};export function createMobileForwardAnimation(@@ -24,6 +22,7 @@ export function createMobileForwardAnimation(let forwardStartFrame: ReturnType<typeof requestAnimationFrame> | undefined;let forwardSettleFrame: ReturnType<typeof requestAnimationFrame> | undefined;+ let forwardCompletionTimer: ReturnType<typeof setTimeout> | undefined;const cancelFrame = (frame: ReturnType<typeof requestAnimationFrame> | undefined@@ -37,29 +36,14 @@ export function createMobileForwardAnimation(function clearScheduledAnimation() {forwardStartFrame = cancelFrame(forwardStartFrame);forwardSettleFrame = cancelFrame(forwardSettleFrame);+ clearTimeout(forwardCompletionTimer);+ forwardCompletionTimer = undefined;}onCleanup(clearScheduledAnimation);- function incomingSplitId() {- return options.mobileSwipeLayout.fgIsSlotA()- ? options.mobileSwipeLayout.slotBSplitId()- : options.mobileSwipeLayout.slotASplitId();- }-- function incomingPanelIsMounted() {- const splitId = incomingSplitId();- if (!splitId) return false;- return options.panelRefs.get(splitId)?.isConnected === true;- }-- function scheduleAnimationStartIfReady() {- if (phase() !== 'preparing') return;- if (!incomingPanelIsMounted()) return;- scheduleAnimationStart();- }-function scheduleAnimationStart() {+ if (phase() !== 'preparing') return;if (forwardStartFrame !== undefined) return;forwardStartFrame = requestAnimationFrame(() => {forwardStartFrame = undefined;@@ -67,6 +51,7 @@ export function createMobileForwardAnimation(forwardSettleFrame = undefined;if (phase() === 'preparing') {setPhase('animating');+ scheduleAnimationCompletion();}});});@@ -77,30 +62,33 @@ export function createMobileForwardAnimation(clearScheduledAnimation();setPhase('preparing');- scheduleAnimationStartIfReady();+ scheduleAnimationStart();}- function handleTransitionEnd(e: TransitionEvent, isForeground: boolean) {- if (e.target !== e.currentTarget) return;- if (isForeground) return;- if (e.propertyName !== 'transform') return;- if (phase() !== 'animating') return;+ function scheduleAnimationCompletion() {+ clearTimeout(forwardCompletionTimer);+ forwardCompletionTimer = setTimeout(() => {+ if (phase() === 'idle') return;+ completeForwardNavigation();+ }, options.animationMs + 250);+ }+ function completeForwardNavigation() {+ if (phase() === 'idle') return;+ clearScheduledAnimation();batch(() => {setPhase('idle');options.mobileSwipeLayout.completeNavigateForward();});}- function handlePanelRef(- splitId: SplitId,- ref: HTMLDivElement,- isForeground: boolean- ) {- options.panelRefs.set(splitId, ref);- if (!isForeground && splitId === incomingSplitId()) {- scheduleAnimationStartIfReady();- }+ function handleTransitionEnd(e: TransitionEvent, isForeground: boolean) {+ if (e.target !== e.currentTarget) return;+ if (isForeground) return;+ if (e.propertyName !== 'transform') return;+ if (phase() !== 'animating') return;++ completeForwardNavigation();}function incomingStyle(): SplitTransformStyle {@@ -136,7 +124,6 @@ export function createMobileForwardAnimation(phase,trigger,handleTransitionEnd,- handlePanelRef,styleForSlot,};}diff --git a/js/app/packages/app/component/split-layout/mobile/createMobileSplitMotion.ts b/js/app/packages/app/component/split-layout/mobile/createMobileSplitMotion.tsindex 69c9d3dab4..3fa0292bae 100644--- a/js/app/packages/app/component/split-layout/mobile/createMobileSplitMotion.ts+++ b/js/app/packages/app/component/split-layout/mobile/createMobileSplitMotion.ts@@ -1,6 +1,5 @@import { cn } from '@ui';import { onCleanup, onMount } from 'solid-js';-import type { SplitId } from '../layoutManager';import { createMobileForwardAnimation } from './createMobileForwardAnimation';import { createMobileSwipeBackGesture } from './createMobileSwipeBackGesture';import type { MobileSwipeLayout } from './createMobileSwipeLayout';@@ -13,7 +12,6 @@ const BG_PEEK_OFFSET = 110; // px the BG panel is offset left at rest; closes totype MobileSplitMotionOptions = {mobileSwipeLayout: MobileSwipeLayout;- panelRefs: Map<SplitId, HTMLDivElement>;};export function createMobileSplitMotion(options: MobileSplitMotionOptions) {@@ -23,7 +21,6 @@ export function createMobileSplitMotion(options: MobileSplitMotionOptions) {animationMs: SWIPE_ANIMATION_MS,bgPeekOffset: BG_PEEK_OFFSET,mobileSwipeLayout,- panelRefs: options.panelRefs,});const swipeBackGesture = createMobileSwipeBackGesture({animationMs: SWIPE_ANIMATION_MS,@@ -47,7 +44,9 @@ export function createMobileSplitMotion(options: MobileSplitMotionOptions) {mobileSwipeLayout.setForwardNavigationTrigger(undefined);});- const forwardIsActive = () => forwardAnimation.phase() !== 'idle';+ const forwardPhase = forwardAnimation.phase;+ const forwardIsActive = () => forwardPhase() !== 'idle';+ const forwardIsAnimating = () => forwardPhase() === 'animating';function styleForSlot(isForeground: boolean) {if (forwardIsActive()) {@@ -63,7 +62,7 @@ export function createMobileSplitMotion(options: MobileSplitMotionOptions) {'z-10': isForeground && !forwardIsActive(),'z-0 pointer-events-none':(!isForeground && !forwardIsActive()) ||- (isForeground && forwardIsActive()),+ (isForeground && forwardIsAnimating()),'z-user-highlight pointer-events-none':!isForeground && forwardIsActive(),},@@ -78,7 +77,6 @@ export function createMobileSplitMotion(options: MobileSplitMotionOptions) {return {classForSlot,styleForSlot,- handlePanelRef: forwardAnimation.handlePanelRef,handleTransitionEnd: forwardAnimation.handleTransitionEnd,handleTouchStart: swipeBackGesture.handleTouchStart,handleTouchMove: swipeBackGesture.handleTouchMove,diff --git a/js/app/packages/app/component/split-layout/mobile/createMobileSwipeLayout.ts b/js/app/packages/app/component/split-layout/mobile/createMobileSwipeLayout.tsindex 81d79441fe..29ecbb17ae 100644--- a/js/app/packages/app/component/split-layout/mobile/createMobileSwipeLayout.ts+++ b/js/app/packages/app/component/split-layout/mobile/createMobileSwipeLayout.ts@@ -20,13 +20,13 @@ export type MobileSwipeLayout = {* Completes a swipe-back. Flips the FG/BG role so the current BG slot becomes FG* (no remount for the promoted panel), destroys the old FG, and lazily mounts a* new BG from the promoted split's history into the old FG slot.- * Called by MobileSwipeBackContainer after its animation finishes.+ * Called by MobileSplitContainer after its animation finishes.*/completeSwipeBack: () => void;/** Completes a prepared forward navigation after the swipe-in animation. */completeNavigateForward: () => void;/**- * Register an animated trigger provided by MobileSwipeBackContainer.+ * Register an animated trigger provided by MobileSplitContainer.* When set, swipeBack() will animate before completing.*/setAnimatedTrigger: (trigger: (() => void) | undefined) => void;