PeterStaev / nativescript-image-swipe

A NativeScript widget to easily :point_up_2: and :mag: through a list of images
Apache License 2.0
35 stars 21 forks source link

Plain Nativescript (Pure Javascript) usage demo or example in documentation #37

Closed marcelbonfim182 closed 5 years ago

marcelbonfim182 commented 5 years ago

I installed the plugin and tried to run the following code in plain nativescript (pure javascript), but only black screen appears.

`const Observable = require ("tns-core-modules/data/observable").Observable; const ObservableArray = require("tns-core-modules/data/observable-array").ObservableArray; const Page = require("tns-core-modules/ui/page").Page;

const PageChangeEventData = require ("nativescript-image-swipe");`

`function onNavigatingTo(args) { page = args.object; page.bindingContext = new GaleriadeimagensViewModel();

items = new ObservableArray(items);

items = [ 
    {
        imageUrl: "http://www.mesmeracomunicacao.com.br/wp-content/uploads/2014/09/Delta-Rock-in-Rio.jpg"
    },
    {
        mageUrl: "http://www.mesmeracomunicacao.com.br/wp-content/uploads/2014/09/Delta-Rock-in-Rio.jpg"        },
    {
        imageUrl: "http://www.mesmeracomunicacao.com.br/wp-content/uploads/2014/09/Delta-Rock-in-Rio.jpg"
    },
    {
        imageUrl: "http://www.mesmeracomunicacao.com.br/wp-content/uploads/2014/09/Delta-Rock-in-Rio.jpg"
    },
    {
        imageUrl: "http://www.mesmeracomunicacao.com.br/wp-content/uploads/2014/09/Delta-Rock-in-Rio.jpg"
    },
    {
        imageUrl: "http://www.mesmeracomunicacao.com.br/wp-content/uploads/2014/09/Delta-Rock-in-Rio.jpg"
    },
    {
        imageUrl: "http://www.mesmeracomunicacao.com.br/wp-content/uploads/2014/09/Delta-Rock-in-Rio.jpg"
    },
    {
        imageUrl: "http://www.mesmeracomunicacao.com.br/wp-content/uploads/2014/09/Delta-Rock-in-Rio.jpg"
    }];

items = new ObservableArray(items);

viewModel = new Observable();
viewModel.set("items", items);
viewModel.set("pageNumber", 3);

page.bindingContext = viewModel;

}

exports.onNavigatingTo = onNavigatingTo;`

`

`

PeterStaev commented 5 years ago

Hey @marcelbonfim182 , your code is a total mess. You are double setting the bindingContext, you have bound some events that are not present in your code.

Here is a running sample of your code with cleaned up things: https://play.nativescript.org/?template=play-js&id=6b8vGd

For future please refer to the demo projects in the repo and the readme in order to understand how the plugin is to be used. Those are there for a reason!

marcelbonfim182 commented 5 years ago

Hello, it worked perfectly now! Thank you very much for your support!