MCPcopy Index your code
hub / github.com/callstack/react-native-paper / ActivityIndicator

Function ActivityIndicator

src/components/ActivityIndicator.tsx:57–238  ·  view source on GitHub ↗
({
  animating = true,
  color: indicatorColor,
  hidesWhenStopped = true,
  size: indicatorSize = 'small',
  style,
  theme: themeOverrides,
  ...rest
}: Props)

Source from the content-addressed store, hash-verified

55 * ```
56 */
57const ActivityIndicator = ({
58 animating = true,
59 color: indicatorColor,
60 hidesWhenStopped = true,
61 size: indicatorSize = 'small',
62 style,
63 theme: themeOverrides,
64 ...rest
65}: Props) => {
66 const theme = useInternalTheme(themeOverrides);
67 const { current: timer } = React.useRef<Animated.Value>(
68 new Animated.Value(0)
69 );
70 const { current: fade } = React.useRef<Animated.Value>(
71 new Animated.Value(!animating && hidesWhenStopped ? 0 : 1)
72 );
73
74 const rotation = React.useRef<Animated.CompositeAnimation | undefined>(
75 undefined
76 );
77
78 const {
79 animation: { scale },
80 } = theme;
81
82 const startRotation = React.useCallback(() => {
83 // Show indicator
84 Animated.timing(fade, {
85 duration: 200 * scale,
86 toValue: 1,
87 isInteraction: false,
88 useNativeDriver: true,
89 }).start();
90
91 // Circular animation in loop
92 if (rotation.current) {
93 timer.setValue(0);
94 // $FlowFixMe
95 Animated.loop(rotation.current).start();
96 }
97 }, [scale, fade, timer]);
98
99 const stopRotation = () => {
100 if (rotation.current) {
101 rotation.current.stop();
102 }
103 };
104
105 React.useEffect(() => {
106 if (rotation.current === undefined) {
107 // Circular animation in loop
108 rotation.current = Animated.timing(timer, {
109 duration: DURATION,
110 easing: Easing.linear,
111 // Animated.loop does not work if useNativeDriver is true on web
112 useNativeDriver: Platform.OS !== 'web',
113 toValue: 1,
114 isInteraction: false,

Callers

nothing calls this directly

Calls 2

useInternalThemeFunction · 0.90
stopRotationFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…