Skip to content

[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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

buuhuu
Copy link
Contributor

@buuhuu buuhuu commented Jun 18, 2017

This implements programmatic navigation between pages. It's useful in case the app requires to have buttons to navigate between the images beside the swipe gesture.

@PeterStaev PeterStaev added this to the 2.1.0 milestone Jun 18, 2017

private get _animateLoadPage(): boolean {
const current: boolean = this._animateLoadPageValue;
this._animateLoadPageValue = false;
Copy link
Owner

Choose a reason for hiding this comment

The 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?

@@ -27,6 +32,9 @@ export class ImageSwipe extends ScrollView {

public ios: any; /* UIScrollView */
public android: any; /* android.support.v4.view.ViewPager */

public nextPage(): void;
Copy link
Owner

Choose a reason for hiding this comment

The 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 public scrollToPage(pageNumber: number, animated?: boolean)? This will allow much broader cases than just +1 and -1 for pages. Also will allow the user to control whether this is animated or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

@@ -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 {
Copy link
Owner

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)?

Copy link
Contributor Author

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.

@@ -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 {
Copy link
Owner

Choose a reason for hiding this comment

The 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 ImageSwipe class. But seems there is a bug in {N} that does not copy static objects from the base class. So I suggest for now to remove this and have it available as part of the main class later once the bug is fixed. Or for now we can add the property in the platform specific files and change its name to not be prefixed with _ since now it will be available for outside usage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Owner

Choose a reason for hiding this comment

The 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:
NativeScript/android#783
NativeScript/ios-jsc#773

@PeterStaev PeterStaev modified the milestones: 2.1.0, Backlog Oct 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants