diff --git a/image-swipe-common.ts b/image-swipe-common.ts index e7ebb6d..0151fe2 100644 --- a/image-swipe-common.ts +++ b/image-swipe-common.ts @@ -21,7 +21,7 @@ import { ImageSwipe as ImageSwipeDefinition } from "."; export * from "ui/scroll-view"; -export class ImageSwipeBase extends ScrollView implements ImageSwipeDefinition { +export abstract class ImageSwipeBase extends ScrollView implements ImageSwipeDefinition { public static pageChangedEvent: string = "pageChanged"; public static _imageCache: Cache; @@ -42,6 +42,14 @@ export class ImageSwipeBase extends ScrollView implements ImageSwipeDefinition { public _getDataItem(index: number): any { return this.isItemsSourceIn ? (this.items as ItemsSource).getItem(index) : this.items[index]; } + + public nextPage(): void { + this.pageNumber ++; + } + + public prevPage(): void { + this.pageNumber --; + } } export const pageNumberProperty = new CoercibleProperty({ diff --git a/image-swipe.android.ts b/image-swipe.android.ts index 60ed9c8..fc03348 100644 --- a/image-swipe.android.ts +++ b/image-swipe.android.ts @@ -67,6 +67,14 @@ export class ImageSwipe extends ImageSwipeBase { // Coerce selected index after we have set items to native view. pageNumberProperty.coerce(this); } + + public nextPage(): void { + this.pageNumber ++; + } + + public prevPage(): void { + this.pageNumber --; + } } @Interfaces([android.support.v4.view.ViewPager.OnPageChangeListener]) diff --git a/image-swipe.d.ts b/image-swipe.d.ts index 56307f3..4a48df0 100644 --- a/image-swipe.d.ts +++ b/image-swipe.d.ts @@ -17,6 +17,11 @@ import { EventData } from "data/observable"; import { CoercibleProperty, Property } from "ui/core/view"; import { ItemsSource } from "ui/list-picker"; import { ScrollView } from "ui/scroll-view"; +import { Cache } from "ui/image-cache"; + +export class ImageSwipeBase { + public static _imageCache: Cache; +} export class ImageSwipe extends ScrollView { public static pageChangedEvent: string; @@ -27,6 +32,9 @@ export class ImageSwipe extends ScrollView { public ios: any; /* UIScrollView */ public android: any; /* android.support.v4.view.ViewPager */ + + public nextPage(): void; + public prevPage(): void; } export interface PageChangeEventData extends EventData { diff --git a/image-swipe.ios.ts b/image-swipe.ios.ts index 7d74df2..d5cba78 100644 --- a/image-swipe.ios.ts +++ b/image-swipe.ios.ts @@ -23,6 +23,7 @@ export class ImageSwipe extends ImageSwipeBase { private _views: Array<{ view: UIView; imageView: UIImageView; zoomDelegate: UIScrollViewZoomDelegateImpl }>; private _delegate: UIScrollViewPagedDelegate; + private _animateLoadPageValue: boolean = false; constructor() { super(); @@ -85,7 +86,7 @@ export class ImageSwipe extends ImageSwipeBase { const pageWidth = scrollView.frame.size.width; if (!this.isScrollingIn) { - scrollView.contentOffset = CGPointMake(value * pageWidth, 0); + scrollView.setContentOffsetAnimated(CGPointMake(value * pageWidth, 0), this._animateLoadPage); } for (let loop = 0; loop < value - 1; loop++) { @@ -135,6 +136,26 @@ export class ImageSwipe extends ImageSwipeBase { imageView.frame = contentsFrame; } + public nextPage(): void { + this._animateLoadPage = true; + super.nextPage(); + } + + public prevPage(): void { + this._animateLoadPage = true; + super.prevPage(); + } + + private get _animateLoadPage(): boolean { + const current: boolean = this._animateLoadPageValue; + this._animateLoadPageValue = false; + return current; + } + + private set _animateLoadPage(value: boolean) { + this._animateLoadPageValue = value; + } + private _resizeNativeViews(page: number) { if (page < 0 || page >= this.items.length) { // Outside Bounds return; @@ -300,6 +321,10 @@ class UIScrollViewPagedDelegate extends NSObject implements UIScrollViewDelegate this._owner.get().isScrollingIn = true; } + public scrollViewDidEndScrollingAnimation(scrollView: UIScrollView) { + this._owner.get().isScrollingIn = false; + } + public scrollViewDidEndDecelerating(scrollView: UIScrollView) { const pageWidth = scrollView.frame.size.width; const owner = this._owner.get();