Fix swiper offset when device rotates (#1253)
This commit is contained in:
parent
92eab50a63
commit
86667de6c3
3 changed files with 16 additions and 4 deletions
|
|
@ -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(() => {
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue