Skip to content

Commit 54346b2

Browse files
authored
feat(android): add support for overScrollMode (#192)
1 parent 1c8d24a commit 54346b2

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ const styles = StyleSheet.create({
125125
|`orientation: Orientation`|Set `horizontal` or `vertical` scrolling orientation (it does **not** work dynamically)|both
126126
|`transitionStyle: TransitionStyle`|Use `scroll` or `curl` to change transition style (it does **not** work dynamically)|iOS
127127
|`showPageIndicator: boolean`|Shows the dots indicator at the bottom of the view|iOS
128+
|`overScrollMode: OverScollMode`|Used to override default value of overScroll mode. Can be `auto`, `always` or `never`. Defaults to `auto`|Android
128129

129130
## Preview
130131

android/src/main/java/com/reactnativecommunity/viewpager/ReactViewPagerManager.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,17 @@ public void setOrientation(ViewPager2 viewPager, String value) {
147147
viewPager.setOrientation(value.equals("vertical") ? ViewPager2.ORIENTATION_VERTICAL : ORIENTATION_HORIZONTAL);
148148
}
149149

150+
@ReactProp(name = "overScrollMode")
151+
public void setOverScrollMode(ViewPager2 viewPager, String value) {
152+
View child = viewPager.getChildAt(0);
153+
if (value.equals("never")) {
154+
child.setOverScrollMode(ViewPager2.OVER_SCROLL_NEVER);
155+
} else if (value.equals("always")) {
156+
child.setOverScrollMode(ViewPager2.OVER_SCROLL_ALWAYS);
157+
} else {
158+
child.setOverScrollMode(ViewPager2.OVER_SCROLL_IF_CONTENT_SCROLLS);
159+
}
160+
}
150161

151162
@Override
152163
public Map getExportedCustomDirectEventTypeConstants() {

js/types.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export type PageSelectedEvent = SyntheticEvent<
4343

4444
export type TransitionStyle = 'scroll' | 'curl';
4545
export type Orientation = 'horizontal' | 'vertical';
46+
export type OverScrollMode = 'auto' | 'always' | 'never';
4647

4748
export type ViewPagerProps = $ReadOnly<{|
4849
/**
@@ -120,4 +121,8 @@ export type ViewPagerProps = $ReadOnly<{|
120121
orientation?: Orientation,
121122
transitionStyle?: TransitionStyle,
122123
showPageIndicator?: boolean,
124+
/**
125+
* Android only
126+
*/
127+
overScrollMode?: OverScrollMode,
123128
|}>;

typings/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ export interface ViewPagerProps {
9090
orientation?: 'horizontal' | 'vertical',
9191
transitionStyle?: 'scroll' | 'curl',
9292
showPageIndicator?: boolean,
93+
/**
94+
* Android only
95+
*/
96+
overScrollMode?: 'auto' | 'always' | 'never',
9397
}
9498

9599
declare class ViewPagerComponent extends React.Component<ViewPagerProps> {}

0 commit comments

Comments
 (0)