~/swaraj.dev
Back to all posts
March 24, 20261 min read

Smooth UI Transitions with InteractionManager in React Native

Delay heavy work until after animations finish by using InteractionManager, keeping the UI buttery smooth on both iOS and Android.

react-nativeperformanceinteractionmanager

Insight

When a screen change triggers a heavy computation—such as parsing a large JSON payload or pre‑loading images—the UI can stutter because the JavaScript thread is busy during the transition animation. InteractionManager lets you schedule work after all ongoing interactions (animations, gestures) have settled, freeing the UI thread for a fluid experience.

Example

import { InteractionManager, useEffect, useState } from 'react';
import { View, Text, ActivityIndicator } from 'react-native';

export default function DetailScreen({ route }) {
  const [data, setData] = useState(null);

  useEffect(() => {
    // Run heavy parsing after the navigation animation completes
    const task = InteractionManager.runAfterInteractions(() => {
      const parsed = JSON.parse(route.params.rawJson);
      setData(parsed);
    });
    return () => task.cancel();
  }, [route.params.rawJson]);

  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      {data ? <Text>{data.title}</Text> : <ActivityIndicator />}
    </View>
  );
}

Takeaway

Wrap any non‑essential, CPU‑intensive logic in InteractionManager.runAfterInteractions to keep navigation animations buttery smooth. Remember to cancel the task on unmount to avoid memory leaks.