Repository navigation
Closed
Labels
Resolution: LockedThis issue was locked by the bot.This issue was locked by the bot.
Description
After orientation mode === LANDSCAPE currentIndex = 0.
I have grid item, after select item - open carousel(FlatList) on currentIndex, and if i rotate device my current item in carousel set 0.
This example
slider.js
componentDidMount() {
const wait = new Promise(resolve => setTimeout(resolve, 500)); // Smaller number should work
wait.then(() => {
this.list.scrollToIndex({
viewPosition: 0.5,
index: this.props.page || 0,
animated: false,
});
});
this._setScrollTarget(this.props);
}
componentWillReceiveProps(nextProps) {
if (...) {
this._setScrollTarget(nextProps);
}
}
_setScrollTarget(props) {
const {
width,
page,
} = props;
this.list.scrollToOffset({
x: ((width) * page),
y: 0,
animated: false,
});
}
_getItems = (media, width, height) => {
const { MediaItem, page } = this.props;
const items = [];
for (let i = 0; i <= media.length - 1; i++) {
const item = media[i];
items.push(
<MediaItem
key={`page-${i}`}
screen={{ width, height }}
currentIndex={page}
{...item}
/>,
);
}
return items;
};
...
const items = this._getItems(media, width, height);
return (
<FlatList
ref={(ref) => { this.list = ref; }}
style={{
flex: 1,
}}
horizontal
pagingEnabled
scrollEnabled={enabled}
removeClippedSubviews={false}
scrollToEnd={this._onScrollEnd}
data={items}
renderItem={({ item }) => item}
getItemLayout={this._getItemLayout}
shouldItemUpdate={this._shouldItemUpdate}
/>
);
Main.js
...
return (
<View
style={{flex: 1}}
onLayout={this._onLayout} // change width/height orientation
>
<MediaSlider
media={files} // data files
MediaItem={FileViewer} // files
page={selectedIndex} // currentIndex
width={this.state.layout.width}
height={this.state.layout.height}
/>
</View>
)
this video - http://take.ms/DHdyO
Additional Information
React Native version: v0.43.1
Platform: Both
Operating System: MacOS
Metadata
Metadata
Assignees
Labels
Resolution: LockedThis issue was locked by the bot.This issue was locked by the bot.
Activity
sahrens commentedon May 3, 2017
You didn't include your
_getItemLayoutimplementation - it's hard to figure out what's wrong with incomplete code.leonidkuznetsov18 commentedon May 3, 2017
@sahrens
leonidkuznetsov18 commentedon May 3, 2017
@sahrens
The only solution at the moment,
slider.jsBut in this solution there is 1 big minus - this is a delay, and flickering(((
[-]FlatList landscape mode bugs getItemLayout[/-][+][FlatList] FlatList landscape mode bugs getItemLayout[/+]hramos commentedon Aug 16, 2017
Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we're automatically closing issues after a period of inactivity. Please do not take it personally!
If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:
If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.