|
1 | 1 | /* @flow */ |
2 | 2 |
|
3 | 3 | import React from 'react' |
4 | | -import { Easing, Animated, StyleSheet, Dimensions } from 'react-native' |
| 4 | +import { Easing, Platform, Animated, StyleSheet, Dimensions } from 'react-native' |
5 | 5 | import ViewerBackground from './ViewerBackground' |
6 | 6 | import ScrollSpacerView from './ScrollSpacerView' |
7 | 7 | import ImageHorizontalContainer from './ImageHorizontalContainer' |
@@ -101,6 +101,7 @@ class ImageViewer extends React.Component<Props, State> { |
101 | 101 | _getTransitionProgress = () => { |
102 | 102 | const gestureDismissProgress = |
103 | 103 | this.state.dismissScrollProgress && |
| 104 | + Platform.OS === 'ios' && |
104 | 105 | this.state.dismissScrollProgress.interpolate({ |
105 | 106 | inputRange: [ |
106 | 107 | 0, |
@@ -286,6 +287,80 @@ class ImageViewer extends React.Component<Props, State> { |
286 | 287 | } |
287 | 288 | } |
288 | 289 |
|
| 290 | + _renderVerticalScrollView( |
| 291 | + width: Animated.Value, |
| 292 | + height: Animated.Value, |
| 293 | + imageSource: ?ImageSource, |
| 294 | + openImageMeasurements: ?ImageMeasurements, |
| 295 | + openProgress: any, |
| 296 | + dismissProgress: any, |
| 297 | + transitionProgress: any |
| 298 | + ) { |
| 299 | + if (Platform.OS === 'ios') { |
| 300 | + return ( |
| 301 | + <Animated.ScrollView |
| 302 | + ref={this._handleRef} |
| 303 | + onScroll={Animated.event( |
| 304 | + [ |
| 305 | + { |
| 306 | + nativeEvent: { |
| 307 | + contentOffset: { y: this.state.dismissScrollProgress } |
| 308 | + } |
| 309 | + } |
| 310 | + ], |
| 311 | + { useNativeDriver: true, listener: this._onScroll } |
| 312 | + )} |
| 313 | + scrollEventThrottle={1} |
| 314 | + pagingEnabled={true} |
| 315 | + showsVerticalScrollIndicator={false} |
| 316 | + > |
| 317 | + <ScrollSpacerView width={width} height={height} /> |
| 318 | + <ImageHorizontalContainer |
| 319 | + images={this.props.images} |
| 320 | + imageId={this.props.imageId} |
| 321 | + uri={imageSource ? imageSource.URI : ''} |
| 322 | + width={width.__getValue()} |
| 323 | + height={height.__getValue()} |
| 324 | + imageWidth={openImageMeasurements ? openImageMeasurements.width : 0} |
| 325 | + imageHeight={ |
| 326 | + openImageMeasurements ? openImageMeasurements.height : 0 |
| 327 | + } |
| 328 | + realImageWidth={this.state.imageWidth} |
| 329 | + realImageHeight={this.state.imageHeight} |
| 330 | + openProgress={openProgress} |
| 331 | + dismissProgress={dismissProgress} |
| 332 | + transitionProgress={transitionProgress} |
| 333 | + dismissScrollProgress={this.state.dismissScrollProgress} |
| 334 | + onChangePhoto={this.props.onChangePhoto} |
| 335 | + openImageMeasurements={openImageMeasurements || {}} |
| 336 | + onPressImage={this._onPressImage} |
| 337 | + /> |
| 338 | + <ScrollSpacerView width={width} height={height} /> |
| 339 | + </Animated.ScrollView> |
| 340 | + ) |
| 341 | + } |
| 342 | + return ( |
| 343 | + <ImageHorizontalContainer |
| 344 | + images={this.props.images} |
| 345 | + imageId={this.props.imageId} |
| 346 | + uri={imageSource ? imageSource.URI : ''} |
| 347 | + width={width.__getValue()} |
| 348 | + height={height.__getValue()} |
| 349 | + imageWidth={openImageMeasurements ? openImageMeasurements.width : 0} |
| 350 | + imageHeight={openImageMeasurements ? openImageMeasurements.height : 0} |
| 351 | + realImageWidth={this.state.imageWidth} |
| 352 | + realImageHeight={this.state.imageHeight} |
| 353 | + openProgress={openProgress} |
| 354 | + dismissProgress={dismissProgress} |
| 355 | + transitionProgress={transitionProgress} |
| 356 | + dismissScrollProgress={this.state.dismissScrollProgress} |
| 357 | + onChangePhoto={this.props.onChangePhoto} |
| 358 | + openImageMeasurements={openImageMeasurements || {}} |
| 359 | + onPressImage={this._onPressImage} |
| 360 | + /> |
| 361 | + ) |
| 362 | + } |
| 363 | + |
289 | 364 | render() { |
290 | 365 | const { |
291 | 366 | width, |
@@ -317,47 +392,15 @@ class ImageViewer extends React.Component<Props, State> { |
317 | 392 | inputRange={[0, height.__getValue(), height.__getValue() * 2]} |
318 | 393 | outputRange={[0.02, 1, 0.02]} |
319 | 394 | /> |
320 | | - <Animated.ScrollView |
321 | | - ref={this._handleRef} |
322 | | - onScroll={Animated.event( |
323 | | - [ |
324 | | - { |
325 | | - nativeEvent: { |
326 | | - contentOffset: { y: this.state.dismissScrollProgress } |
327 | | - } |
328 | | - } |
329 | | - ], |
330 | | - { useNativeDriver: true, listener: this._onScroll } |
331 | | - )} |
332 | | - scrollEventThrottle={1} |
333 | | - pagingEnabled={true} |
334 | | - showsVerticalScrollIndicator={false} |
335 | | - > |
336 | | - <ScrollSpacerView width={width} height={height} /> |
337 | | - <ImageHorizontalContainer |
338 | | - images={this.props.images} |
339 | | - imageId={this.props.imageId} |
340 | | - uri={imageSource ? imageSource.URI : ''} |
341 | | - width={width.__getValue()} |
342 | | - height={height.__getValue()} |
343 | | - imageWidth={ |
344 | | - openImageMeasurements ? openImageMeasurements.width : 0 |
345 | | - } |
346 | | - imageHeight={ |
347 | | - openImageMeasurements ? openImageMeasurements.height : 0 |
348 | | - } |
349 | | - realImageWidth={this.state.imageWidth} |
350 | | - realImageHeight={this.state.imageHeight} |
351 | | - openProgress={openProgress} |
352 | | - dismissProgress={dismissProgress} |
353 | | - transitionProgress={transitionProgress} |
354 | | - dismissScrollProgress={this.state.dismissScrollProgress} |
355 | | - onChangePhoto={this.props.onChangePhoto} |
356 | | - openImageMeasurements={openImageMeasurements || {}} |
357 | | - onPressImage={this._onPressImage} |
358 | | - /> |
359 | | - <ScrollSpacerView width={width} height={height} /> |
360 | | - </Animated.ScrollView> |
| 395 | + {this._renderVerticalScrollView( |
| 396 | + width, |
| 397 | + height, |
| 398 | + imageSource, |
| 399 | + openImageMeasurements, |
| 400 | + openProgress, |
| 401 | + dismissProgress, |
| 402 | + transitionProgress |
| 403 | + )} |
361 | 404 | </Animated.View> |
362 | 405 | {initialImageMeasurements && |
363 | 406 | openImageMeasurements && ( |
|
0 commit comments