Skip to content

Commit 13a9360

Browse files
feat(sample): add running indicator (animation overlay) (#3903)
1 parent c3ff79f commit 13a9360

File tree

4 files changed

+378
-3
lines changed

4 files changed

+378
-3
lines changed

samples/react-native/babel.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ module.exports = {
99
},
1010
},
1111
],
12+
'react-native-reanimated/plugin',
1213
],
1314
};

samples/react-native/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"react-native": "0.73.2",
3030
"react-native-gesture-handler": "^2.14.0",
3131
"react-native-macos": "^0.73.0-0",
32+
"react-native-reanimated": "3.8.1",
3233
"react-native-safe-area-context": "4.8.0",
3334
"react-native-screens": "3.29.0",
3435
"react-native-vector-icons": "^10.0.3",

samples/react-native/src/App.tsx

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ import {
55
} from '@react-navigation/native';
66
import { createNativeStackNavigator } from '@react-navigation/native-stack';
77
import { createStackNavigator } from '@react-navigation/stack';
8-
98
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
9+
import Animated, {
10+
Easing,
11+
useAnimatedStyle,
12+
useSharedValue,
13+
withRepeat,
14+
withTiming,
15+
} from 'react-native-reanimated';
1016

1117
// Import the Sentry React Native SDK
1218
import * as Sentry from '@sentry/react-native';
@@ -22,7 +28,7 @@ import { Provider } from 'react-redux';
2228
import { store } from './reduxApp';
2329
import { GestureHandlerRootView } from 'react-native-gesture-handler';
2430
import GesturesTracingScreen from './Screens/GesturesTracingScreen';
25-
import { Platform, StyleSheet } from 'react-native';
31+
import { Platform, StyleSheet, View } from 'react-native';
2632
import { HttpClient } from '@sentry/integrations';
2733
import Ionicons from 'react-native-vector-icons/Ionicons';
2834
import PlaygroundScreen from './Screens/PlaygroundScreen';
@@ -227,14 +233,59 @@ function BottomTabs() {
227233
}}
228234
/>
229235
</Tab.Navigator>
236+
<RunningIndicator />
230237
</NavigationContainer>
231238
);
232239
}
233240

241+
function RunningIndicator() {
242+
if (Platform.OS !== 'android' && Platform.OS !== 'ios') {
243+
return null;
244+
}
245+
246+
return <RotatingBox />;
247+
}
248+
249+
function RotatingBox() {
250+
const sv = useSharedValue<number>(0);
251+
252+
React.useEffect(() => {
253+
sv.value = withRepeat(
254+
withTiming(360, {
255+
duration: 1_000_000,
256+
easing: Easing.linear,
257+
}),
258+
-1,
259+
);
260+
// eslint-disable-next-line react-hooks/exhaustive-deps
261+
}, []);
262+
263+
const animatedStyle = useAnimatedStyle(() => ({
264+
transform: [{ rotate: `${sv.value * 360}deg` }],
265+
}));
266+
267+
return (
268+
<View style={styles.container}>
269+
<Animated.View style={[styles.box, animatedStyle]} />
270+
</View>
271+
);
272+
}
273+
234274
const styles = StyleSheet.create({
235275
wrapper: {
236276
flex: 1,
237277
},
278+
container: {
279+
position: 'absolute',
280+
left: 30,
281+
top: 30,
282+
},
283+
box: {
284+
height: 50,
285+
width: 50,
286+
backgroundColor: '#b58df1',
287+
borderRadius: 5,
288+
},
238289
});
239290

240291
export default Sentry.wrap(BottomTabs);

0 commit comments

Comments
 (0)