diff options
author | Paul Frazee <pfrazee@gmail.com> | 2022-11-15 12:07:41 -0600 |
---|---|---|
committer | Paul Frazee <pfrazee@gmail.com> | 2022-11-15 12:07:41 -0600 |
commit | 4ae6fbd3c8e8be9d47d0bd959aeac380f7bf67ce (patch) | |
tree | 89648c8a9a91ef0f67e49dfa4c5e0a449c7461f4 /src/view/com/util/LoadingPlaceholder.tsx | |
parent | e470e3933b923abfeed4eb8c3bd0cf0b32b0232d (diff) | |
download | voidsky-4ae6fbd3c8e8be9d47d0bd959aeac380f7bf67ce.tar.zst |
Better loading screens
Diffstat (limited to 'src/view/com/util/LoadingPlaceholder.tsx')
-rw-r--r-- | src/view/com/util/LoadingPlaceholder.tsx | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/view/com/util/LoadingPlaceholder.tsx b/src/view/com/util/LoadingPlaceholder.tsx new file mode 100644 index 000000000..55b6ad1b3 --- /dev/null +++ b/src/view/com/util/LoadingPlaceholder.tsx @@ -0,0 +1,73 @@ +import React, {useEffect, useMemo} from 'react' +import { + Animated, + StyleProp, + useWindowDimensions, + View, + ViewStyle, +} from 'react-native' +import LinearGradient from 'react-native-linear-gradient' +import {colors} from '../../lib/styles' + +export function LoadingPlaceholder({ + width, + height, + style, +}: { + width: string | number + height: string | number + style?: StyleProp<ViewStyle> +}) { + const dim = useWindowDimensions() + const elWidth = typeof width === 'string' ? dim.width : width + const offset = useMemo(() => new Animated.Value(elWidth * -1), []) + useEffect(() => { + const anim = Animated.loop( + Animated.sequence([ + Animated.timing(offset, { + toValue: elWidth, + duration: 1e3, + useNativeDriver: true, + isInteraction: false, + }), + Animated.timing(offset, { + toValue: elWidth * -1, + duration: 0, + delay: 500, + useNativeDriver: true, + isInteraction: false, + }), + ]), + ) + anim.start() + return () => anim.stop() + }, []) + + return ( + <View + style={[ + { + width, + height, + backgroundColor: colors.gray2, + borderRadius: 6, + overflow: 'hidden', + }, + style, + ]}> + <Animated.View + style={{ + width, + height, + transform: [{translateX: offset}], + }}> + <LinearGradient + colors={[colors.gray2, '#d4d2d2', colors.gray2]} + start={{x: 0, y: 0}} + end={{x: 1, y: 0}} + style={{width: '100%', height: '100%'}} + /> + </Animated.View> + </View> + ) +} |