UNPKG

8.53 kBTypeScriptView Raw
1import { ComponentType } from 'react'
2import { StandardProps, CommonEventFunction } from './common'
3interface SwiperProps extends StandardProps {
4 /** 是否显示面板指示点
5 * @default false
6 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony_hybrid
7 */
8 indicatorDots?: boolean
9 /** 指示点颜色
10 * @default "rgba(0, 0, 0, .3)"
11 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony_hybrid
12 */
13 indicatorColor?: string
14 /** 当前选中的指示点颜色
15 * @default "#000000"
16 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony_hybrid
17 */
18 indicatorActiveColor?: string
19 /** 是否自动切换
20 * @default false
21 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony_hybrid
22 */
23 autoplay?: boolean
24 /** 当前所在滑块的 index
25 * @default 0
26 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony_hybrid
27 */
28 current?: number
29 /** 当前所在滑块的 item-id ,不能与 current 被同时指定
30 * @supported swan, tt, qq, jd, h5, harmony_hybrid
31 * @weapp deprecated
32 * @default ""
33 */
34 currentItemId?: string
35 /** 自动切换时间间隔
36 * @default 5000
37 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony_hybrid
38 */
39 interval?: number
40 /** 滑动动画时长
41 * @default 500
42 * @supported weapp, alipay, swan, tt, qq, jd, h5, harmony_hybrid
43 */
44 duration?: number
45 /** 是否采用衔接滑动
46 * @default false
47 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony_hybrid
48 */
49 circular?: boolean
50 /** 滑动方向是否为纵向
51 * @default false
52 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony_hybrid
53 */
54 vertical?: boolean
55 /** 前边距,可用于露出前一项的一小部分,接受 px 和 rpx 值
56 * @default "0px"
57 * @supported weapp, alipay, swan, tt, qq, jd, h5, harmony_hybrid
58 */
59 previousMargin?: string
60 /** 后边距,可用于露出后一项的一小部分,接受 px 和 rpx 值
61 * @default "0px"
62 * @supported weapp, alipay, swan, tt, qq, jd, h5, harmony_hybrid
63 */
64 nextMargin?: string
65 /**
66 * 当 swiper-item 的个数大于等于 2,关闭 circular 并且开启 previous-margin 或 next-margin 的时候,可以指定这个边距是否应用到第一个、最后一个元素
67 * @default false
68 * @supported weapp, alipay
69 */
70 snapToEdge?: boolean
71 /** 同时显示的滑块数量
72 * @default 1
73 * @supported weapp, alipay, swan, tt, qq, jd, h5, harmony_hybrid
74 */
75 displayMultipleItems?: number
76 /** 是否跳过未显示的滑块布局,设为 true 可优化复杂情况下的滑动性能,但会丢失隐藏状态滑块的布局信息
77 * @default false
78 * @supported qq, jd
79 */
80 skipHiddenItemLayout?: boolean
81 /** 指定 swiper 切换缓动动画类型
82 * @default "default"
83 * @supported weapp, alipay, tt, jd
84 */
85 easingFunction?: keyof SwiperProps.TEasingFunction
86 /** 是否禁止用户 touch 操作
87 * @default false
88 * @supported alipay
89 */
90 disableTouch?: boolean
91 /** 是否启用缩放
92 * @default false
93 * @supported h5, harmony_hybrid
94 */
95 zoom?: boolean
96 /** 是否开启全屏
97 * @default false
98 * @supported h5, harmony_hybrid
99 */
100 full?: boolean
101 /** swiper-item 可见时的 class。
102 * @supported alipay
103 */
104 activeClass?: string
105 /** acceleration 设置为 {{true}} 时且处于滑动过程中,中间若干屏处于可见时的 class。
106 * @supported alipay
107 */
108 changingClass?: string
109 /** 当开启时,会根据滑动速度,连续滑动多屏。
110 * @default false
111 * @supported alipay
112 */
113 acceleration?: string
114 /** 是否禁用代码变动触发 swiper 切换时使用动画。
115 * @default false
116 * @supported alipay
117 */
118 disableProgrammaticAnimation?: string
119 /** 滑动距离阈值,当滑动距离超过阈值时进行 swiper-item 切换。
120 * @supported alipay
121 */
122 swipeRatio?: string
123 /** 滑动综合速度阈值,当超过阈值时进行 swiper-item 切换,数值越小越敏感。
124 * @supported alipay
125 */
126 swipeSpeed?: string
127 /** 计算用户手势时所依赖的滑动角度。角度根据 touchstart 事件和首次 touchmove 事件的坐标计算得出。数值越小越对用户的滑动方向准确度要求越高。
128 * @supported alipay
129 */
130 touchAngle?: string
131 /** 自动以指定滑块的高度为整个容器的高度。当 vertical 为 true 时,默认不调整。可选值为:
132 * @supported alipay
133 */
134 adjustHeight?: 'first' | 'current' | 'highest' | 'none'
135 /** vertical 为 true 时强制使 adjust-height 生效。
136 * @supported alipay
137 */
138 adjustVerticalHeight?: string
139 /** 是否停止响应用户 touchmove 操作
140 * @default false
141 * @supported swan
142 */
143 disableTouchmove?: string
144 /** 改变 current 时使用动画过渡
145 * @supported weapp
146 * @default true
147 */
148 scrollWithAnimation?: boolean
149 /** 缓存区域大小,值为 1 表示提前渲染上下各一屏区域(swiper 容器大小)
150 * @supported weapp
151 * @default 0
152 */
153 cacheExtent?: number
154 /** current 改变时会触发 change 事件
155 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony_hybrid
156 */
157 onChange?: CommonEventFunction<SwiperProps.onChangeEventDetail>
158 /** swiper-item 的位置发生改变时会触发 transition 事件
159 * @supported weapp, alipay, tt, qq
160 */
161 onTransition?: CommonEventFunction<SwiperProps.onTransitionEventDetail>
162 /** 动画结束时会触发 animationfinish 事件
163 * @supported weapp, swan, tt, qq, jd, h5, rn, harmony_hybrid
164 */
165 onAnimationFinish?: SwiperProps['onChange']
166 /** 动画结束时会触发 animationEnd 事件
167 * @supported alipay
168 */
169 onAnimationEnd?: CommonEventFunction<SwiperProps.onCommonEventDetail>
170}
171declare namespace SwiperProps {
172 /** 导致变更的原因 */
173 interface TChangeSource {
174 /** 自动播放 */
175 autoplay
176 /** 用户划动 */
177 touch
178 /** 其它原因 */
179 ''
180 }
181 /** 指定 swiper 切换缓动动画类型 */
182 interface TEasingFunction {
183 /** 默认缓动函数 */
184 default
185 /** 线性动画 */
186 linear
187 /** 缓入动画 */
188 easeInCubic
189 /** 缓出动画 */
190 easeOutCubic
191 /** 缓入缓出动画 */
192 easeInOutCubic
193 }
194 interface onCommonEventDetail {
195 /** 当前所在滑块的索引 */
196 current: number
197 /** 导致变更的原因 */
198 source: keyof SwiperProps.TChangeSource
199 }
200 interface onChangeEventDetail {
201 /** 当前所在滑块的索引 */
202 current: number
203 /** 导致变更的原因 */
204 source: keyof SwiperProps.TChangeSource
205 /** SwiperItem的itemId参数值 */
206 currentItemId?: string
207 }
208 interface onTransitionEventDetail {
209 /** X 坐标 */
210 dx: number
211 /** Y 坐标 */
212 dy: number
213 }
214}
215/** 滑块视图容器。其中只可放置 swiper-item 组件,否则会导致未定义的行为。
216 * > 不要为 `SwiperItem` 设置 **style** 属性,可以通过 class 设置样式。[7147](https://github.com/NervJS/taro/issues/7147)
217 * @classification viewContainer
218 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony, harmony_hybrid
219 * @example_react
220 * ```tsx
221 * class App extends Component {
222 * render () {
223 * return (
224 * <Swiper
225 * className='test-h'
226 * indicatorColor='#999'
227 * indicatorActiveColor='#333'
228 * vertical
229 * circular
230 * indicatorDots
231 * autoplay>
232 * <SwiperItem>
233 * <View className='demo-text-1'>1</View>
234 * </SwiperItem>
235 * <SwiperItem>
236 * <View className='demo-text-2'>2</View>
237 * </SwiperItem>
238 * <SwiperItem>
239 * <View className='demo-text-3'>3</View>
240 * </SwiperItem>
241 * </Swiper>
242 * )
243 * }
244 * }
245 * ```
246 * @example_vue
247 * ```html
248 * <template>
249 * <swiper
250 * class='test-h'
251 * indicator-color='#999'
252 * indicator-active-color='#333'
253 * :vertical="true"
254 * :circular="true"
255 * :indicator-dots="true"
256 * :autoplay="true"
257 * >
258 * <swiper-item>
259 * <view class='demo-text-1'>1</view>
260 * </swiper-item>
261 * <swiper-item>
262 * <view class='demo-text-2'>2</view>
263 * </swiper-item>
264 * <swiper-item>
265 * <view class='demo-text-3'>3</view>
266 * </swiper-item>
267 * </swiper>
268 * </template>
269 * ```
270 * @see https://developers.weixin.qq.com/miniprogram/dev/component/swiper.html
271 */
272declare const Swiper: ComponentType<SwiperProps>
273export { Swiper, SwiperProps }