Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Slide Animation for Mobile Apps: Step-by-Step Guide

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

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., withAnimation in SwiftUI, animate*AsState in Compose, Animated in React Native, AnimationController in Flutter).

Step-by-Step

  1. 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).
  2. Set up the container. In SwiftUI, wrap your content in a ZStack or use NavigationStack with a custom transition. In UIKit, use a UIViewPropertyAnimator or a custom UIViewControllerAnimatedTransitioning. In Android Views, use ObjectAnimator or TransitionManager. In Jetpack Compose, use AnimatedVisibility with slideInHorizontally. In Flutter, use SlideTransition with a Tween. In React Native, use Animated.timing on a translateX value.
  3. Define the animation curve and duration. Use a standard easing like easeInOut or FastOutSlowIn (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.
  4. Trigger the animation. For navigation, set the transition on the navigation action (e.g., .navigationTransition(.slide) in SwiftUI, or overridePendingTransition in 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 }).
  5. 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 inside withAnimation. In Flutter, reverse the AnimationController. In React Native, run Animated.timing to the original value and then call setState to unmount.
  6. 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).
  7. Respect reduced motion settings. iOS: check UIAccessibility.isReduceMotionEnabled and skip or shorten the animation. Android: check Settings.Global.ANIMATOR_DURATION_SCALE or use AccessibilityManager. Flutter: MediaQuery.of(context).disableAnimations. React Native: AccessibilityInfo.isReduceMotionEnabled(). Provide a crossfade or instant transition as fallback.
  8. Add a completion callback if needed. For chaining animations or cleaning up, use the completion handler (e.g., withAnimation(..., completion:) in SwiftUI, addListener in Flutter, Animated.timing(...).start(({finished}) => ...) in React Native).

Common Mistakes

  • Animating layout properties instead of transforms. Changing width, height, top, or left triggers layout passes and causes jank. Animate translationX/Y or transform instead.
  • 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 willChange or shouldRasterize sparingly; 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., ZStack or NavigationStack).
  • Animation is janky: Switch to animating transforms. In React Native, set useNativeDriver: true for translateX. In Flutter, use SlideTransition with a Transform widget rather than animating Positioned.
  • 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.Value on each render; use useRef. In Flutter, initialize the AnimationController in initState.

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.