forked from ascoders/react-native-image-viewer
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathimage-viewer.type.ts
308 lines (261 loc) · 5.78 KB
/
image-viewer.type.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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
import * as React from 'react';
import { Image, ImageURISource, Text, View, ViewStyle } from 'react-native';
import { simpleStyle } from './image-viewer.style';
interface IOnMove {
type: string;
positionX: number;
positionY: number;
scale: number;
zoomCurrentDistance: number;
}
export class Props {
/**
* 是否显示
*/
public show?: boolean = false;
/**
* 图片数组
*/
public imageUrls: IImageInfo[] = [];
/**
* 滑动到下一页的X阈值
*/
public flipThreshold?: number = 80;
/**
* 当前页能滑到下一页X位置最大值
*/
public maxOverflow?: number = 300;
/**
* 初始显示第几张图
*/
public index?: number = 0;
/**
* 加载失败的图
*/
public failImageSource?: IImageInfo = undefined;
/**
* 背景颜色
*/
public backgroundColor?: string = 'black';
/**
* style props for the footer container
*/
public footerContainerStyle?: object = {};
/**
* Menu Context Values
*/
public menuContext?: any = { saveToLocal: 'save to the album', cancel: 'cancel' };
/**
* 是否开启长按保存到本地的功能
*/
public saveToLocalByLongPress?: boolean = true;
/**
* 是否允许缩放图片
*/
public enableImageZoom?: boolean = true;
public style?: ViewStyle = {};
/**
* Enable swipe down to close image viewer.
* When swipe down, will trigger onCancel.
*/
public enableSwipeDown?: boolean = false;
/**
* threshold for firing swipe down function
*/
public swipeDownThreshold?: number;
public doubleClickInterval?: number;
/**
* Min and Max scale for zooming
*/
public minScale?: number;
public maxScale?: number;
/**
* 是否预加载图片
*/
public enablePreload?: boolean = false;
/**
* 翻页时的动画时间
*/
public pageAnimateTime?: number = 100;
/**
* 是否启用原生动画驱动
* Whether to use the native code to perform animations.
*/
public useNativeDriver?: boolean = false;
/**
* 长按图片的回调
*/
public onLongPress?: (image?: IImageInfo) => void = () => {
//
};
/**
* 单击回调
*/
public onClick?: (close?: () => any, currentShowIndex?: number) => void = () => {
//
};
/**
* 双击回调
*/
public onDoubleClick?: (close?: () => any) => void = () => {
//
};
/**
* 图片保存到本地方法,如果写了这个方法,就不会调取系统默认方法
* 针对安卓不支持 saveToCameraRoll 远程图片,可以在安卓调用此回调,调用安卓原生接口
*/
public onSave?: (url: string) => void = () => {
//
};
public onMove?: (position?: IOnMove) => void = () => {
//
};
/**
* 自定义头部
*/
public renderHeader?: (currentIndex?: number) => React.ReactElement<any> = () => {
return null as any;
};
/**
* 自定义尾部
*/
public renderFooter?: (currentIndex: number) => React.ReactElement<any> = () => {
return null as any;
};
/**
* 自定义计时器
*/
public renderIndicator?: (currentIndex?: number, allSize?: number) => React.ReactElement<any> = (
currentIndex?: number,
allSize?: number
) => {
return React.createElement(
View,
{ style: simpleStyle.count },
React.createElement(Text, { style: simpleStyle.countText }, currentIndex + '/' + allSize)
);
};
/**
* Render image component
*/
public renderImage?: (props: any) => React.ReactElement<any> = (props: any) => {
return React.createElement(Image, props);
};
/**
* 自定义左翻页按钮
*/
public renderArrowLeft?: () => React.ReactElement<any> = () => {
return null as any;
};
/**
* 自定义右翻页按钮
*/
public renderArrowRight?: () => React.ReactElement<any> = () => {
return null as any;
};
/**
* 弹出大图的回调
*/
public onShowModal?: (content?: any) => void = () => {
//
};
/**
* 取消看图的回调
*/
public onCancel?: () => void = () => {
//
};
/**
* function that fires when user swipes down
*/
public onSwipeDown?: () => void = () => {
//
};
/**
* 渲染loading元素
*/
public loadingRender?: () => React.ReactElement<any> = () => {
return null as any;
};
/**
* 保存到相册的回调
*/
public onSaveToCamera?: (index?: number) => void = () => {
//
};
/**
* 当图片切换时触发
*/
public onChange?: (index?: number) => void = () => {
//
};
public menus?: ({ cancel, saveToLocal }: any) => React.ReactElement<any>;
}
export class State {
/**
* 是否显示
*/
public show?: boolean = false;
/**
* 当前显示第几个
*/
public currentShowIndex?: number = 0;
/**
* Used to detect if parent component applied new index prop
*/
public prevIndexProp?: number = 0;
/**
* 图片拉取是否完毕了
*/
public imageLoaded?: boolean = false;
/**
* 图片长宽列表
*/
public imageSizes?: IImageSize[] = [];
/**
* 是否出现功能菜单
*/
public isShowMenu?: boolean = false;
}
export interface IImageInfo {
url: string;
/**
* 没有的话会自动拉取
*/
width?: number;
/**
* 没有的话会自动拉取
*/
height?: number;
/**
* 图片字节大小(kb为单位)
*/
sizeKb?: number;
/**
* 原图字节大小(kb为单位)
* 如果设置了这个字段,并且有原图url,则显示查看原图按钮
*/
originSizeKb?: number;
/**
* 原图url地址
*/
originUrl?: string;
/**
* Pass to image props
*/
props?: any;
/**
* 初始是否不超高 TODO:
*/
freeHeight?: boolean;
/**
* 初始是否不超高 TODO:
*/
freeWidth?: boolean;
}
export interface IImageSize {
width: number;
height: number;
// 图片加载状态
status: 'loading' | 'success' | 'fail';
}