Slide Animation for Mobile Apps: Step-by-Step Guide
In this article
Slide animation for mobile apps is the transition where a new screen or element enters by moving horizontally or vertically into place, rather than appearing instantly. To implement it, you define the start and end positions, set a duration and easing curve, and apply that animation to the view or navigation transition. The exact steps depend on whether you are using a native framework (SwiftUI, UIKit, Android Views, Jetpack Compose) or a cross-platform tool (Flutter, React Native), but the core process is the same: choose the motion, set the timing, and test on a real device.
What You'll Need
- A mobile development environment: Xcode for iOS, Android Studio for Android, or your cross-platform tool (Flutter SDK, React Native CLI/Expo).
- A basic screen or view to animate (a container, a list item, or a navigation controller).
- A physical device or simulator/emulator for testing.
- Familiarity with your framework's animation APIs (e.g.,
withAnimationin SwiftUI,animate*AsStatein Compose,Animatedin React Native,AnimationControllerin Flutter).
Step-by-Step
- Decide what should slide and from where. A full-screen push usually slides from the right (iOS) or fades/slides up (Android). A bottom sheet slides up from the bottom. A list item can slide in from the side. Write down the start offset (e.g., x = screen width) and the end offset (x = 0).
- Set up the container. In SwiftUI, wrap your content in a
ZStackor useNavigationStackwith a custom transition. In UIKit, use aUIViewPropertyAnimatoror a customUIViewControllerAnimatedTransitioning. In Android Views, useObjectAnimatororTransitionManager. In Jetpack Compose, useAnimatedVisibilitywithslideInHorizontally. In Flutter, useSlideTransitionwith aTween. In React Native, useAnimated.timingon atranslateXvalue. - Define the animation curve and duration. Use a standard easing like
easeInOutorFastOutSlowIn(Material). Duration: 200–300 ms for small elements, 300–400 ms for full-screen transitions. Avoid durations over 500 ms for navigation, as it feels sluggish. - Trigger the animation. For navigation, set the transition on the navigation action (e.g.,
.navigationTransition(.slide)in SwiftUI, oroverridePendingTransitionin Android). For in-place elements, toggle a state variable that drives the offset, and wrap the change in an animation block (e.g.,withAnimation(.easeInOut) { isVisible = true }). - Handle the reverse (exit) animation. When dismissing, animate the offset back to the start value before removing the view. In SwiftUI, use
.transition(.move(edge: .trailing))and ensure the view is removed insidewithAnimation. In Flutter, reverse theAnimationController. In React Native, runAnimated.timingto the original value and then callsetStateto unmount. - Test on a real device. Simulators can hide performance issues. Check for jank (dropped frames) using the platform's performance tools: Xcode Instruments (Core Animation), Android Profiler, Flutter DevTools, or React Native's Performance Monitor. If frames drop, reduce the animated area (animate a transform instead of layout) or use native driver (React Native:
useNativeDriver: true). - Respect reduced motion settings. iOS: check
UIAccessibility.isReduceMotionEnabledand skip or shorten the animation. Android: checkSettings.Global.ANIMATOR_DURATION_SCALEor useAccessibilityManager. Flutter:MediaQuery.of(context).disableAnimations. React Native:AccessibilityInfo.isReduceMotionEnabled(). Provide a crossfade or instant transition as fallback. - Add a completion callback if needed. For chaining animations or cleaning up, use the completion handler (e.g.,
withAnimation(..., completion:)in SwiftUI,addListenerin Flutter,Animated.timing(...).start(({finished}) => ...)in React Native).
Common Mistakes
- Animating layout properties instead of transforms. Changing
width,height,top, orlefttriggers layout passes and causes jank. AnimatetranslationX/Yortransforminstead. - Forgetting to disable the animation on the first render. If you set the offset to the start value and then animate to zero on mount, the view may flash at the start position. Initialize the state to the end value if the view should be visible immediately.
- Using too long a duration. Users perceive delays over 400 ms as slow. Keep navigation slides under 350 ms.
- Ignoring the back gesture. On iOS, the interactive pop gesture may conflict with a custom slide transition. Test edge swipes and ensure your transition doesn't break the system gesture.
- Not testing on low-end devices. A smooth animation on a flagship can stutter on older hardware. Test on a mid-range or older device if possible.
Tips
- Use platform-standard transitions where possible (iOS: horizontal push; Android: shared axis or fade through). Users expect these patterns.
- Keep the slide distance proportional to the screen: a full-screen slide should move the full width; a small element should move a shorter distance.
- Combine slide with a subtle fade for a more polished feel, but avoid over-animating.
- Use
willChangeorshouldRasterizesparingly; modern devices handle transforms well without them. - Profile with the “slow animations” setting (iOS Simulator: Debug > Slow Animations) to inspect timing and easing.
Troubleshooting
- Animation doesn't run: Check that the state change is wrapped in an animation block or that the transition is attached to a view that is being inserted/removed. In SwiftUI, ensure the view is inside a container that supports transitions (e.g.,
ZStackorNavigationStack). - Animation is janky: Switch to animating transforms. In React Native, set
useNativeDriver: truefortranslateX. In Flutter, useSlideTransitionwith aTransformwidget rather than animatingPositioned. - View jumps at the end: The final offset may not match the layout position. Ensure the animated value ends at 0 and the view's natural position is correct. In UIKit, set the final frame before animating.
- Back navigation is broken: If you replaced the default transition, you may need to implement the reverse animation manually or use a navigation library that handles it. On iOS, avoid overriding the interactive pop gesture unless necessary.
- Animation runs on every render: In React Native, avoid creating a new
Animated.Valueon each render; useuseRef. In Flutter, initialize theAnimationControllerininitState.
Frequently Asked Questions
What is the ideal duration for a slide animation?
For navigation transitions, 300–350 ms is typical. For smaller elements, 200–250 ms. Always test with real users and respect reduced motion settings.
Can I use slide animation for a bottom sheet?
Yes, a bottom sheet typically slides up from the bottom. Use the same principles: animate the Y offset from the screen height to 0, with a decelerating curve.
How do I make a slide animation feel natural?
Use platform-standard easing curves (e.g., iOS: easeInOut; Android: FastOutSlowInInterpolator) and keep the distance proportional to the element's size. Avoid linear easing for UI transitions.
Do slide animations affect accessibility?
They can trigger motion sickness. Always check the system's reduce motion setting and provide a crossfade or instant transition as an alternative.
Why does my slide animation stutter on Android?
Likely because you are animating layout properties. Use translationX or translationY instead, and enable hardware acceleration (on by default for most views).
Can I chain multiple slide animations?
Yes, use completion callbacks or animation sequences (e.g., AnimationController.forward().then(...) in Flutter, or Animated.sequence in React Native). Keep total duration under 500 ms to avoid feeling slow.