Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement _goToPrevPage() #167

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 73 additions & 61 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,69 +1,81 @@
declare module 'rn-viewpager' {
declare module "rn-viewpager" {
import * as React from "react";
import {
ImageURISource,
ViewProperties,
NativeScrollEvent,
NativeSyntheticEvent
} from "react-native";
import { ViewPagerAndroidOnPageScrollEventData } from "@react-native-community/viewpager";

import * as React from 'react';
import { ImageURISource, ViewProperties, NativeScrollEvent, NativeSyntheticEvent, ViewPagerAndroidOnPageScrollEventData } from 'react-native';

interface ViewPagerProps extends ViewProperties {
initialPage?: number;
keyboardDismissMode?: 'none' | 'on-drag';
onPageScroll?(e: ViewPagerAndroidOnPageScrollEventData): void;
onPageScrollStateChanged?(state: 'idle' | 'settling' | 'dragging'): void;
onPageSelected?(e: ViewPagerAndroidOnPageScrollEventData): void;
scrollEnabled?: boolean;
}

export class ViewPager extends React.Component<ViewPagerProps> {
setPage(selectedPage: number): void;
setPageWithoutAnimation(selectedPage: number): void;
}

interface IndicatorViewPagerProps extends ViewProperties {
indicator: React.ReactNode;
pagerStyle?: ViewProperties['style'];
autoPlayEnable?: boolean;
autoPlayInterval?: boolean;
horizontalScroll?: boolean;
interface ViewPagerProps extends ViewProperties {
initialPage?: number;
keyboardDismissMode?: "none" | "on-drag";
onPageScroll?(e: ViewPagerAndroidOnPageScrollEventData): void;
onPageScrollStateChanged?(state: "idle" | "settling" | "dragging"): void;
onPageSelected?(e: ViewPagerAndroidOnPageScrollEventData): void;
scrollEnabled?: boolean;
}

}
export class IndicatorViewPager extends React.Component<IndicatorViewPagerProps> {
setPage(selectedPage: number): void;
setPageWithoutAnimation(selectedPage: number): void;
}
export class ViewPager extends React.Component<ViewPagerProps> {
setPage(selectedPage: number): void;
setPageWithoutAnimation(selectedPage: number): void;
}

interface PagerDotIndicatorProps extends ViewProperties {
pageCount: number;
dotStyle?: ViewProperties['style'];
selectedDotStyle?: ViewProperties['style'];
hideSingle?: boolean;
}
interface IndicatorViewPagerProps extends ViewProperties {
indicator: React.ReactNode;
pagerStyle?: ViewProperties["style"];
autoPlayEnable?: boolean;
autoPlayInterval?: boolean;
horizontalScroll?: boolean;
}
export class IndicatorViewPager extends React.Component<
IndicatorViewPagerProps
> {
setPage(selectedPage: number): void;
setPageWithoutAnimation(selectedPage: number): void;
}

export class PagerDotIndicator extends React.Component<PagerDotIndicatorProps> {}
interface PagerDotIndicatorProps extends ViewProperties {
pageCount: number;
dotStyle?: ViewProperties["style"];
selectedDotStyle?: ViewProperties["style"];
hideSingle?: boolean;
}

interface PageTitleIndicatorProps extends ViewProperties {
titles: string[];
trackScroll?: boolean;
itemStyle?: ViewProperties['style'];
itemTextStyle?: ViewProperties['style'];
selectedItemTextStyle?: ViewProperties['style'];
selectedBorderStyle?: ViewProperties['style'];
renderTitle(index: number, title: string, isSelected: boolean): JSX.Element;
}
export class PagerTitleIndicator extends React.Component<PageTitleIndicatorProps> {}
export class PagerDotIndicator extends React.Component<
PagerDotIndicatorProps
> {}

interface PagerTabIndicatorProps extends ViewProperties {
tabs: Array<{
text: string,
iconSource: ImageURISource,
selectedIconSource: ImageURISource
}>;
itemStyle?: ViewProperties['style'];
selectedItemStyle?: ViewProperties['style'];
iconStyle?: ViewProperties['style'];
selectedIconStyle?: ViewProperties['style'];
textStyle?: ViewProperties['style'];
selectedTextStyle?: ViewProperties['style'];
changePageWithAnimation?: boolean;
}
interface PageTitleIndicatorProps extends ViewProperties {
titles: string[];
trackScroll?: boolean;
itemStyle?: ViewProperties["style"];
itemTextStyle?: ViewProperties["style"];
selectedItemTextStyle?: ViewProperties["style"];
selectedBorderStyle?: ViewProperties["style"];
renderTitle(index: number, title: string, isSelected: boolean): JSX.Element;
}
export class PagerTitleIndicator extends React.Component<
PageTitleIndicatorProps
> {}

export class PagerTabIndicator extends React.PureComponent<PagerTabIndicatorProps> {}
interface PagerTabIndicatorProps extends ViewProperties {
tabs: Array<{
text: string;
iconSource: ImageURISource;
selectedIconSource: ImageURISource;
}>;
itemStyle?: ViewProperties["style"];
selectedItemStyle?: ViewProperties["style"];
iconStyle?: ViewProperties["style"];
selectedIconStyle?: ViewProperties["style"];
textStyle?: ViewProperties["style"];
selectedTextStyle?: ViewProperties["style"];
changePageWithAnimation?: boolean;
}

export class PagerTabIndicator extends React.PureComponent<
PagerTabIndicatorProps
> {}
}
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@
"bugs": {
"url": "https://github.com/zbtang/React-Native-ViewPager/issues"
},
"homepage": "https://github.com/zbtang/React-Native-ViewPager#readme"
"homepage": "https://github.com/zbtang/React-Native-ViewPager#readme",
"dependencies": {
"@react-native-community/viewpager": "^1.1.7"
}
}
6 changes: 6 additions & 0 deletions viewpager/IndicatorViewPager.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default class IndicatorViewPager extends Component {
this._onPageScroll = this._onPageScroll.bind(this)
this._onPageSelected = this._onPageSelected.bind(this)
this._goToNextPage = this._goToNextPage.bind(this)
this._goToPrevPage = this._goToPrevPage.bind(this)
this._renderIndicator = this._renderIndicator.bind(this)
this.setPage = this.setPage.bind(this)
this.setPageWithoutAnimation = this.setPageWithoutAnimation.bind(this)
Expand Down Expand Up @@ -103,6 +104,11 @@ export default class IndicatorViewPager extends Component {
this.setPage(nextIndex)
}

_goToPrevPage() {
let nextIndex = (this._currentIndex - 1) % this._childrenCount
this.setPage(nextIndex < 0 ? this._childrenCount - 1 : nextIndex)
}

_startAutoPlay () {
if (this._timerId) clearInterval(this._timerId)
this._timerId = setInterval(this._goToNextPage, this.props.autoPlayInterval)
Expand Down
Loading