Skip to content

Commit

Permalink
fix(rkModalImg): fix swipe images in full screen mode on android
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-kozel committed Jan 12, 2018
1 parent c9a9f5c commit 4923bd2
Showing 1 changed file with 13 additions and 36 deletions.
49 changes: 13 additions & 36 deletions src/components/image/rkModalImg.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import {
Image,
Text,
Modal,
ListView,
Animated,
Dimensions,
Platform
Platform,
FlatList
} from 'react-native';
import _ from 'lodash';
import {RkButton} from '../button/rkButton';
import {RkText} from '../text/rkText';
import {RkComponent} from '../rkComponent';
Expand Down Expand Up @@ -151,7 +150,6 @@ export class RkModalImg extends RkComponent {
modal: {}
};

firstOrientationChange = true;
needUpdateScroll = false;

constructor(props) {
Expand All @@ -166,54 +164,38 @@ export class RkModalImg extends RkComponent {
}

componentDidUpdate() {
let updateScroll = () => {
this.refs.listView.scrollTo({x: this.state.index * this.state.width, animated: false});
if (this.needUpdateScroll && this.refs.list) {
this.refs.list.scrollToOffset({offset: this.state.index * this.state.width, animated: false});
this.needUpdateScroll = false;
};
if (this.needUpdateScroll && this.refs.listView) {
if (Platform.OS === 'ios') {
updateScroll();
} else {
_.delay(updateScroll, 100);
}
}
}

_renderList(source, index, props) {
let ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
return <ListView
ref='listView'
onScroll={(e) => this._onScroll(e)}
dataSource={ds.cloneWithRows(source.map((s) => {
return {img: s}
}))}
renderRow={(source) => this._renderImage(source.img, props)}
return <FlatList
ref='list'
data={Array.from(this.props.source)}
renderItem={({item}) => this._renderImage(item, props)}
horizontal
pagingEnabled
renderSeparator={() => null}
showsHorizontalScrollIndicator={false}
showsVerticalScrollIndicator={false}
directionalLockEnabled
scrollEventThrottle={100}
keyExtractor={(item, index) => index}
extraData={this.state}
onScroll={(e) => this._onScroll(e)}
/>
}

_renderImage(source, props) {
return (
<TouchableWithoutFeedback style={{flex:1}}
onPress={() => this._toggleControls()}
onPressIn={() => this.pressActive = true}>
onPress={() => this._toggleControls()}>
<Image source={source} {...props}/>
</TouchableWithoutFeedback>
)
}

_toggleControls() {
if (this.pressActive) {
Animated.timing(this.state.opacity, {
toValue: this.state.opacity._value ? 0 : 1
}).start()
}
}

_renderFooter(options) {
Expand Down Expand Up @@ -262,20 +244,15 @@ export class RkModalImg extends RkComponent {
index: imageIndex
})
}
this.pressActive = false;
}

_closeImage() {
this.setState({visible: false})
this.setState({visible: false});
}

_onOrientationChange() {
if (!this.firstOrientationChange) {
this.needUpdateScroll = true;
this.forceUpdate();
} else {
this.firstOrientationChange = undefined;
}
}

_updateDimensionsState() {
Expand Down

0 comments on commit 4923bd2

Please sign in to comment.