← Back to blog

Optimizing Animation in Desktop, Web and iOS Apps: A Tutorial

A small pill grows through a trail of outlines into a large card with a photo

Plenty of apps feel disjointed once their features are built: tap a list row and the screen flashes over to a new page; click a card and a dialog pops out of nowhere in the middle of the screen.

The problem is a lack of continuity. Continuity means that when the interface changes state, the element the user clicked morphs into the next state without disappearing or being rebuilt along the way, so people always know where they came from and where they are now.

This approach works for web pages, Electron and Tauri desktop apps, and iOS, Android and Flutter clients. Send the spec broken down below to an AI: it scans your existing codebase first, finds up to 10 abrupt jumps, and waits for you to pick numbers before changing them one at a time.

1. What a continuous transition is

Abrupt jumps in everyday software cluster in the eight kinds of scenes below. Here is how each one behaves as a continuous transition:

Page navigation

The list row's title carries over into the page title, and the original page title shrinks into the back button. As you scroll down, the title tucks into the top bar.

Card expansion

The card expands into the full content and its image stretches into the header image. Pulled down to close, it shrinks back along the same path to where it started.

Mini player

The mini player bar expands into the player page, and the cover, title and buttons each move to their places.

Search field

The search field moves to the top. As you type, matches move up and the other items fade out.

Data chart

The data card expands into a chart, and the small bars in the card carry over into the chart's bars.

Pop-up menu

The menu unfolds from the button where it sits. A new item drops into first place and the rest move down in turn.

Tab switching

The selection pill stretches first, then settles into place.

List reflow

When switching between grid and list, sorting, or adding and removing items, every element moves from its old position to its new one.

2. The six rule modules

With repeated descriptions removed, the whole prompt splits into six modules. Day to day, you can save modules 2 to 6 in your project's rules file and send only module 1 in each conversation, or copy the merged version in section 3 and send it all at once.

1. Scope and process

[Scope and process]
1. Scope: work within the existing codebase, tech stack, components, design tokens and layout. Keep each action's existing function, displayed content and final position, and change only the transition between states. The element being acted on morphs and moves into the next state; it must never disappear and then reappear. Don't borrow demo setups: no phone frames, backdrops, fake data or extra fonts. Never add a third-party dependency or change the routing architecture without asking.
2. Take stock: first read the code for pages, routes, panels, drawers, dialogs, menus and lists. Find the existing animation approach, durations and curves, spring parameters, Reduce Motion handling and the input methods on each platform, and report the results in a few sentences.
3. Diagnose and rank: by how often an action is used, how lost users get and the cost of the change, output a list of at most 10 changes. Each entry includes: the location and triggering platform, the current behavior, the matching pattern letter and the elements that carry over, the motion path with its duration and curve, a value rating, and the scope and risk of the code changes. Put frequent, disorienting and cheap ones first. After the list, stop, ask me which ones to implement and wait for my reply.
4. Implement one at a time: for the selected entries, explain the implementation for the current platform and list the files to change; write code only after I confirm. Change one entry at a time. When it's done, list the files changed and check them item by item against the acceptance checklist.

Tell an AI to rework the animation across a whole site and it tends to install extra third-party libraries, stuff in fake test data or break the routing structure. This module locks the AI inside the existing code, makes it take stock and hand in a report of at most 10 changes, and has it start on each one only after a person picks the numbers and confirms the files to change.

2. Eight continuous transition patterns

[Eight continuous transition patterns]
a. Page navigation: the list row's title carries over into the page title, the row image stretches into the header image, and the previous page's title shrinks into the back button. As the page scrolls, the large title tucks into the top bar, centered in the control row. Going back retraces the same path.
b. Card expansion: the card's own frame, corners and image expand into the content view or dialog; the title stays the same line of text and scales its size; the rest of the content fades in once the card is mostly expanded. Closing or pulling down shrinks it back into the same card in its original position.
c. Mini bar expansion: a mini player bar, floating chat bubble, upload or download pill, or notification bar expands into the full panel, and the cover, title and main button move to their new positions. The panel stays opaque; the page underneath scales to 0.94 and darkens by 30%.
d. Search and filter: the search field moves up into the top bar, the page title leaves, and a Cancel or Close button slides in. As the user types, matching items slide from where they were into the results list and the rest fade out. Opening a command palette on desktop works the same way.
e. Data summary expansion: a data card expands into a chart, a progress ring into a report, a thumbnail into an album. The sparkline becomes the chart's line, the card's small bars carry over into the chart's large bars, labels move into the title position and numbers scale up in proportion; never redraw or swap them.
f. Control opens a panel: when a More button, plus button, dropdown or date field opens its menu or picker, the panel unfolds from the control's own corner. Once it's mostly open, the items inside fade in one after another, 25ms apart, and the highlight slides with the pointer or finger. When items are added, removed or moved, the target item drops into its place and the others shift to make room; nothing jumps.
g. Tab bar switching: top tabs, segmented controls, bottom bars and side navigation share one selection pill. When switching, the pill's leading edge moves first and its trailing edge follows, so it stretches on the way, losing about 15% of its height at its longest, then recovers and settles. Text labels collapse or expand, neighboring items shift to make room, and the new content enters from the side of the selected tab.
h. Layout reflow: when switching grid to list, sorting, swapping, inserting, deleting, expanding or collapsing, every element moves from its old coordinates to its new ones. An element that changes rows leaves from the end of its row and enters at the start of the next one; nothing cuts diagonally across the grid.

This module turns the eight common jumps into concrete element mappings. When the AI scans the code, it matches each case to a through h and knows which line of text scales, which image stretches and how far the page behind shrinks, so you don't have to describe every page in words.

3. Rendering and timing

[Rendering and timing]
1. Single element and properties: the moving subject reuses the same element, or a shared element the framework matches by ID. Measure the start and end rectangles and use only transform to move and scale; never animate width, height, top or margin on elements that trigger page layout.
2. Fade timing: content that exists only at the start fades out within the first 25%–35% of progress; content that exists only at the end fades in once 45%–55% of the movement is done. Text that changes size scales directly; never duplicate the node to crossfade.
3. Layers and corners: an expanding panel stays opaque, and no text underneath may show through. A moving element sits above its neighbors while it moves and returns to its own layer once it lands. Corner radii transition along the product's radius curve, and nested shapes keep even padding and concentric corners.
4. Duration and curve: expanding and collapsing use the fast-start, slow-finish curve cubic-bezier(.32, .72, 0, 1) or the product's existing spring parameters. Phone: full-screen expansion 450–700ms, menus and drawers 350–500ms, selection pill movement 400–450ms. Desktop: two thirds of the phone durations, shorter still when triggered from the keyboard. Movement within one screen uses ease-in-out, and list staggers stay within 20–50ms.
5. Gestures and interruption: while a finger or pointer drags, the view follows 1:1 and the dragged card shrinks to 0.82 along with it; on release it keeps the release velocity and glides to the nearer end. A new action in the middle of an animation takes over from the current frame; never wait for the animation to end, and never lock input.

These parameters solve three common problems in frontend animation:

No dropped frames: changing width, height and margins makes the browser recompute the whole page's layout on every frame. Measure the start and end positions first and use only transform to move and scale, so the GPU does the work and nothing stutters.

No ghosting: when old and new content fade at the same time, they pile up into a blur. Old content leaves in the first third of the movement and new content enters after the halfway point, so the screen stays clean during the transition.

No lockups: clicks are never locked while an animation plays. When a user opens the wrong page and taps back, the animation reverses from where it is, without waiting for the last one to finish.

4. Phone vs. desktop

[Phone vs. desktop]
1. Phone: swipe back, pull-down-to-close gestures and button taps drive the same animation, and every frame stays within the safe area.
2. Desktop: smaller and faster. A card or list row expands into a side panel or dialog, growing from the original card into the target panel; never scale the whole app window. Hovering must never shift the layout. While an animation runs, click targets stay where they were, so repeated clicks land. In split views, animate only inside the pane that changes.
3. Static exemptions: resizing the window and switching responsive breakpoints are not transitions; don't animate them.

Computer screens are big and the mouse travels short distances. Copy the phone's full-screen zoom to the desktop and scaling the whole app window is dizzying, and the animation runs too long. This rule cuts desktop durations by a third, keeps animation inside a sidebar or a local dialog, and turns off the extra animation when someone drags the window edge.

5. Accessibility and acceptance checklist

[Accessibility and acceptance checklist]
1. Reduce Motion: when the user turns on the system's Reduce Motion setting, remove movement and scaling and keep only the state change with a fade of about 150ms.
2. Accessibility support: when a new state opens, focus moves to its title or first control; when it closes, focus returns to the element that triggered it. Screen readers keep their existing announcements.
3. Self-check item by item: the first and last frames match the real resting states, and nothing jumps by a pixel when the moving element hands over to the real one. Test long text, short text, missing images, the first item, the last item, empty lists and scrolled lists. Test rapid repeated clicks, going back mid-animation and gestures cancelled halfway. Check phone and desktop layouts, light and dark mode, Reduce Motion, keyboard use and screen readers. Resting screens look the same as before the change, and all existing tests pass.

A finished animation often has its first or last frame off by a pixel or two, or breaks the layout on a very long title or a missing image. This checklist makes the AI check every change against extreme data, and handle the system Reduce Motion setting and moving keyboard focus as well.

6. Platform implementation

[Platform implementation]
1. Web: after checking versions, prefer the View Transitions API, with view-transition-name on shared elements, covering same-document and cross-document changes; where it isn't supported, fall back to a direct update. Everywhere else, use FLIP: measure the first state, apply the change, measure the last state and transition back with transform. You can reuse Motion's layout and layoutId, Svelte's flip and crossfade, or Vue's TransitionGroup. Routed pages start the transition from the router's navigation hook.
2. iOS: in SwiftUI, shared elements within one view use matchedGeometryEffect; pushes and sheets on iOS 18 and later use navigationTransition(.zoom(sourceID:in:)) with matchedTransitionSource. In UIKit on iOS 18, use preferredTransition = .zoom; custom transitions that gestures can interrupt use UIViewControllerAnimatedTransitioning with UIViewPropertyAnimator.
3. Android: Compose uses SharedTransitionLayout with Modifier.sharedElement and sharedBounds, AnimatedContent, and Modifier.animateItem for list items, with Predictive Back for gesture navigation; the View system uses MaterialContainerTransform and shared element transitions.
4. Flutter: shared elements across routes use Hero, cards that open into pages use OpenContainer from the animations package, and layout reflow uses AnimatedList and implicit animations.
5. Desktop apps: Electron and Tauri follow the web approach, and Tauri must test View Transitions support in the system WebView and keep the fallback; native desktop apps apply the same coordinate measurement and interpolation rules through their platform's native animation APIs.

Each tech stack has its own official shared element API. Naming the standard API stops the AI from hand-writing timers that compute coordinates. When you add this to a project, keep only the entry your project uses.

3. The complete merged prompt

Open a conversation in Claude Code, Cursor, Cindy or T3 Code, then copy and send the whole block below:

# Interface Continuity Animation Spec

## 1. Scope and process
- Scope: work within the existing codebase, tech stack, components, design tokens and layout. Keep each action's existing function, displayed content and final position, and change only the transition between states. The element being acted on morphs and moves into the next state; it must never disappear and then reappear. Don't borrow demo setups: no phone frames, backdrops, fake data or extra fonts. Never add a third-party dependency or change the routing architecture without asking.
- Take stock: first read the code for pages, routes, panels, drawers, dialogs, menus and lists. Find the existing animation approach, durations and curves, spring parameters, Reduce Motion handling and the input methods on each platform, and report the results in a few sentences.
- Diagnose and rank: by how often an action is used, how lost users get and the cost of the change, output a list of at most 10 changes. Each entry includes: the location and triggering platform, the current behavior, the matching pattern letter and the elements that carry over, the motion path with its duration and curve, a value rating, and the scope and risk of the code changes. Put frequent, disorienting and cheap ones first. After the list, stop, ask me which ones to implement and wait for my reply.
- Implement one at a time: for the selected entries, explain the implementation for the current platform and list the files to change; write code only after I confirm. Change one entry at a time. When it's done, list the files changed and check them item by item against section 5.

## 2. Eight continuous transition patterns
- a. Page navigation: the list row's title carries over into the page title, the row image stretches into the header image, and the previous page's title shrinks into the back button. As the page scrolls, the large title tucks into the top bar, centered in the control row. Going back retraces the same path.
- b. Card expansion: the card's own frame, corners and image expand into the content view or dialog; the title stays the same line of text and scales its size; the rest of the content fades in once the card is mostly expanded. Closing or pulling down shrinks it back into the same card in its original position.
- c. Mini bar expansion: a mini player bar, floating chat bubble, upload or download pill, or notification bar expands into the full panel, and the cover, title and main button move to their new positions. The panel stays opaque; the page underneath scales to 0.94 and darkens by 30%.
- d. Search and filter: the search field moves up into the top bar, the page title leaves, and a Cancel or Close button slides in. As the user types, matching items slide from where they were into the results list and the rest fade out. Opening a command palette on desktop works the same way.
- e. Data summary expansion: a data card expands into a chart, a progress ring into a report, a thumbnail into an album. The sparkline becomes the chart's line, the card's small bars carry over into the chart's large bars, labels move into the title position and numbers scale up in proportion; never redraw or swap them.
- f. Control opens a panel: when a More button, plus button, dropdown or date field opens its menu or picker, the panel unfolds from the control's own corner. Once it's mostly open, the items inside fade in one after another, 25ms apart, and the highlight slides with the pointer or finger. When items are added, removed or moved, the target item drops into its place and the others shift to make room; nothing jumps.
- g. Tab bar switching: top tabs, segmented controls, bottom bars and side navigation share one selection pill. When switching, the pill's leading edge moves first and its trailing edge follows, so it stretches on the way, losing about 15% of its height at its longest, then recovers and settles. Text labels collapse or expand, neighboring items shift to make room, and the new content enters from the side of the selected tab.
- h. Layout reflow: when switching grid to list, sorting, swapping, inserting, deleting, expanding or collapsing, every element moves from its old coordinates to its new ones. An element that changes rows leaves from the end of its row and enters at the start of the next one; nothing cuts diagonally across the grid.

## 3. Rendering and timing
- Single element and properties: the moving subject reuses the same element, or a shared element the framework matches by ID. Measure the start and end rectangles and use only transform to move and scale; never animate width, height, top or margin on elements that trigger page layout.
- Fade timing: content that exists only at the start fades out within the first 25%–35% of progress; content that exists only at the end fades in once 45%–55% of the movement is done. Text that changes size scales directly; never duplicate the node to crossfade.
- Layers and corners: an expanding panel stays opaque, and no text underneath may show through. A moving element sits above its neighbors while it moves and returns to its own layer once it lands. Corner radii transition along the product's radius curve, and nested shapes keep even padding and concentric corners.
- Duration and curve: expanding and collapsing use the fast-start, slow-finish curve cubic-bezier(.32, .72, 0, 1) or the product's existing spring parameters. Phone: full-screen expansion 450–700ms, menus and drawers 350–500ms, selection pill movement 400–450ms. Desktop: two thirds of the phone durations, shorter still when triggered from the keyboard. Movement within one screen uses ease-in-out, and list staggers stay within 20–50ms.
- Gestures and interruption: while a finger or pointer drags, the view follows 1:1 and the dragged card shrinks to 0.82 along with it; on release it keeps the release velocity and glides to the nearer end. A new action in the middle of an animation takes over from the current frame; never wait for the animation to end, and never lock input.

## 4. Phone vs. desktop
- Phone: swipe back, pull-down-to-close gestures and button taps drive the same animation, and every frame stays within the safe area.
- Desktop: smaller and faster. A card or list row expands into a side panel or dialog, growing from the original card into the target panel; never scale the whole app window. Hovering must never shift the layout. While an animation runs, click targets stay where they were, so repeated clicks land. In split views, animate only inside the pane that changes.
- Static exemptions: resizing the window and switching responsive breakpoints are not transitions; don't animate them.

## 5. Accessibility and acceptance checklist
- Reduce Motion: when the user turns on the system's Reduce Motion setting, remove movement and scaling and keep only the state change with a fade of about 150ms.
- Accessibility support: when a new state opens, focus moves to its title or first control; when it closes, focus returns to the element that triggered it. Screen readers keep their existing announcements.
- Self-check item by item: the first and last frames match the real resting states, and nothing jumps by a pixel when the moving element hands over to the real one. Test long text, short text, missing images, the first item, the last item, empty lists and scrolled lists. Test rapid repeated clicks, going back mid-animation and gestures cancelled halfway. Check phone and desktop layouts, light and dark mode, Reduce Motion, keyboard use and screen readers. Resting screens look the same as before the change, and all existing tests pass.

## 6. Platform implementation
- Web: after checking versions, prefer the View Transitions API, with view-transition-name on shared elements, covering same-document and cross-document changes; where it isn't supported, fall back to a direct update. Everywhere else, use FLIP: measure the first state, apply the change, measure the last state and transition back with transform. You can reuse Motion's layout and layoutId, Svelte's flip and crossfade, or Vue's TransitionGroup. Routed pages start the transition from the router's navigation hook.
- iOS: in SwiftUI, shared elements within one view use matchedGeometryEffect; pushes and sheets on iOS 18 and later use navigationTransition(.zoom(sourceID:in:)) with matchedTransitionSource. In UIKit on iOS 18, use preferredTransition = .zoom; custom transitions that gestures can interrupt use UIViewControllerAnimatedTransitioning with UIViewPropertyAnimator.
- Android: Compose uses SharedTransitionLayout with Modifier.sharedElement and sharedBounds, AnimatedContent, and Modifier.animateItem for list items, with Predictive Back for gesture navigation; the View system uses MaterialContainerTransform and shared element transitions.
- Flutter: shared elements across routes use Hero, cards that open into pages use OpenContainer from the animations package, and layout reflow uses AnimatedList and implicit animations.
- Desktop apps: Electron and Tauri follow the web approach, and Tauri must test View Transitions support in the system WebView and keep the fallback; native desktop apps apply the same coordinate measurement and interpolation rules through their platform's native animation APIs.

4. Step by step

  1. Send the spec and get the list: start your AI coding tool in the project root, paste the complete merged prompt, and wait for the AI to read the code and output its top 10 changes.
  2. Pick two or three to start: from the high-value, low-cost items at the top, choose 2 or 3 and reply with their numbers. Check the files the AI lists to change, then let it change them one by one.
  3. Run the app and do three checks: after each change, open the interface and test three actions. Drag slowly to check for flicker or jumps where the start and end hand over, tap back halfway through the animation to check it can reverse midway, and turn on the system Reduce Motion setting to check that the movement is off. Once the checks pass, commit the code and move on to the next item.
← Back to blog