1
- import { bounce , ping , pulse , spin } from 'react-native-css-animations' ;
1
+ import {
2
+ bounce ,
3
+ ping ,
4
+ pulse ,
5
+ shimmer ,
6
+ spin ,
7
+ } from 'react-native-css-animations' ;
2
8
3
- import { SafeAreaView , StyleSheet , Text , View } from 'react-native' ;
9
+ import { Platform , SafeAreaView , StyleSheet , Text , View } from 'react-native' ;
4
10
import { LinearGradient } from 'expo-linear-gradient' ;
5
11
import Animated from 'react-native-reanimated' ;
6
12
import Fontisto from '@expo/vector-icons/Fontisto' ;
@@ -10,15 +16,6 @@ import MaskedView from '@react-native-masked-view/masked-view';
10
16
11
17
const AnimatedLinearGradient = Animated . createAnimatedComponent ( LinearGradient ) ;
12
18
13
- const shimmer = {
14
- from : {
15
- transform : [ { translateX : '-25%' } ] ,
16
- } ,
17
- to : {
18
- transform : [ { translateX : '25%' } ] ,
19
- } ,
20
- } ;
21
-
22
19
export default function App ( ) {
23
20
return (
24
21
< SafeAreaView style = { styles . container } >
@@ -46,45 +43,38 @@ export default function App() {
46
43
</ View >
47
44
48
45
< Text style = { styles . label } > Bounce</ Text >
46
+ { /* Bounce animation ⬇️ */ }
49
47
< Animated . View style = { [ styles . arrow , bounce ] } >
50
48
< Entypo name = "chevron-down" size = { 24 } color = "black" />
51
49
</ Animated . View >
52
50
53
- < Text style = { styles . label } > Skimmer</ Text >
54
- < View style = { styles . shimmerContainer } >
55
- < MaskedView
56
- style = { { height : 48 , width : 48 + 12 + 150 } }
57
- maskElement = {
58
- < View style = { styles . skeletonContainer } >
59
- < Animated . View style = { styles . skeletonAvatar } />
60
- < Animated . View style = { styles . skeletonText } />
61
- </ View >
62
- }
63
- >
64
- < Animated . View
65
- style = { {
66
- flex : 1 ,
67
- width : '300%' ,
68
- marginHorizontal : '-100%' ,
69
- animationName : shimmer ,
70
- animationDuration : '1s' ,
71
- animationIterationCount : 'infinite' ,
72
- animationTimingFunction : 'linear' ,
73
- } }
74
- >
75
- < AnimatedLinearGradient
76
- colors = { [ '#e2e8f0' , '#f8fafc' , '#e2e8f0' ] }
77
- locations = { [ 0.46 , 0.5 , 0.54 ] }
78
- start = { { x : 0 , y : - 5 } }
79
- end = { { x : 1 , y : 5 } }
80
- style = { {
81
- flex : 1 ,
82
- width : '100%' ,
83
- } }
84
- />
85
- </ Animated . View >
86
- </ MaskedView >
87
- </ View >
51
+ { ( Platform . OS === 'ios' || Platform . OS === 'android' ) && (
52
+ < >
53
+ < Text style = { styles . label } > Shimmer</ Text >
54
+ < View style = { styles . shimmerContainer } >
55
+ < MaskedView
56
+ style = { styles . mask }
57
+ maskElement = {
58
+ < View style = { styles . skeletonContainer } >
59
+ < Animated . View style = { styles . skeletonAvatar } />
60
+ < Animated . View style = { styles . skeletonText } />
61
+ </ View >
62
+ }
63
+ >
64
+ { /* Shimmer animation ⬇️ */ }
65
+ < Animated . View style = { [ styles . gradientContainer , shimmer ] } >
66
+ < AnimatedLinearGradient
67
+ colors = { [ '#e2e8f0' , '#f8fafc' , '#e2e8f0' ] }
68
+ locations = { [ 0.46 , 0.5 , 0.54 ] }
69
+ start = { { x : 0 , y : - 5 } }
70
+ end = { { x : 1 , y : 5 } }
71
+ style = { styles . gradient }
72
+ />
73
+ </ Animated . View >
74
+ </ MaskedView >
75
+ </ View >
76
+ </ >
77
+ ) }
88
78
</ SafeAreaView >
89
79
) ;
90
80
}
@@ -172,4 +162,17 @@ const styles = StyleSheet.create({
172
162
alignItems : 'center' ,
173
163
justifyContent : 'center' ,
174
164
} ,
165
+ mask : {
166
+ height : 48 ,
167
+ width : 210 ,
168
+ } ,
169
+ gradientContainer : {
170
+ flex : 1 ,
171
+ width : '300%' ,
172
+ marginHorizontal : '-100%' ,
173
+ } ,
174
+ gradient : {
175
+ flex : 1 ,
176
+ width : '100%' ,
177
+ } ,
175
178
} ) ;
0 commit comments