11import 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' ;
44import NativeLinearGradient from 'react-native-linear-gradient' ;
55import rgb2hex from 'rgb2hex' ;
66
77// const {height, width} = Dimensions.get('window');
88
99class LinearGradient extends Component {
10- render ( ) {
11- const { color0, color1, children, points} = this . props ;
10+ render ( ) {
11+ const { color0, color1, children, points } = this . props ;
1212 const gStart = points . start ;
1313 const gEnd = points . end ;
1414 return (
@@ -24,6 +24,7 @@ class LinearGradient extends Component {
2424 }
2525}
2626Animated . LinearGradient = Animated . createAnimatedComponent ( LinearGradient )
27+ Animated . useNativeDriver = true
2728// Animated.NativeLinearGradient = Animated.createAnimatedComponent(NativeLinearGradient)
2829
2930export const presetColors = {
@@ -59,8 +60,8 @@ class AnimatedGradient extends Component {
5960 customColors : presetColors . instagram ,
6061 speed : 4000 ,
6162 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 }
6465 }
6566 }
6667
@@ -74,8 +75,8 @@ class AnimatedGradient extends Component {
7475 }
7576
7677 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 ;
7980 [ color0 , color1 ] . forEach ( color => color . setValue ( 0 ) ) ;
8081
8182 Animated . parallel (
@@ -91,22 +92,22 @@ class AnimatedGradient extends Component {
9192
9293 } ;
9394
94- render ( ) {
95+ render ( ) {
9596
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 ;
9899 const preferColors = [ ] ;
99100 // while (preferColors.length < customColors.length) {
100101 while ( preferColors . length < 2 ) {
101102 preferColors . push (
102103 customColors
103104 . slice ( preferColors . length )
104- . concat ( customColors . slice ( 0 , preferColors . length + 1 ) )
105+ . concat ( customColors . slice ( 0 , preferColors . length + 1 ) )
105106 )
106107 }
107108 const interpolatedColors = [ color0 , color1 ] . map ( ( animatedColor , index ) => {
108109 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 ) ,
110111 outputRange : preferColors [ index ]
111112 } )
112113 } ) ;
0 commit comments