Fix swiper offset when device rotates (#1253)

This commit is contained in:
enahum 2017-12-04 16:32:06 -03:00 committed by GitHub
parent 92eab50a63
commit 86667de6c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 4 deletions

View file

@ -68,7 +68,9 @@ export default class Swiper extends PureComponent {
};
};
onLayout = () => {
onLayout = (e) => {
this.offset = e.nativeEvent.layout.width * this.state.index;
if (this.runOnLayout) {
if (Platform.OS === 'ios') {
setTimeout(() => {

View file

@ -75,6 +75,7 @@ export default class ImagePreview extends PureComponent {
this.zoomableImages = {};
const currentFile = props.files.findIndex((file) => file.id === props.fileId);
this.initialPage = currentFile;
this.state = {
currentFile,
@ -499,7 +500,7 @@ export default class ImagePreview extends PureComponent {
return (
<Swiper
ref='swiper'
initialPage={this.state.currentFile}
initialPage={this.initialPage}
onIndexChanged={this.handleIndexChanged}
width={this.props.deviceWidth}
activeDotColor={this.props.theme.sidebarBg}

View file

@ -2,7 +2,8 @@ import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
import {
Animated,
ScrollView
ScrollView,
StyleSheet
} from 'react-native';
const {Image: AnimatedImage} = Animated;
@ -73,7 +74,7 @@ export default class ImageView extends PureComponent {
alwaysBounceHorizontal={false}
alwaysBounceVertical={false}
bounces={false}
contentContainerStyle={{alignItems: 'center', justifyContent: 'center'}}
contentContainerStyle={style.content}
centerContent={true}
maximumZoomScale={maximumZoomScale}
minimumZoomScale={minimumZoomScale}
@ -87,3 +88,11 @@ export default class ImageView extends PureComponent {
);
}
}
const style = StyleSheet.create({
content: {
alignItems: 'center',
flex: 1,
justifyContent: 'center'
}
});