forked from rcbyr/keen-slider
-
Notifications
You must be signed in to change notification settings - Fork 1
/
react-native.d.ts
260 lines (223 loc) · 6.15 KB
/
react-native.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
import { MutableRefObject } from 'react'
import { GestureResponderEvent } from 'react-native'
import { LayoutChangeEvent } from 'react-native'
import { NativeMethods } from 'react-native'
export declare interface AnimatorInstance {
active: boolean
start: (
keyframes: {
distance: number
duration: number
earlyExit?: number
easing: (t: number) => number
}[]
) => void
stop: () => void
targetIdx: number | null
}
declare const _default: new <
O = {},
P = {},
H extends string = KeenSliderNativeHooks
>(
options?: KeenSliderNativeOptions<O, P, H>,
plugins?: KeenSliderNativePlugin<O, P, H>[]
) => KeenSliderNativeInstance<O, P, H>
export default _default
export declare type DRAG_ANIMATION_MODE_FREE = 'free'
export declare type DRAG_ANIMATION_MODE_FREE_SNAP = 'free-snap'
export declare type DRAG_ANIMATION_MODE_SNAP = 'snap'
export declare interface DragAnimationOptions<M> {
mode?: M
rubberband?: boolean
}
export declare type HOOK_ANIMATION_ENDED = 'animationEnded'
export declare type HOOK_ANIMATION_STARTED = 'animationStarted'
export declare type HOOK_ANIMATION_STOPPED = 'animationStopped'
export declare type HOOK_CREATED = 'created'
export declare type HOOK_DETAILS_CHANGED = 'detailsChanged'
export declare type HOOK_DRAG_CHECKED = 'dragChecked'
export declare type HOOK_DRAG_ENDED = 'dragEnded'
export declare type HOOK_DRAG_STARTED = 'dragStarted'
export declare type HOOK_DRAGGED = 'dragged'
export declare type HOOK_LAYOUT_CHANGED = 'layoutChanged'
export declare type HOOK_OPTIONS_CHANGED = 'optionsChanged'
export declare type HOOK_SLIDE_CHANGED = 'slideChanged'
export declare type HOOK_UPDATED = 'updated'
export declare type KeenSliderNativeHooks =
| SliderHooks
| HOOK_UPDATED
| HOOK_DRAGGED
| HOOK_DRAG_ENDED
| HOOK_DRAG_STARTED
| HOOK_DRAG_CHECKED
export declare type KeenSliderNativeInstance<
O = {},
P = {},
H extends string = KeenSliderNativeHooks
> = SliderInstance<
KeenSliderNativeOptions<O, P, H>,
NativeInstance<KeenSliderNativeOptions<O, P, H>> & P,
KeenSliderNativeHooks | H
>
export declare type KeenSliderNativeOptions<
O = {},
P = {},
H extends string = KeenSliderNativeHooks
> = SliderOptions<NativeOptions> & {
[key in Exclude<
H | KeenSliderNativeHooks,
keyof SliderOptions<NativeOptions>
>]?: (slider: KeenSliderNativeInstance<O, P, H>) => void
} & Omit<O, keyof SliderOptions<NativeOptions>>
export declare type KeenSliderNativePlugin<
O = {},
P = {},
H extends string = KeenSliderNativeHooks
> = SliderPlugin<
KeenSliderNativeOptions<O, P, H>,
KeenSliderNativeInstance<O, P, H>,
KeenSliderNativeHooks | H
>
export declare interface NativeInstance<O> {
containerProps: {
onStartShouldSetResponder?: (event: GestureResponderEvent) => void
onResponderMove?: (event: GestureResponderEvent) => void
onResponderRelease?: (event: GestureResponderEvent) => void
onResponderTerminate?: (event: GestureResponderEvent) => void
onLayout?: (event: LayoutChangeEvent) => void
}
slidesProps: SlideProps[]
size: number
next: () => void
prev: () => void
update: (options?: O, idx?: number) => void
}
export declare type NativeOptions = {
drag?: boolean
dragSpeed?: number | ((val: number) => number)
rubberband?: boolean
slides?:
| ((size: number) => TrackSlidesConfigOption)
| number
| {
origin?: 'center' | 'auto' | number
number?: number | (() => number | null) | null
perView?: number | (() => number)
spacing?: number | (() => number)
}
vertical?: boolean
} & DragAnimationOptions<
| DRAG_ANIMATION_MODE_SNAP
| DRAG_ANIMATION_MODE_FREE_SNAP
| DRAG_ANIMATION_MODE_FREE
>
export declare type SlideProps = {
ref?: MutableRefObject<NativeMethods | null>
style?: {
height: number | string
left: number | string
position: string
top: number | string
width: number | string
}
}
export declare type SliderHookOptions<H extends string, I> = {
[key in H]?: (slider: I) => void
}
export declare type SliderHooks =
| HOOK_CREATED
| HOOK_ANIMATION_ENDED
| HOOK_ANIMATION_STARTED
| HOOK_ANIMATION_STOPPED
| HOOK_SLIDE_CHANGED
| HOOK_DETAILS_CHANGED
export declare type SliderInstance<
O = {},
C = {},
H extends string = string
> = {
animator: AnimatorInstance
emit: (name: H | SliderHooks) => void
moveToIdx: (
idx: number,
absolute?: boolean,
animation?: {
duration?: number
easing?: (t: number) => number
}
) => void
on: (
name: H | SliderHooks,
cb: (props: SliderInstance<O, C, H>) => void,
remove?: boolean
) => void
options: SliderOptions<O>
track: TrackInstance
} & C
export declare type SliderOptions<O = {}> = {
defaultAnimation?: {
duration?: number
easing?: (t: number) => number
}
initial?: number
loop?:
| boolean
| {
min?: number
max?: number
}
range?: {
align?: boolean
min?: number
max?: number
}
rtl?: boolean
trackConfig?: TrackSlidesConfigOption
} & O
export declare type SliderPlugin<O = {}, C = {}, H extends string = string> = (
slider: SliderInstance<O, C, H>
) => void
export declare type TrackDetails = {
abs: number
length: number
max: number
maxIdx: number
min: number
minIdx: number
position: number
rel: number
progress: number
slides: {
abs: number
distance: number
portion: number
size: number
}[]
slidesLength: number
}
export declare interface TrackInstance {
absToRel: (absoluteIdx: number) => number
add: (value: number) => void
details: TrackDetails
distToIdx: (distance: number) => number
idxToDist: (idx: number, absolute?: boolean, fromPosition?: number) => number
init: (idx?: number) => void
to: (value: number) => void
velocity: () => number
}
export declare type TrackSlidesConfigEntry = {
origin?: Number
size?: Number
spacing?: Number
} | null
export declare type TrackSlidesConfigOption = TrackSlidesConfigEntry[]
export declare function useKeenSliderNative<
O = {},
P = {},
H extends string = KeenSliderNativeHooks
>(
options?: KeenSliderNativeOptions<O, P, H>,
plugins?: KeenSliderNativePlugin<O, P, H>[]
): KeenSliderNativeInstance<O, P, H>
export {}