Skip to content

Commit 55d02ff

Browse files
M-i-k-e-llidord-wix
authored andcommitted
Fader - move to design tokens (#1954)
* Fader - move to design tokens * Change default to backgroundDefault
1 parent 65d191e commit 55d02ff

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

demo/src/screens/componentScreens/FaderScreen.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class FaderScreen extends Component<WithScrollReachedProps> {
1818
renderItem = (index: number) => {
1919
return (
2020
<View key={index} style={styles.item}>
21-
<Text>{index + 1}</Text>
21+
<Text $textDefault>{index + 1}</Text>
2222
</View>
2323
);
2424
};
@@ -31,7 +31,7 @@ class FaderScreen extends Component<WithScrollReachedProps> {
3131
: !scrollReachedProps.isScrollAtStart;
3232

3333
return (
34-
<View margin-10>
34+
<View padding-10>
3535
{renderHeader('Fader', {'marginB-10': true})}
3636
<View center>
3737
<View style={styles.container}>
@@ -69,8 +69,8 @@ const styles = StyleSheet.create({
6969
item: {
7070
height: itemHeight,
7171
width: itemWidth,
72-
backgroundColor: Colors.grey60,
73-
borderColor: Colors.grey40,
72+
backgroundColor: Colors.$backgroundDefault,
73+
borderColor: Colors.$outlineNeutralMedium,
7474
borderWidth: 2,
7575
alignItems: 'center',
7676
justifyContent: 'center'

src/components/fader/index.tsx

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import _ from 'lodash';
2-
import React, {useCallback} from 'react';
2+
import React, {useMemo} from 'react';
33
import {StyleSheet} from 'react-native';
44
import View from '../view';
55
import Image, {ImageProps} from '../image';
6+
import {Colors} from 'style';
67

78
export enum FaderPosition {
89
/**
@@ -33,7 +34,7 @@ export type FaderProps = Pick<ImageProps, 'supportRTL'> & {
3334
*/
3435
size?: number;
3536
/**
36-
* Change the default (white) tint color of the fade view.
37+
* Change the default tint color of the fade view.
3738
*/
3839
tintColor?: string;
3940
};
@@ -46,38 +47,39 @@ const DEFAULT_FADE_SIZE = 50;
4647
* @gif: https://github.com/wix/react-native-ui-lib/blob/master/demo/showcase/Fader/Fader.gif?raw=true
4748
*/
4849
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;
5256

53-
const fadeSize = getFadeSize();
54-
const getStyles = useCallback(() => {
55-
const position = props.position || FaderPosition.END;
57+
const styles = useMemo(() => {
5658
let containerStyle, imageStyle, imageSource;
5759
switch (position) {
5860
case FaderPosition.LEFT:
5961
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};
6264
imageSource = require('./gradientLeft.png');
6365
break;
6466
case FaderPosition.RIGHT:
6567
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};
6870
imageSource = require('./gradientRight.png');
6971
break;
7072
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%'};
7375
imageSource = require('./gradientTop.png');
7476
break;
7577
case FaderPosition.BOTTOM:
7678
containerStyle = {
7779
...staticStyles.containerBottom,
78-
height: fadeSize
80+
height: size
7981
};
80-
imageStyle = {height: fadeSize, width: '100%'};
82+
imageStyle = {height: size, width: '100%'};
8183
imageSource = require('./gradientBottom.png');
8284
break;
8385
}
@@ -87,17 +89,15 @@ function Fader(props: FaderProps) {
8789
imageStyle,
8890
imageSource
8991
};
90-
}, [fadeSize, props.position]);
91-
92-
const styles = getStyles();
92+
}, [size, position]);
9393

9494
return (
9595
<View pointerEvents={'none'} style={styles.containerStyle}>
96-
{(props.visible || _.isUndefined(props.visible)) && (
96+
{(visible || _.isUndefined(visible)) && (
9797
<Image
9898
supportRTL
9999
source={styles.imageSource}
100-
tintColor={props.tintColor}
100+
tintColor={tintColor}
101101
style={styles.imageStyle}
102102
resizeMode={'stretch'}
103103
/>

0 commit comments

Comments
 (0)