-
Notifications
You must be signed in to change notification settings - Fork 21
[Feature] Programmatic navigation between pages #7
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exporting the base class is a bad thing. Since we are extending the base class the cache should be visible on the main
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, +1 for the later approach. I think its more a typescript issue then {N} one.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here are the issues I've submitted for both android and ios runtime: |
||
| 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; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about instead of having just next and previous page navigation we change this to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if that works nicely with the way the prev and next views are loaded in iOS. I can give that a try. |
||
| public prevPage(): void; | ||
| } | ||
|
|
||
| export interface PageChangeEventData extends EventData { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a really "hidden" thing and it is not very intuitive that the flag will be lowered once it is returned. How about we change this to a simple property and just raise the flag before navigation and the lower it manually? |
||
| 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(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For animation to occur on android shouldn't this line: https://github.com/Buuhuu/nativescript-image-swipe/blob/dd03eb2f5a2cbf59e899945f0c46d949d20c2f7e/image-swipe.android.ts#L61 be changed to
this.nativeView.setCurrentItem(value, true)(so basically a similar approach as on iOS)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works quite well even without specifying that explicitly.