Skip to content

Commit f90b73a

Browse files
Merge pull request ascoders#394 from pxpeterxu/master
Allow specifying whether to use useNativeDriver
2 parents 176942a + 963416e commit f90b73a

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export default class App extends React.Component {
105105
| doubleClickInterval | number | no | Double click interval. | |
106106
| pageAnimateTime | number | no | Set the animation time for page flipping. | `100` |
107107
| enablePreload | boolean | no | Preload the next image | `false` |
108+
| useNativeDriver | boolean | no | Whether to animate using [`useNativeDriver`](https://reactnative.dev/docs/animations#using-the-native-driver) | `false` |
108109
| menus | function<br><br>`({cancel,saveToLocal}) => React.ReactElement<any>` | no | Custom menus, with 2 methods:`cancel` to hide menus and `saveToLocal` to save image to camera
109110
| menuContext | object<br><br>`{someKey: someValue}` | no | Custom menu context. | `{ saveToLocal: 'save to the album', cancel: 'cancel' }`
110111
## Development pattern

Diff for: src/image-viewer.component.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default class ImageViewer extends React.Component<Props, State> {
7070
Animated.timing(this.fadeAnim, {
7171
toValue: 1,
7272
duration: 200,
73-
useNativeDriver: false
73+
useNativeDriver: !!this.props.useNativeDriver
7474
}).start();
7575
}
7676
}
@@ -111,7 +111,7 @@ export default class ImageViewer extends React.Component<Props, State> {
111111
Animated.timing(this.fadeAnim, {
112112
toValue: 1,
113113
duration: 200,
114-
useNativeDriver: false
114+
useNativeDriver: !!nextProps.useNativeDriver
115115
}).start();
116116
}
117117
);
@@ -307,7 +307,7 @@ export default class ImageViewer extends React.Component<Props, State> {
307307
Animated.timing(this.positionX, {
308308
toValue: this.positionXNumber,
309309
duration: this.props.pageAnimateTime,
310-
useNativeDriver: false
310+
useNativeDriver: !!this.props.useNativeDriver
311311
}).start();
312312

313313
const nextIndex = (this.state.currentShowIndex || 0) - 1;
@@ -341,7 +341,7 @@ export default class ImageViewer extends React.Component<Props, State> {
341341
Animated.timing(this.positionX, {
342342
toValue: this.positionXNumber,
343343
duration: this.props.pageAnimateTime,
344-
useNativeDriver: false
344+
useNativeDriver: !!this.props.useNativeDriver
345345
}).start();
346346

347347
const nextIndex = (this.state.currentShowIndex || 0) + 1;
@@ -366,7 +366,7 @@ export default class ImageViewer extends React.Component<Props, State> {
366366
Animated.timing(this.positionX, {
367367
toValue: this.standardPositionX,
368368
duration: 150,
369-
useNativeDriver: false
369+
useNativeDriver: !!this.props.useNativeDriver
370370
}).start();
371371
}
372372

Diff for: src/image-viewer.type.ts

+6
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ export class Props {
9898
*/
9999
public pageAnimateTime?: number = 100;
100100

101+
/**
102+
* 是否启用原生动画驱动
103+
* Whether to use the native code to perform animations.
104+
*/
105+
public useNativeDriver?: boolean = false;
106+
101107
/**
102108
* 长按图片的回调
103109
*/

0 commit comments

Comments
 (0)