Skip to content
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

how to use plugin in angular/ionic 2 with types? #2

Open
joshgarwood opened this issue Oct 21, 2016 · 19 comments
Open

how to use plugin in angular/ionic 2 with types? #2

joshgarwood opened this issue Oct 21, 2016 · 19 comments
Assignees

Comments

@joshgarwood
Copy link

Hi there! I'm really excited to give this plugin a try, but was wondering if you have an example of how to use it with the types you've created? So for instance, would I import something like this:

import PhotoLibraryCorova from 'cordova-plugin-photo-library'

... I tried this and it didn't seem to work, but I'm pretty sure I'm not doing it correctly, ha.

Thanks for your time!

@viskin
Copy link
Member

viskin commented Oct 21, 2016

You doing it completely right for plugin that supports Ionic2. But Ionic 2 is very very new stuff which requires wrapper for each existing plugin. And such wrapper does not exist yet for my young library.

  • You can use the plugin directly, without importing. No typescript candies, but this should work. Just window.cordova.plugins.photoLibrary etc.
  • If I have time, I'll write a wrapper, which I hope will be accepted by ionic. The library does not have much stars yet, and I don't know is it enough to be accepted there. In theory, there's repository which called ionic-native. This is place where people add wrappers for their libraries, which enables syntax that you want to use (import PhotoLibraryCorova). The wrapper should be something like this:
@Plugin({
  name: 'PhotoLibrary',
  plugin: 'cordova-plugin-photo-library',
  pluginRef: 'cordova.plugins.photoLibrary',
  repo: 'https://github.com/terikon/cordova-plugin-photo-library',
  platforms: ['Android', 'Browser', 'iOS']
})
export class PhotoLibrary{
// blahblah this should not be complex
}

Please try the plugin using window.cordova, and if it will work for your project, I will appreciate an contribution to ionic-native.

I myself cannot give you a promise when I will add such wrapper.

@dnmd
Copy link

dnmd commented Nov 16, 2016

@joshgarwood did you get things working with Ionic 2? For me it only works after sanitizing URL's, see #15

@viskin
Copy link
Member

viskin commented Feb 20, 2017

Working on this. I have working ionic native wrapper. What's left is documenting it and publishing a PR.

@viskin viskin self-assigned this Feb 20, 2017
@arberkryeziu
Copy link

arberkryeziu commented Feb 20, 2017

@viskin how can we import the plugin in ionic 2 ?
I tried with
import {PhotoLibrary} from '../../../plugins/cordova-plugin-photo-library/www/PhotoLibrary.js' with no luck...

But I think PhotoLibrary.js is still not complete , right ? Are you following the ionic dev-guideline for the wrapper ?

https://github.com/driftyco/ionic-native/blob/master/DEVELOPER.md

@viskin
Copy link
Member

viskin commented Feb 21, 2017

@ArberK The usage will be

  import { PhotoLibrary } from 'ionic-native';

I implemented ionic-native wrapper, and submitted this PR to ionic. You still cannot use the wrapper until PR is approved, I hope this will happen soon.

@arberkryeziu
Copy link

arberkryeziu commented Feb 21, 2017

Can't I somehow use the plugin in ionic 2 with typescript till the plugin will be included in ionic-native ?

@viskin
Copy link
Member

viskin commented Feb 21, 2017

I didn't try this (using plain JS mostly), by this file is TypeScript ds file. As far as I understand, you shouldn't do any import. You should make TS compiler see this d.ts file (from tsconfig?), and then definitions will be attached to cordova.plugins.photoLibrary. In theory.
I use this d.ts file for vscode intellisense. It does work.

@viskin
Copy link
Member

viskin commented Feb 21, 2017

Maybe adding this to tsconfig.json will work:

"files": [
  "plugins/cordova-plugin-photo-library/PhotoLibrary.d.ts"
]

@viskin
Copy link
Member

viskin commented Feb 22, 2017

Added demo project for ionic2 (not yet approved PR).
https://github.com/terikon/photo-library-demo-ionic2
This includes online demo and permission handling.

@arberkryeziu
Copy link

Great work! Thank you...

Can you take a look at this ?
terikon/photo-library-demo-ionic2#1

@viskin
Copy link
Member

viskin commented Feb 25, 2017

no-ionic-native branch contains working typescript version that does not require ionic-native.
These are changes needed to make it work.

@arberkryeziu
Copy link

Thank you for doing this! Sadly, Im getting a runtime error after the application is started.
Cannot find module 'ionic-native'

(I just downloaded the branch, run on it npm install, and then deployed to my iPhone. )

@viskin
Copy link
Member

viskin commented Feb 26, 2017

Oops, ionic-native still should be present in package.json. Fixed this.

@arberkryeziu
Copy link

Ok, i did give it a try on my iPhone. Its very unresponsive. At the beginning one can scroll just a litttle, but after 5 sec it becomes unresponsive till it crashes. I can see the lists of photos are created (however, without any photos. Photos somehow are not displayed in my iPhone, I dont know why). However, in the iPhone simulator, where I have ca. 10 photos, it seems to work perfectly fine, also the images are correctly shown.

@viskin
Copy link
Member

viskin commented Feb 26, 2017

Well, filling in all the photos to one giant list is not good approach (that's what demo does). Android handles this pretty well, but iOS uses old UIWebView component which is bad. It will be interesting to experiment with new WKWebView which should be more close to Android in terms of performance and reliability. I'll give this a try.
The really correct approach (which we implemented in our app with react) is to show images in visualized list. I could not make ionic's VirtualScroll component work as expected. But I will add react demo later.

@arberkryeziu
Copy link

arberkryeziu commented Feb 26, 2017

I tried to install WKWebView and used VirtualScroll. It seems to work well, in my simulator. In my iPhone, its responsive and fast also. It does not hang, it does not crach, scrolling is fine. But in my iPhone 5s, I have the problem of images not showing up, its just the list. Can you test this on your iPhone?

I also found this approach http://rintoj.github.io/angular2-virtual-scroll/

Do you think it would be helpfull in our case ?

@viskin
Copy link
Member

viskin commented Feb 26, 2017

Cool, I will try both - WKWebView and angular2-virtual-scroll.

@viskin
Copy link
Member

viskin commented Feb 26, 2017

angular2-virtual-scroll looks very promising, but I could not make it work with ionic in this branch.

@viskin
Copy link
Member

viskin commented Feb 27, 2017

Well, sad to say, but WKWebView still does not provide support for custom schemas. See this issue.
I will open a new issue for this, even though the issue seems to be completely in hands of apache/ionic: #41

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

No branches or pull requests

4 participants