Skip to content
This repository was archived by the owner on Nov 27, 2022. It is now read-only.

Commit f6d7cfd

Browse files
azurechensatya164
authored andcommitted
feat: support horizontal bounces for PagerScoll to make it looks like iOS component (#722)
1 parent 3e5fed7 commit f6d7cfd

File tree

6 files changed

+10
-4
lines changed

6 files changed

+10
-4
lines changed

example/src/TopBarIconExample.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export default class TopBarIconExample extends React.Component<*, State> {
6969
renderScene={this._renderScene}
7070
renderTabBar={this._renderTabBar}
7171
onIndexChange={this._handleIndexChange}
72+
bounces // only iOS
7273
/>
7374
);
7475
}

example/src/TopBarTextExample.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export default class TopBarTextExample extends React.Component<*, State> {
7373
renderTabBar={this._renderTabBar}
7474
onIndexChange={this._handleIndexChange}
7575
initialLayout={initialLayout}
76+
bounces // only iOS
7677
/>
7778
);
7879
}

src/PagerScroll.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export default class PagerScroll<T: *> extends React.Component<
3232

3333
static defaultProps = {
3434
canJumpToTab: () => true,
35+
bounces: false,
3536
};
3637

3738
constructor(props: Props<T>) {
@@ -140,6 +141,7 @@ export default class PagerScroll<T: *> extends React.Component<
140141
navigationState,
141142
onSwipeStart,
142143
onSwipeEnd,
144+
bounces,
143145
} = this.props;
144146

145147
return (
@@ -153,8 +155,8 @@ export default class PagerScroll<T: *> extends React.Component<
153155
scrollToOverflowEnabled
154156
scrollEnabled={this.props.swipeEnabled}
155157
automaticallyAdjustContentInsets={false}
156-
bounces={false}
157-
alwaysBounceHorizontal={false}
158+
bounces={bounces}
159+
alwaysBounceHorizontal={bounces}
158160
scrollsToTop={false}
159161
showsHorizontalScrollIndicator={false}
160162
scrollEventThrottle={1}

src/PropTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export const PagerRendererPropType = {
4040
jumpTo: PropTypes.func.isRequired,
4141
animationEnabled: PropTypes.bool,
4242
swipeEnabled: PropTypes.bool,
43+
bounces: PropTypes.bool.isRequired,
4344
useNativeDriver: PropTypes.bool,
4445
onSwipeStart: PropTypes.func,
4546
onSwipeEnd: PropTypes.func,

src/TabBar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ export default class TabBar<T: *> extends React.Component<Props<T>, State> {
213213
const translateX = Animated.multiply(
214214
Animated.multiply(
215215
position.interpolate({
216-
inputRange: [0, navigationState.routes.length - 1],
217-
outputRange: [0, navigationState.routes.length - 1],
216+
inputRange: [-1, navigationState.routes.length],
217+
outputRange: [-1, navigationState.routes.length],
218218
extrapolate: 'clamp',
219219
}),
220220
width

src/TypeDefinitions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export type PagerRendererProps<T> = PagerCommonProps<T> & {
4646
export type PagerCommonProps<T> = {
4747
animationEnabled?: boolean,
4848
swipeEnabled?: boolean,
49+
bounces?: boolean,
4950
onSwipeStart?: () => mixed,
5051
onSwipeEnd?: () => mixed,
5152
onAnimationEnd?: () => mixed,

0 commit comments

Comments
 (0)