1
1
import PropTypes from 'prop-types' ;
2
- import React , { Component } from 'react' ;
3
- import { StyleSheet , StatusBar , Dimensions , View , Animated , Easing } from 'react-native' ;
2
+ import React , { Component } from 'react' ;
3
+ import { StyleSheet , StatusBar , Dimensions , View , Animated , Easing } from 'react-native' ;
4
4
import NativeLinearGradient from 'react-native-linear-gradient' ;
5
5
import rgb2hex from 'rgb2hex' ;
6
6
7
7
// const {height, width} = Dimensions.get('window');
8
8
9
9
class LinearGradient extends Component {
10
- render ( ) {
11
- const { color0, color1, children, points} = this . props ;
10
+ render ( ) {
11
+ const { color0, color1, children, points } = this . props ;
12
12
const gStart = points . start ;
13
13
const gEnd = points . end ;
14
14
return (
@@ -24,6 +24,7 @@ class LinearGradient extends Component {
24
24
}
25
25
}
26
26
Animated . LinearGradient = Animated . createAnimatedComponent ( LinearGradient )
27
+ Animated . useNativeDriver = true
27
28
// Animated.NativeLinearGradient = Animated.createAnimatedComponent(NativeLinearGradient)
28
29
29
30
export const presetColors = {
@@ -59,8 +60,8 @@ class AnimatedGradient extends Component {
59
60
customColors : presetColors . instagram ,
60
61
speed : 4000 ,
61
62
points : {
62
- start : { x : 0 , y : 0.4 } ,
63
- end : { x : 1 , y : 0.6 }
63
+ start : { x : 0 , y : 0.4 } ,
64
+ end : { x : 1 , y : 0.6 }
64
65
}
65
66
}
66
67
@@ -74,8 +75,8 @@ class AnimatedGradient extends Component {
74
75
}
75
76
76
77
startAnimation = ( ) => {
77
- const { color0, color1} = this . state ;
78
- const { customColors, speed} = this . props ;
78
+ const { color0, color1 } = this . state ;
79
+ const { customColors, speed } = this . props ;
79
80
[ color0 , color1 ] . forEach ( color => color . setValue ( 0 ) ) ;
80
81
81
82
Animated . parallel (
@@ -91,22 +92,22 @@ class AnimatedGradient extends Component {
91
92
92
93
} ;
93
94
94
- render ( ) {
95
+ render ( ) {
95
96
96
- const { color0, color1} = this . state ;
97
- const { customColors, children, points, style} = this . props ;
97
+ const { color0, color1 } = this . state ;
98
+ const { customColors, children, points, style } = this . props ;
98
99
const preferColors = [ ] ;
99
100
// while (preferColors.length < customColors.length) {
100
101
while ( preferColors . length < 2 ) {
101
102
preferColors . push (
102
103
customColors
103
104
. slice ( preferColors . length )
104
- . concat ( customColors . slice ( 0 , preferColors . length + 1 ) )
105
+ . concat ( customColors . slice ( 0 , preferColors . length + 1 ) )
105
106
)
106
107
}
107
108
const interpolatedColors = [ color0 , color1 ] . map ( ( animatedColor , index ) => {
108
109
return animatedColor . interpolate ( {
109
- inputRange : Array . from ( { length : customColors . length + 1 } , ( v , k ) => k ) ,
110
+ inputRange : Array . from ( { length : customColors . length + 1 } , ( v , k ) => k ) ,
110
111
outputRange : preferColors [ index ]
111
112
} )
112
113
} ) ;
0 commit comments