manijak / nativescript-photoviewer

A simple Photo-Viewer component for NativeScript.
Other
44 stars 24 forks source link

Typecript support #13

Closed sittingbool closed 6 years ago

sittingbool commented 7 years ago

Hey, are you planning on supporting typescript or even angular? Would be very nice

manijak commented 7 years ago

Not sure what you are after, the plugin should work fine in TypeScript & Angular-based projects.

sittingbool commented 7 years ago

It wont compile in typescript. Basically because type definitions are missing. Took me a while to figure out how to insert it but check on my fork, i added it there and then it can be imported by const PhotoViewer = require("nativescript-photoviewer");. Also the documentation on how to load images from the apps resources is not correct. It only works by using

const imageSourceModule = require("image-source");
...
let paths = ['~/images/file1.jpg', '~/images/file2.jpg'];
let photoViewer = new PhotoViewer();

        let images = [];

        if (typeof paths === 'string' ) {
            if ( paths.length > 0 ) {
                paths = [paths];
            } else {
                paths = [];
            }
        }

        paths.forEach(path => {

            let imageSource = imageSourceModule.fromFile(path);
            let img = {
                image: imageSource.ios
            };

            images.push(img);
        });

        photoViewer.showViewer(images);
manijak commented 6 years ago

I'm using this plugin my my own TypeScript based app, and no type definitions need to be added.

Include the plugin like this:

const PhotoViewer = require("nativescript-photoviewer");
...
let photoViewer = new PhotoViewer();
photoViewer.showViewer(imageList);

New version released, 1.4.0, demo and readme also updated.