Skip to content

Commit 977addb

Browse files
authored
Merge pull request #2322 from didi/feat-swiper-indicator-type
Feat:输出 RN swiper 组件支持 indicator 样式相关属性
2 parents 399d373 + 5e3babf commit 977addb

File tree

1 file changed

+42
-15
lines changed

1 file changed

+42
-15
lines changed

packages/webpack-plugin/lib/runtime/components/react/mpx-swiper.tsx

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import Portal from './mpx-portal'
1111
/**
1212
* ✔ indicator-dots
1313
* ✔ indicator-color
14+
* ✔ indicator-width
15+
* ✔ indicator-height
16+
* ✔ indicator-radius
17+
* ✔ indicator-spacing
18+
* ✔ indicator-margin
1419
* ✔ indicator-active-color
1520
* ✔ autoplay
1621
* ✔ current
@@ -46,6 +51,11 @@ interface SwiperProps {
4651
scale?: boolean
4752
'indicator-dots'?: boolean
4853
'indicator-color'?: string
54+
'indicator-width'?: number
55+
'indicator-height'?: number
56+
'indicator-spacing'?: number
57+
'indicator-radius'?: number
58+
'indicator-margin'?: number
4959
'indicator-active-color'?: string
5060
vertical?: boolean
5161
style: {
@@ -72,23 +82,23 @@ interface SwiperProps {
7282
const styles: { [key: string]: Object } = {
7383
pagination_x: {
7484
position: 'absolute',
75-
bottom: 25,
85+
bottom: 0,
7686
left: 0,
7787
right: 0,
7888
flexDirection: 'row',
7989
flex: 1,
8090
justifyContent: 'center',
81-
alignItems: 'center'
91+
alignItems: 'flex-end'
8292
},
8393
pagination_y: {
8494
position: 'absolute',
85-
right: 15,
95+
right: 0,
8696
top: 0,
8797
bottom: 0,
8898
flexDirection: 'column',
8999
flex: 1,
90100
justifyContent: 'center',
91-
alignItems: 'center'
101+
alignItems: 'flex-end'
92102
},
93103
pagerWrapperx: {
94104
position: 'absolute',
@@ -109,16 +119,6 @@ const styles: { [key: string]: Object } = {
109119
}
110120
}
111121

112-
const dotCommonStyle = {
113-
width: 8,
114-
height: 8,
115-
borderRadius: 4,
116-
marginLeft: 3,
117-
marginRight: 3,
118-
marginTop: 3,
119-
marginBottom: 3,
120-
zIndex: 98
121-
}
122122
const activeDotStyle = {
123123
zIndex: 99
124124
}
@@ -136,6 +136,11 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
136136
const {
137137
'indicator-dots': showPagination,
138138
'indicator-color': dotColor = 'rgba(0, 0, 0, .3)',
139+
'indicator-width': dotWidth = 8,
140+
'indicator-height': dotHeight = 8,
141+
'indicator-radius': dotRadius = 4,
142+
'indicator-spacing': dotSpacing = 4,
143+
'indicator-margin': paginationMargin = 10,
139144
'indicator-active-color': activeDotColor = '#000000',
140145
'enable-var': enableVar = false,
141146
'parent-font-size': parentFontSize,
@@ -151,6 +156,17 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
151156
current: propCurrent = 0,
152157
bindchange
153158
} = props
159+
160+
const dotCommonStyle = {
161+
width: dotWidth,
162+
height: dotHeight,
163+
borderRadius: dotRadius,
164+
marginLeft: dotSpacing,
165+
marginRight: dotSpacing,
166+
marginTop: dotSpacing,
167+
marginBottom: dotSpacing,
168+
zIndex: 98
169+
}
154170
const easeingFunc = props['easing-function'] || 'default'
155171
const easeDuration = props.duration || 500
156172
const horizontal = props.vertical !== undefined ? !props.vertical : true
@@ -252,6 +268,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
252268
'style',
253269
'indicator-dots',
254270
'indicator-color',
271+
'indicator-width',
255272
'indicator-active-color',
256273
'previous-margin',
257274
'vertical',
@@ -294,8 +311,18 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
294311
for (let i = 0; i < children.length; i++) {
295312
dots.push(<View style={[dotCommonStyle, { backgroundColor: unActionColor }]} key={i}></View>)
296313
}
314+
let paginationStyle = styles['pagination_' + dir]
315+
if (paginationMargin) {
316+
paginationStyle = {
317+
...paginationStyle,
318+
marginBottom: paginationMargin,
319+
marginLeft: paginationMargin,
320+
marginRight: paginationMargin,
321+
marginTop: paginationMargin
322+
}
323+
}
297324
return (
298-
<View pointerEvents="none" style={styles['pagination_' + dir]}>
325+
<View pointerEvents="none" style={paginationStyle}>
299326
<View style={[styles['pagerWrapper' + dir]]}>
300327
<Animated.View style={[
301328
dotCommonStyle,

0 commit comments

Comments
 (0)