Skip to content
This repository was archived by the owner on Sep 28, 2021. It is now read-only.

Commit bf7f637

Browse files
authored
Merge pull request #245 from sanqi/master
add pageAnimateTime and fix enablePreload
2 parents f19387f + 1ef226b commit bf7f637

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ export default class App extends React.Component {
100100
| backgroundColor | string<br><br>`white` | no | Component background color | `black` |
101101
| enableSwipeDown | boolean | no | Enable swipe down to close image viewer. When swipe down, will trigger onCancel. | false |
102102
| doubleClickInterval | number | no | Double click interval. | |
103+
| pageAnimateTime | number | no | Set the animation time for page flipping. | 100 |
104+
| enablePreload | boolean | no | Preload the next image | false |
103105

104106
## Development pattern
105107

src/image-viewer.component.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ export default class ImageViewer extends React.Component<Props, State> {
181181

182182
// 如果已知源图片宽高,直接设置为 success
183183
if (image.width && image.height){
184+
if(this.props.enablePreload && imageLoaded===false){
185+
Image.prefetch(image.url)
186+
}
184187
imageStatus.width = image.width;
185188
imageStatus.height = image.height;
186189
imageStatus.status = 'success';
@@ -299,7 +302,7 @@ export default class ImageViewer extends React.Component<Props, State> {
299302
this.standardPositionX = this.positionXNumber;
300303
Animated.timing(this.positionX, {
301304
toValue: this.positionXNumber,
302-
duration: 100
305+
duration: this.props.pageAnimateTime
303306
}).start();
304307

305308
const nextIndex = (this.state.currentShowIndex || 0) - 1;
@@ -332,7 +335,7 @@ export default class ImageViewer extends React.Component<Props, State> {
332335
this.standardPositionX = this.positionXNumber;
333336
Animated.timing(this.positionX, {
334337
toValue: this.positionXNumber,
335-
duration: 100
338+
duration: this.props.pageAnimateTime
336339
}).start();
337340

338341
const nextIndex = (this.state.currentShowIndex || 0) + 1;

src/image-viewer.type.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ export class Props {
7373
*/
7474
public enablePreload?: boolean = false;
7575

76+
/**
77+
* 翻页时的动画时间
78+
*/
79+
public pageAnimateTime?: number = 100;
80+
7681
/**
7782
* 长按图片的回调
7883
*/

0 commit comments

Comments
 (0)