viewPagerAndroid not working after push and back
I use react-native-tab-view , and push to a view ,and back to the last view , the viewPagerAndroid's touch is not working , and the Tab Button clicks without effect Android:7.0,5.0 react-native : 0.44, react-native-navigation:1.1.80
Is the onPress triggering JS side?
I'm having the same issue, whenever I push a view and then come back no onPress work in any component rendered inside the ViewPagerAndroid, and swiping the pager becomes really really slow
That is the ViewPagerAndroid 's bug I think , and I solve that by using react-native-tab-view ' s TabViewPagerPan https://github.com/react-native-community/react-native-tab-view
still happens with the suggested library or any other, including https://github.com/leecade/react-native-swiper and the funny thing is that it only happens on Android, IOS works just fine.
If I instead of pop do a resetTo everything works just fine.
I am also experiencing this issue.
So the way I solved it is that on android instead of doing a push and pop I did a show and dismiss modal
Its a bug in ViewPagerAndroid . In ios its works fine as its based on ScrollView .Any library that implements ViewPagerAndroid ,same problem will occur . Using Modal instead of push will work , but not a good solution.
this is a critical bug towards android app using viewpager, please help support this ticket guys Tons of thanks
@dzunglht You can try something like this:
import React, { PureComponent } from 'react';
import {
View,
Dimensions,
} from 'react-native';
export default class ViewPagerWrapper extends PureComponent {
constructor(props) {
super(props);
this.props.navigator &&
this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent.bind(this));
}
onNavigatorEvent (event) {
switch(event.id) {
case 'willAppear':
this._reattach();
break;
}
}
state = {
width: Dimensions.get('window').width,
}
render() {
return (
<View style={[this.props.style, { flex: 1 }]}>
<View style={{ width: this.state.width, flex: 1 }}>
{this.props.children}
</View>
</View>
)
}
_x = 0.5
_reattach = () => {
this.setState({
width: this.state.width - this._x,
}, () => {
this._x *= -1;
});
}
and then use:
<ViewPagerWrapper navigator={this.props.navigator}>
<YourAwesomeComponent>
//Component that uses ViewPagerAndroid
...
</YourAwesomeComponent>
</ViewPagerWrapper>
Maybe this is not most elegant solution, but it works for me.
@guyca Please have an official fix asap, this is such a critical bug, above way doesn't work. Thanks
look at this https://github.com/jykun/react-native-swiper.git, i change viewPageAndroid to scrollView.
@meow0703 @dzunglht Can you guys upload an example where the bug is reproducible? I doubt this is a bug in RNN, it's probably an issue in the actual component which will require a PR to RN.
I just came here to confirm that this happens to me too.
@guyca Steps to reproduce:
- create root with startTabBasedApp() with
xtabs - in one tab, render
ViewPagerAndroid - from that tab push some screen with this.props.navigator.push()
- press back on the newly pushed screen
- the
ViewPagerAndroidno longer works
Dear folks, 8 days passed, we're looking for your official fix asap Many thanks
Dear wix team , can you make a alternative viewPager component to ViewPagerAndroid . ViewpagerAndroid has only few features that doesnot include pagePadding or snapped carousel like features . I know react-native-navigation has a built in Viewpager class used for TopTabs scrolling . So please create a top lavel Viewpager Component .
@guyca please , think about it.
On 03-Jul-2017 3:09 PM, "dzunglht" [email protected] wrote:
Dear folks, 8 days passed, we're looking for your official fix asap Many thanks
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/wix/react-native-navigation/issues/1317#issuecomment-312598982, or mute the thread https://github.com/notifications/unsubscribe-auth/AKYl_wb7kdKCC-wsDdOATDhSUm8NBNiSks5sKLbqgaJpZM4Nt0y9 .
@all @guyca Please have a look on below elegant library (built for react-native in mind) and refer how efficiently they use their viewPager, we should extend and/or make use of their effort. Hope that help. Ref: https://github.com/appintheair/react-native-looped-carousel
@guyca where are you now, when we have official fix for the ticket ?
If you guys are waiting on this internally or something then I'd try and look at alternative options for now, there is no timeline on when this will be fixed.
Hey guys
I managed to take some time today to look into this issue. I think this is actually a bug in the native ViewPager. It seems to be tracking its layout state when the view is attached. Since the view is already laid out when it's added again to the screen - onLayout isn't called which is where mIsFirstLayout is set to false.
Because the ViewPager can't smooth scroll back to the selected item before onLayout stage is completed (since it doesn't know the item size) - smooth scrolling doesn't work.
We can easily trick the system into measuring and going through the entire layout cycle of the ViewPager (essentially invalidating the view) by changing the dimensions of the ViewPagerAndroid when the visibility of the screen changes.
export default class ViewPagerAndroidScreen extends React.Component {
constructor(props) {
super(props);
this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent.bind(this));
this.state = {
visible: true
}
}
onNavigatorEvent(event) {
if (event.id === 'willAppear') {
this.setState({
visible: true
});
}
if (event.id === 'willDisappear') {
this.setState({
visible: false
});
}
}
render() {
return (
<ViewPagerAndroid
style={[styles.viewPager, {flex: this.state.visible ? 1 : 0}]}>
<View>
<Text>First page</Text>
</View>
<View>
<Text>Second page</Text>
</View>
</ViewPagerAndroid>
);
}
}
Perhaps we can introduce a property to navigator.pop which will force the native views the layout