1 | import { ComponentType } from 'react'
|
2 | import { StandardProps, CommonEventFunction, TouchEventFunction } from './common'
|
3 | interface MovableViewProps extends Omit<StandardProps, 'animation'> {
|
4 | /** movable-view 的移动方向,属性值有`all`、`vertical`、`horizontal`、`none`
|
5 | * @default none
|
6 | * @supported weapp, alipay, swan, tt, qq, h5, rn
|
7 | */
|
8 | direction?: 'all' | 'vertical' | 'horizontal' | 'none'
|
9 |
|
10 | /** movable-view 是否带有惯性
|
11 | * @default false
|
12 | * @supported weapp, alipay, swan, tt, qq, h5
|
13 | */
|
14 | inertia?: boolean
|
15 |
|
16 | /** 超过可移动区域后,movable-view 是否还可以移动
|
17 | * @default false
|
18 | * @supported weapp, alipay, swan, tt, qq, h5
|
19 | */
|
20 | outOfBounds?: boolean
|
21 |
|
22 | /** 定义 x 轴方向的偏移,如果 x 的值不在可移动范围内,会自动移动到可移动范围;改变 x 的值会触发动画
|
23 | * @supported weapp, alipay, swan, tt, qq, h5, rn
|
24 | */
|
25 | x?: number | string
|
26 |
|
27 | /** 定义 y 轴方向的偏移,如果 y 的值不在可移动范围内,会自动移动到可移动范围;改变 y 的值会触发动画
|
28 | * @supported weapp, alipay, swan, tt, qq, h5, rn
|
29 | */
|
30 | y?: number | string
|
31 |
|
32 | /** 阻尼系数,用于控制x或y改变时的动画和过界回弹的动画,值越大移动越快
|
33 | * @default 20
|
34 | * @supported weapp, alipay, swan, tt, qq, h5
|
35 | */
|
36 | damping?: number
|
37 |
|
38 | /** 摩擦系数,用于控制惯性滑动的动画,值越大摩擦力越大,滑动越快停止;必须大于 0,否则会被设置成默认值
|
39 | * @default 2
|
40 | * @supported weapp, alipay, swan, tt, qq, h5
|
41 | */
|
42 | friction?: number
|
43 |
|
44 | /** 是否禁用
|
45 | * @default false
|
46 | * @supported weapp, alipay, swan, tt, qq, h5, rn
|
47 | */
|
48 | disabled?: boolean
|
49 |
|
50 | /** 是否支持双指缩放,默认缩放手势生效区域是在 movable-view 内
|
51 | * @default false
|
52 | * @supported weapp, alipay, swan, tt, qq, h5
|
53 | */
|
54 | scale?: boolean
|
55 |
|
56 | /** 定义缩放倍数最小值
|
57 | * @default 0.5
|
58 | * @supported weapp, alipay, swan, tt, qq, h5
|
59 | */
|
60 | scaleMin?: number
|
61 |
|
62 | /** 定义缩放倍数最大值
|
63 | * @default 10
|
64 | * @supported weapp, alipay, swan, tt, qq, h5
|
65 | */
|
66 | scaleMax?: number
|
67 |
|
68 | /** 定义缩放倍数,取值范围为 0.5 - 10
|
69 | * @default 1
|
70 | * @supported weapp, alipay, swan, tt, qq, h5
|
71 | */
|
72 | scaleValue?: number
|
73 |
|
74 | /** 是否使用动画
|
75 | * @default true
|
76 | * @supported weapp, alipay, swan, tt, qq, h5
|
77 | */
|
78 | animation?: boolean
|
79 |
|
80 | /** 拖动过程中触发的事件
|
81 | * @supported weapp, alipay, swan, tt, qq
|
82 | */
|
83 | onChange?: CommonEventFunction<MovableViewProps.onChangeEventDetail>
|
84 |
|
85 | /** 拖动结束触发的事件
|
86 | * @supported alipay
|
87 | */
|
88 | onChangeEnd?: CommonEventFunction<MovableViewProps.onChangeEventDetail>
|
89 |
|
90 | /** 开始拖动时触发
|
91 | * @supported rn
|
92 | */
|
93 | onDragStart?: CommonEventFunction
|
94 |
|
95 | /** 拖动结束时触发
|
96 | * @supported rn
|
97 | */
|
98 | onDragEnd?: CommonEventFunction
|
99 |
|
100 | /** 缩放过程中触发的事件
|
101 | * @supported weapp, alipay, swan, tt, qq, h5
|
102 | */
|
103 | onScale?: CommonEventFunction<MovableViewProps.onScaleEventDetail>
|
104 |
|
105 | /** 触摸动作开始,事件会向父节点传递。
|
106 | * @supported alipay
|
107 | */
|
108 | onTouchStart?: CommonEventFunction
|
109 |
|
110 | /** 触摸动作开始,事件仅作用于组件,不向父节点传递。
|
111 | * @supported alipay
|
112 | */
|
113 | onTouchMove?: CommonEventFunction
|
114 |
|
115 | /** 手指触摸动作结束
|
116 | * @supported alipay, h5
|
117 | * @h5 此事件的触发顺序会因为当前事件机制引起组件内外注册的事件执行顺序不正常,外部注册的事件可能会优先于内部执行,如需保证执行顺序一致,需要在回调函数中包裹 setTimeout 临时处理
|
118 | */
|
119 | onTouchEnd?: TouchEventFunction
|
120 |
|
121 | /** 触摸动作被打断,如来电提醒、弹窗。
|
122 | * @supported alipay
|
123 | */
|
124 | onTouchCancel?: CommonEventFunction
|
125 |
|
126 | /** 初次手指触摸后移动为横向的移动,如果 catch 此事件,则意味着 touchmove 事件也被 catch
|
127 | * @supported weapp, swan, tt, h5
|
128 | */
|
129 | onHTouchMove?: TouchEventFunction
|
130 |
|
131 | /** 初次手指触摸后移动为纵向的移动,如果 catch 此事件,则意味着 touchmove 事件也被 catch
|
132 | * @supported weapp, swan, tt, h5
|
133 | */
|
134 | onVTouchMove?: TouchEventFunction
|
135 |
|
136 | /** 触摸移动事件,事件仅作用于组件,不向父节点传递。
|
137 | * @supported alipay
|
138 | */
|
139 | catchTouchStart?: CommonEventFunction
|
140 |
|
141 | /** 触摸移动事件,事件仅作用于组件,不向父节点传递。
|
142 | * @supported alipay
|
143 | */
|
144 | catchTouchMove?: CommonEventFunction
|
145 |
|
146 | /** 触摸动作结束,事件仅作用于组件,不向父节点传递。
|
147 | * @supported alipay
|
148 | */
|
149 | catchTouchEnd?: CommonEventFunction
|
150 | }
|
151 | declare namespace MovableViewProps {
|
152 | /** 拖动过程中触发的事件 */
|
153 | interface TChangeSource {
|
154 | /** 拖动 */
|
155 | touch
|
156 |
|
157 | /** 超出移动范围 */
|
158 | 'touch-out-of-bounds'
|
159 |
|
160 | /** 超出移动范围后的回弹 */
|
161 | 'out-of-bounds'
|
162 |
|
163 | /** 惯性 */
|
164 | friction
|
165 |
|
166 | /** setData */
|
167 | ''
|
168 | }
|
169 | interface onChangeEventDetail {
|
170 | /** X 坐标 */
|
171 | x: number
|
172 |
|
173 | /** Y 坐标 */
|
174 | y: number
|
175 |
|
176 | /** 触发事件 */
|
177 | source: keyof MovableViewProps.TChangeSource
|
178 | }
|
179 | interface onScaleEventDetail {
|
180 | /** X 坐标 */
|
181 | x: number
|
182 |
|
183 | /** Y 坐标 */
|
184 | y: number
|
185 |
|
186 | /** 缩放比例 */
|
187 | scale: number
|
188 | }
|
189 | }
|
190 |
|
191 | /** 可移动的视图容器,在页面中可以拖拽滑动。movable-view 必须在 movable-area 组件中,并且必须是直接子节点,否则不能移动。
|
192 | * @classification viewContainer
|
193 | * @supported weapp, alipay, swan, tt, qq, h5, rn
|
194 | * @example_react
|
195 | * ```tsx
|
196 | * class App extends Components {
|
197 | * render () {
|
198 | * return (
|
199 | * <MovableArea style='height: 200px; width: 200px; background: red;'>
|
200 | * <MovableView style='height: 50px; width: 50px; background: blue;' direction='all'></MovableView>
|
201 | * </MovableArea>
|
202 | * )
|
203 | * }
|
204 | * }
|
205 | * ```
|
206 | * @example_vue
|
207 | * ```html
|
208 | * <movable-area style='height: 200px; width: 200px; background: red;'>
|
209 | * <movable-view style='height: 50px; width: 50px; background: blue;' direction='all'>带我走</movable-view>
|
210 | * </movable-area>
|
211 | * ```
|
212 | * @see https://developers.weixin.qq.com/miniprogram/dev/component/movable-view.html
|
213 | */
|
214 | declare const MovableView: ComponentType<MovableViewProps>
|
215 | export { MovableView, MovableViewProps }
|