$ git show button-loading

Loading button

Intermediate/anim button-loading

On tap the button shrinks into a circle with a spinner, then grows back when the work is done.

Main · New Architecture only · worklets live in react-native-worklets
transitionPropertyFadeIn / FadeOutCSS transitions
button-loading.tsx · reanimated 4
// Reanimated 4: CSS transitions on the loading state, layout animations for the spinner
const [loading, setLoading] = useState(false);

const submit = async () => {
  setLoading(true);
  await pay();
  setLoading(false);
};

<Pressable onPress={submit} disabled={loading}>
  {/* styles.button: height 52, borderRadius 26, overflow 'hidden', centered content */}
  <Animated.View style={[styles.button, {
    width: loading ? 52 : 220,
    transitionProperty: 'width',
    transitionDuration: '300ms',
    transitionTimingFunction: 'ease-in-out',
  }]}>
    <Animated.Text
      numberOfLines={1}
      style={[styles.label, { opacity: loading ? 0 : 1, transitionProperty: 'opacity', transitionDuration: '150ms' }]}>
      Pay now
    </Animated.Text>
    {loading && (
      <Animated.View entering={FadeIn.delay(200)} exiting={FadeOut.duration(100)} style={[StyleSheet.absoluteFill, styles.center]}>
        <ActivityIndicator color="white" />
      </Animated.View>
    )}
  </Animated.View>
</Pressable>