Skip to content

Commit

Permalink
view pager allows setPage without animation
Browse files Browse the repository at this point in the history
  • Loading branch information
machard committed Nov 6, 2015
1 parent 48278f8 commit 7fe9e78
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
5 changes: 4 additions & 1 deletion Libraries/Components/ViewPager/ViewPagerAndroid.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var VIEWPAGER_REF = 'viewPager';

var ViewPagerValidAttributes = {
selectedPage: true,
showAnimation: true
};

/**
Expand Down Expand Up @@ -148,15 +149,17 @@ var ViewPagerAndroid = React.createClass({
this.props.onPageSelected(event);
}
},
setPage: function(selectedPage) {
setPage: function(selectedPage, showAnimation = true) {
this.setState({
selectedPage,
showAnimation
});
},
render: function() {
return (
<NativeAndroidViewPager
ref={VIEWPAGER_REF}
showAnimation={this.state.showAnimation}
style={this.props.style}
selectedPage={this.state.selectedPage}
onPageScroll={this._onPageScroll}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
getAdapter().addView(child, index);
}

/* package */ void setCurrentItemFromJs(int item) {
/* package */ void setCurrentItemFromJs(int item, boolean showAnimation) {
mIsCurrentItemFromJs = true;
setCurrentItem(item);
setCurrentItem(item, showAnimation);
mIsCurrentItemFromJs = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
public class ReactViewPagerManager extends ViewGroupManager<ReactViewPager> {

private static final String REACT_CLASS = "AndroidViewPager";
private int nextPage;
private boolean showAnimation;

@Override
public String getName() {
Expand All @@ -38,7 +40,18 @@ protected ReactViewPager createViewInstance(ThemedReactContext reactContext) {
@ReactProp(name = "selectedPage")
public void setSelectedPage(ReactViewPager view, int page) {
// TODO(8496821): Handle selectedPage property cleanup correctly, now defaults to 0
view.setCurrentItemFromJs(page);
nextPage = page;
}

@ReactProp(name = "showAnimation", defaultBoolean = true)
public void setShowAnimation(ReactViewPager view, boolean value) {
showAnimation = value;
}

@Override
protected void onAfterUpdateTransaction(ReactViewPager view) {
view.setCurrentItemFromJs(nextPage, showAnimation);
super.onAfterUpdateTransaction(view);
}

@Override
Expand Down

1 comment on commit 7fe9e78

@machard
Copy link
Owner Author

@machard machard commented on 7fe9e78 Nov 6, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.