Skip to content

Commit ab9ddc9

Browse files
committed
overlay labels style
1 parent d09db22 commit ab9ddc9

File tree

3 files changed

+118
-70
lines changed

3 files changed

+118
-70
lines changed

Diff for: README.md

+83-14
Original file line numberDiff line numberDiff line change
@@ -96,35 +96,104 @@ npm install react-native-deck-swiper --save
9696
### Swipe overlay labels
9797
| Props | type | description | default |
9898
|:----------|:--------|:---------------------------------------------------------------------------------------------------------|:----------------------------------|
99-
| overlayLabels| object | swipe labels info | null, see below for format |
99+
| overlayLabels| object | swipe labels title and style | null, see below for format |
100+
| overlayLabelStyle | object | swipe labels style | null, see below for format |
101+
| overlayLabelWrapperStyle | object | overlay label wrapper style | see below for default |
100102

101-
Demo inside the [Exemples Folder](https://github.com/alexbrillant/react-native-deck-swiper/tree/master/Exemples)
103+
### overlayLabelStyle
104+
```javascript
105+
{
106+
fontSize: 45,
107+
fontWeight: 'bold',
108+
borderRadius: 10,
109+
padding: 10,
110+
overflow: 'hidden'
111+
}
112+
```
113+
114+
### overlayLabelWrapperStyle default props:
115+
```javascript
116+
{
117+
position: 'absolute',
118+
backgroundColor: 'transparent',
119+
zIndex: 2,
120+
flex: 1,
121+
width: '100%',
122+
height: '100%'
123+
}
124+
```
125+
126+
### overlayLabels default props :
102127

103128
```javascript
104129
{
105130
bottom: {
106131
title: 'BLEAH',
107-
swipeColor: '#946C8C',
108-
backgroundOpacity: '0.75',
109-
fontColor: '#FFF'
132+
style: {
133+
label: {
134+
backgroundColor: 'black',
135+
borderColor: 'black',
136+
color: 'white',
137+
borderWidth: 1
138+
},
139+
wrapper: {
140+
flexDirection: 'column',
141+
alignItems: 'center',
142+
justifyContent: 'center'
143+
}
144+
}
110145
},
111146
left: {
112147
title: 'NOPE',
113-
swipeColor: '#4A2359',
114-
backgroundOpacity: '0.75',
115-
fontColor: '#FFF'
148+
style: {
149+
label: {
150+
backgroundColor: 'black',
151+
borderColor: 'black',
152+
color: 'white',
153+
borderWidth: 1
154+
},
155+
wrapper: {
156+
flexDirection: 'column',
157+
alignItems: 'flex-end',
158+
justifyContent: 'flex-start',
159+
marginTop: 30,
160+
marginLeft: -30
161+
}
162+
}
116163
},
117164
right: {
118165
title: 'LIKE',
119-
swipeColor: '#FA9F8C',
120-
backgroundOpacity: '0.75',
121-
fontColor: '#FFF'
166+
style: {
167+
label: {
168+
backgroundColor: 'black',
169+
borderColor: 'black',
170+
color: 'white',
171+
borderWidth: 1
172+
},
173+
wrapper: {
174+
flexDirection: 'column',
175+
alignItems: 'flex-start',
176+
justifyContent: 'flex-start',
177+
marginTop: 30,
178+
marginLeft: 30
179+
}
180+
}
122181
},
123182
top: {
124183
title: 'SUPER LIKE',
125-
swipeColor: '#FFC37B',
126-
backgroundOpacity: '0.75',
127-
fontColor: '#FFF'
184+
style: {
185+
label: {
186+
backgroundColor: 'black',
187+
borderColor: 'black',
188+
color: 'white',
189+
borderWidth: 1
190+
},
191+
wrapper: {
192+
flexDirection: 'column',
193+
alignItems: 'center',
194+
justifyContent: 'center'
195+
}
196+
}
128197
}
129198
}
130199
```

Diff for: Swiper.js

+11-56
Original file line numberDiff line numberDiff line change
@@ -458,71 +458,22 @@ class Swiper extends React.Component {
458458
}
459459

460460
calculateOverlayLabelStyle = () => {
461-
let externalStyles = styles.overlayLabel
462-
let dynamicStyles = {}
463-
const labelProps = this.props.overlayLabels[this.state.labelType]
464-
465-
if (labelProps && this.state.labelType !== LABEL_TYPES.NONE) {
466-
dynamicStyles = {
467-
backgroundColor: this.hex2rgba(
468-
labelProps.swipeColor,
469-
labelProps.backgroundOpacity
470-
),
471-
borderColor: labelProps.swipeColor,
472-
color: labelProps.fontColor,
473-
borderWidth: 1
474-
}
475-
} else {
476-
externalStyles = styles.hideOverlayLabel
461+
let overlayLabelStyle = this.props.overlayLabels[this.state.labelType].style.label
462+
463+
if (this.state.labelType === LABEL_TYPES.NONE) {
464+
overlayLabelStyle = styles.hideOverlayLabel
477465
}
478466

479-
return [externalStyles, dynamicStyles]
467+
return [this.props.overlayLabelStyle, overlayLabelStyle]
480468
}
481469

482470
calculateOverlayLabelWrapperStyle = () => {
483-
let dynamicStyles = {}
484-
switch (this.state.labelType) {
485-
case LABEL_TYPES.BOTTOM:
486-
dynamicStyles = {
487-
flexDirection: 'column',
488-
alignItems: 'center',
489-
justifyContent: 'center'
490-
}
491-
break
492-
493-
case LABEL_TYPES.LEFT:
494-
dynamicStyles = {
495-
flexDirection: 'column',
496-
alignItems: 'flex-end',
497-
justifyContent: 'flex-start',
498-
marginTop: 30,
499-
marginLeft: -30
500-
}
501-
break
502-
503-
case LABEL_TYPES.RIGHT:
504-
dynamicStyles = {
505-
flexDirection: 'column',
506-
alignItems: 'flex-start',
507-
justifyContent: 'flex-start',
508-
marginTop: 30,
509-
marginLeft: 30
510-
}
511-
break
512-
513-
case LABEL_TYPES.TOP:
514-
dynamicStyles = {
515-
flexDirection: 'column',
516-
alignItems: 'center',
517-
justifyContent: 'center'
518-
}
519-
break
520-
}
471+
let dynamicStyles = this.props.overlayLabels[this.state.labelType].style.wrapper
521472

522473
const opacity = this.props.animateOverlayLabelsOpacity
523474
? this.interpolateOverlayLabelsOpacity()
524475
: 1
525-
return [styles.overlayLabelWrapper, dynamicStyles, { opacity }]
476+
return [this.props.overlayLabelWrapperStyle, dynamicStyles, { opacity }]
526477
}
527478

528479
calculateSwipableCardStyle = () => {
@@ -789,6 +740,8 @@ Swiper.propTypes = {
789740
outputRotationRange: PropTypes.array,
790741
outputCardOpacityRange: PropTypes.array,
791742
overlayLabels: PropTypes.object,
743+
overlayLabelStyle: PropTypes.object,
744+
overlayLabelWrapperStyle: PropTypes.object,
792745
previousCardInitialPositionX: PropTypes.number,
793746
previousCardInitialPositionY: PropTypes.number,
794747
renderCard: PropTypes.func.isRequired,
@@ -870,6 +823,8 @@ Swiper.defaultProps = {
870823
outputOverlayLabelsOpacityRangeY: [1, 0, 0, 0, 1],
871824
outputRotationRange: ['-10deg', '0deg', '10deg'],
872825
overlayLabels: null,
826+
overlayLabelStyle: styles.overlayLabel,
827+
overlayLabelWrapperStyle: styles.overlayLabelWrapper,
873828
previousCardInitialPositionX: 0,
874829
previousCardInitialPositionY: -height,
875830
secondCardZoom: 0.97,

Diff for: styles.js

+24
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,30 @@ const styles = StyleSheet.create({
3737
borderRadius: 10,
3838
padding: 10,
3939
overflow: 'hidden'
40+
},
41+
bottomOverlayLabelWrapper: {
42+
flexDirection: 'column',
43+
alignItems: 'center',
44+
justifyContent: 'center'
45+
},
46+
topOverlayLabelWrapper: {
47+
flexDirection: 'column',
48+
alignItems: 'center',
49+
justifyContent: 'center'
50+
},
51+
rightOverlayLabelWrapper: {
52+
flexDirection: 'column',
53+
alignItems: 'flex-start',
54+
justifyContent: 'flex-start',
55+
marginTop: 30,
56+
marginLeft: 30
57+
},
58+
leftOverlayLabelWrapper: {
59+
flexDirection: 'column',
60+
alignItems: 'flex-end',
61+
justifyContent: 'flex-start',
62+
marginTop: 30,
63+
marginLeft: -30
4064
}
4165
})
4266

0 commit comments

Comments
 (0)