esolution-nativescript-photoviewer
Version:
A simple Photo-viewer component for NativeScript based on NYTPhotoViewer pod for iOS and ImageGalleryViewer for Android.
60 lines • 2.83 kB
JavaScript
import { Application } from "@nativescript/core";
import { PaletteType } from "./photoviewer.common";
export * from './photoviewer.common';
export class PhotoViewer {
constructor() {
this.onActivityResult = (args) => {
if (args.requestCode === PhotoViewer.CLOSE_PHOTO_REQUEST) {
this._currentResolve();
this._currentResolve = undefined;
Application.android.off("activityResult", this.onActivityResult);
}
};
}
showGallery(imagesArray, options) {
var photosArray = new java.util.ArrayList();
imagesArray.forEach((imgUrl) => {
photosArray.add(imgUrl);
});
let startIndex = options.startIndex || 0;
let paletteType = options.android.paletteType || null;
let showAlbum = options.android.showAlbum || false;
let intent;
Application.android.on("activityResult", this.onActivityResult);
return new Promise((resolve) => {
this._currentResolve = resolve;
if (!showAlbum) {
intent = new android.content.Intent(Application.android.foregroundActivity, com.etiennelawlor.imagegallery.library.activities.FullScreenImageGalleryActivity.class);
}
else {
intent = new android.content.Intent(Application.android.foregroundActivity, com.etiennelawlor.imagegallery.library.activities.ImageGalleryActivity.class);
}
intent.putStringArrayListExtra("images", photosArray);
intent.putExtra("position", startIndex);
if (paletteType) {
intent.putExtra("palette_color_type", getPaletteType(paletteType));
}
Application.android.foregroundActivity.startActivityForResult(intent, PhotoViewer.CLOSE_PHOTO_REQUEST);
});
}
}
PhotoViewer.CLOSE_PHOTO_REQUEST = 9191;
function getPaletteType(paletteType) {
switch (paletteType) {
case PaletteType.Vibrant:
return com.etiennelawlor.imagegallery.library.enums.PaletteColorType.VIBRANT;
case PaletteType.LightVibrant:
return com.etiennelawlor.imagegallery.library.enums.PaletteColorType.LIGHT_VIBRANT;
case PaletteType.DarkVibrant:
return com.etiennelawlor.imagegallery.library.enums.PaletteColorType.DARK_VIBRANT;
case PaletteType.Muted:
return com.etiennelawlor.imagegallery.library.enums.PaletteColorType.MUTED;
case PaletteType.LightMuted:
return com.etiennelawlor.imagegallery.library.enums.PaletteColorType.LIGHT_MUTED;
case PaletteType.DarkMuted:
return com.etiennelawlor.imagegallery.library.enums.PaletteColorType.DARK_MUTED;
default:
return null;
}
}
//# sourceMappingURL=photoviewer.android.js.map