1
1
import _ from 'lodash' ;
2
- import React , { useCallback } from 'react' ;
2
+ import React , { useMemo } from 'react' ;
3
3
import { StyleSheet } from 'react-native' ;
4
4
import View from '../view' ;
5
5
import Image , { ImageProps } from '../image' ;
6
+ import { Colors } from 'style' ;
6
7
7
8
export enum FaderPosition {
8
9
/**
@@ -33,7 +34,7 @@ export type FaderProps = Pick<ImageProps, 'supportRTL'> & {
33
34
*/
34
35
size ?: number ;
35
36
/**
36
- * Change the default (white) tint color of the fade view.
37
+ * Change the default tint color of the fade view.
37
38
*/
38
39
tintColor ?: string ;
39
40
} ;
@@ -46,38 +47,39 @@ const DEFAULT_FADE_SIZE = 50;
46
47
* @gif : https://github.com/wix/react-native-ui-lib/blob/master/demo/showcase/Fader/Fader.gif?raw=true
47
48
*/
48
49
function Fader ( props : FaderProps ) {
49
- const getFadeSize = useCallback ( ( ) => {
50
- return props . size || DEFAULT_FADE_SIZE ;
51
- } , [ props . size ] ) ;
50
+ const {
51
+ size = DEFAULT_FADE_SIZE ,
52
+ position = FaderPosition . END ,
53
+ visible,
54
+ tintColor = Colors . $backgroundDefault
55
+ } = props ;
52
56
53
- const fadeSize = getFadeSize ( ) ;
54
- const getStyles = useCallback ( ( ) => {
55
- const position = props . position || FaderPosition . END ;
57
+ const styles = useMemo ( ( ) => {
56
58
let containerStyle , imageStyle , imageSource ;
57
59
switch ( position ) {
58
60
case FaderPosition . LEFT :
59
61
case FaderPosition . START :
60
- containerStyle = { ...staticStyles . containerLeft , width : fadeSize } ;
61
- imageStyle = { height : '100%' , width : fadeSize } ;
62
+ containerStyle = { ...staticStyles . containerLeft , width : size } ;
63
+ imageStyle = { height : '100%' , width : size } ;
62
64
imageSource = require ( './gradientLeft.png' ) ;
63
65
break ;
64
66
case FaderPosition . RIGHT :
65
67
case FaderPosition . END :
66
- containerStyle = { ...staticStyles . containerRight , width : fadeSize } ;
67
- imageStyle = { height : '100%' , width : fadeSize } ;
68
+ containerStyle = { ...staticStyles . containerRight , width : size } ;
69
+ imageStyle = { height : '100%' , width : size } ;
68
70
imageSource = require ( './gradientRight.png' ) ;
69
71
break ;
70
72
case FaderPosition . TOP :
71
- containerStyle = { ...staticStyles . containerTop , height : fadeSize } ;
72
- imageStyle = { height : fadeSize , width : '100%' } ;
73
+ containerStyle = { ...staticStyles . containerTop , height : size } ;
74
+ imageStyle = { height : size , width : '100%' } ;
73
75
imageSource = require ( './gradientTop.png' ) ;
74
76
break ;
75
77
case FaderPosition . BOTTOM :
76
78
containerStyle = {
77
79
...staticStyles . containerBottom ,
78
- height : fadeSize
80
+ height : size
79
81
} ;
80
- imageStyle = { height : fadeSize , width : '100%' } ;
82
+ imageStyle = { height : size , width : '100%' } ;
81
83
imageSource = require ( './gradientBottom.png' ) ;
82
84
break ;
83
85
}
@@ -87,17 +89,15 @@ function Fader(props: FaderProps) {
87
89
imageStyle,
88
90
imageSource
89
91
} ;
90
- } , [ fadeSize , props . position ] ) ;
91
-
92
- const styles = getStyles ( ) ;
92
+ } , [ size , position ] ) ;
93
93
94
94
return (
95
95
< View pointerEvents = { 'none' } style = { styles . containerStyle } >
96
- { ( props . visible || _ . isUndefined ( props . visible ) ) && (
96
+ { ( visible || _ . isUndefined ( visible ) ) && (
97
97
< Image
98
98
supportRTL
99
99
source = { styles . imageSource }
100
- tintColor = { props . tintColor }
100
+ tintColor = { tintColor }
101
101
style = { styles . imageStyle }
102
102
resizeMode = { 'stretch' }
103
103
/>
0 commit comments