nativescript-photoviewer
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -9,12 +9,91 @@ var frameModule = require("ui/frame"); | ||
}); | ||
var startIndex = this._startIndex || 0; | ||
var paletteType = this._paletteType || null ; | ||
var showAlbum = this._showAlbum || false; | ||
var activity = frameModule.topmost().android.activity; | ||
var intent = new android.content.Intent(activity, com.etiennelawlor.imagegallery.library.activities.ImageGalleryActivity.class); | ||
intent.putStringArrayListExtra("images", photosArray); | ||
//intent.putExtra("palette_color_type", com.etiennelawlor.imagegallery.library.enums.PaletteColorType.MUTED); | ||
if(!showAlbum) | ||
_android = new android.content.Intent(activity, com.etiennelawlor.imagegallery.library.activities.FullScreenImageGalleryActivity.class); | ||
else | ||
_android = new android.content.Intent(activity, com.etiennelawlor.imagegallery.library.activities.ImageGalleryActivity.class); | ||
_android.putStringArrayListExtra("images", photosArray); | ||
_android.putExtra("position", startIndex); | ||
if(paletteType) | ||
_android.putExtra("palette_color_type", getPaletteType(paletteType)); | ||
activity.startActivity(intent); | ||
activity.startActivity(_android); | ||
}; | ||
function getPaletteType(paletteType){ | ||
switch (paletteType) { | ||
case 'VIBRANT': | ||
return com.etiennelawlor.imagegallery.library.enums.PaletteColorType.VIBRANT; | ||
break; | ||
case 'LIGHT_VIBRANT': | ||
return com.etiennelawlor.imagegallery.library.enums.PaletteColorType.LIGHT_VIBRANT; | ||
break; | ||
case 'DARK_VIBRANT': | ||
return com.etiennelawlor.imagegallery.library.enums.PaletteColorType.DARK_VIBRANT; | ||
break; | ||
case 'MUTED': | ||
return com.etiennelawlor.imagegallery.library.enums.PaletteColorType.MUTED; | ||
break; | ||
case 'LIGHT_MUTED': | ||
return com.etiennelawlor.imagegallery.library.enums.PaletteColorType.LIGHT_MUTED; | ||
break; | ||
case 'DARK_MUTED': | ||
return com.etiennelawlor.imagegallery.library.enums.PaletteColorType.DARK_MUTED; | ||
break; | ||
default: | ||
return null; | ||
break; | ||
} | ||
} | ||
function PhotoViewer() { | ||
Object.defineProperty(PhotoViewer.prototype, "android", { | ||
get: function () { | ||
return this._android; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(PhotoViewer.prototype, "startIndex", { | ||
get: function () { | ||
return this._startIndex; | ||
}, | ||
set: function (value) { | ||
this._startIndex = value; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(PhotoViewer.prototype, "paletteType", { | ||
get: function () { | ||
return this._paletteType; | ||
}, | ||
set: function (value) { | ||
this._paletteType = value; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(PhotoViewer.prototype, "showAlbum", { | ||
get: function () { | ||
return this._showAlbum; | ||
}, | ||
set: function (value) { | ||
this._showAlbum = value; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
if (!this instanceof PhotoViewer) { | ||
@@ -21,0 +100,0 @@ return new PhotoViewer(); |
@@ -5,3 +5,3 @@ var imageSource = require("image-source"); | ||
PhotoViewer.prototype.showViewer = function(imagesArray, startIndex) { | ||
PhotoViewer.prototype.showViewer = function(imagesArray) { | ||
var currentViewController = frameModule.topmost().currentPage; | ||
@@ -11,2 +11,5 @@ var photosArray = NSMutableArray.alloc().init(); | ||
var startIndex = that._startIndex || 0; | ||
var completitionCallback = that._completitionCallback || null; | ||
imagesArray.forEach(function(imageItem) { | ||
@@ -48,9 +51,11 @@ | ||
var dataSource = NYTPhotoViewerArrayDataSource.dataSourceWithPhotos(photosArray); | ||
startIndex = startIndex ? startIndex : 0; | ||
var photosViewController = NYTPhotosViewController.alloc().initWithDataSourceInitialPhotoIndexDelegate(dataSource, startIndex, null); | ||
var self = frameModule.topmost().ios; | ||
var photosViewController = NYTPhotosViewController.alloc().initWithDataSourceInitialPhotoIndexDelegate(dataSource, startIndex, self); | ||
UIApplication.sharedApplication.keyWindow.rootViewController.presentViewControllerAnimatedCompletion(photosViewController, true, completitionCallback); | ||
this._ios = photosViewController; | ||
UIApplication.sharedApplication.keyWindow.rootViewController.presentViewControllerAnimatedCompletion(photosViewController, true, null); | ||
}; | ||
function attributedString(text, color, fontFamily, fontSize) { | ||
@@ -185,3 +190,25 @@ var attrString = NSString.stringWithString(text || ""); | ||
Object.defineProperty(PhotoViewer.prototype, "startIndex", { | ||
get: function () { | ||
return this._startIndex; | ||
}, | ||
set: function (value) { | ||
this._startIndex = value; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(PhotoViewer.prototype, "completitionCallback", { | ||
get: function () { | ||
return this._completitionCallback; | ||
}, | ||
set: function (value) { | ||
this._completitionCallback = value; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
if (!this instanceof PhotoViewer) { | ||
@@ -188,0 +215,0 @@ return new PhotoViewer(); |
@@ -5,3 +5,3 @@ { | ||
"main": "index", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"nativescript": { | ||
@@ -8,0 +8,0 @@ "platforms": { |
@@ -16,3 +16,3 @@ # NativeScript PhotoViewer | ||
## Installation | ||
Run ```npm i nativescript-photoviewer``` in your ROOT directory of your project. | ||
Run `npm i nativescript-photoviewer` in your ROOT directory of your project. | ||
@@ -23,13 +23,30 @@ ## Limitations | ||
## Usage | ||
The usage is very simple. Require "nativescript-photoviewer" module and create a instance of it. Call the ```showViewer(array)``` function to present the photoViewer. | ||
The ```showViewer(ARRAY, <INDEX>)``` function accepts a two parameters on iOS and one on Android. The first one is allways an Array. The Array can contain one, or a mixture, of the following types: | ||
The usage is very simple. Require "nativescript-photoviewer" module and create a instance of it. Call the `showViewer(array)` function to present the photoViewer. | ||
The `showViewer(ARRAY)` function accepts a two parameters on iOS and one on Android. The first one is allways an Array. The Array can contain one, or a mixture, of the following types: | ||
- String URLs that point to external images (iOS & Android) | ||
- Custom defined objects that contain image-data (image/imageURL, title, summary, credit) (iOS only) | ||
- Objects that conform to the ```NYTPhoto``` protocol (see the cocoapod documentation for more info - very similar to the above option) (iOS only) | ||
- Objects that conform to the `NYTPhoto` protocol (see the cocoapod documentation for more info - very similar to the above option) (iOS only) | ||
When using the second option, properties that one can use are defined below in the second example. The ```image``` conforms to the UIImage object, while the ```imageURL``` is a string containing the URL of the image. | ||
If ```imageURL``` is set, then ```image``` is ignored. You can also customize fontFamily, fontSize and color of the caption texts. FontFamily applies to all captions, size and color are caption-specific. | ||
When using the second option, properties that one can use are defined below in the second example. The `image` conforms to the UIImage object, while the `imageURL` is a string containing the URL of the image. If `imageURL` is set, then `image` is ignored. | ||
You can also customize fontFamily, fontSize and color of the caption texts (iOS). FontFamily applies to all captions, size and color are caption-specific. | ||
The second parameter is only for iOS, and is an optional `index` of the image, so that the gallery can focus on that image when loaded. | ||
**Properties Android (Optional):** | ||
- `startIndex` (number): Optional index to start the gallery from (Fullscreen Image gallery only) | ||
- `showAlbum` (boolean): Set to `true` if you want to show the album first, otherwise `false` if you want to show fullscreen slides directly. | ||
- `paletteType` (string): Optional string value telling the fullscreen image gallery what type of background color palette to use (`VIBRANT`, `LIGHT_VIBRANT`, `DARK_VIBRANT`, `MUTED`, `LIGHT_MUTED`, `DARK_MUTED`) | ||
**Properties iOS (Optional):** | ||
- `startIndex`: Optional index to start the gallery from (Fullscreen Image gallery only) | ||
- `completitionCallback` Optional function to run after the gallery has done loading images and is showing | ||
- `fontFamily` (string): Font familiy to use for caption and titles | ||
- `titleFontSize` (number): Font-size for title | ||
- `summaryFontSize` (number): Font-size for summary-title | ||
- `creditFontSize` (number): Font-size for credits | ||
- `titleColor` (UIColor): Title color | ||
- `summaryColor` (UIColor): Summary-title color | ||
- `creditColor` (UIColor): Credits color | ||
**Methods:** | ||
- `showViewer(array)`: Method to call when you want to show the gallery. Mandatory param is an array of image urls or a custom image-object (iOS). | ||
```js | ||
@@ -45,6 +62,11 @@ // Require the module | ||
photoViewer.creditFontSize = 14; | ||
photoViewer.titleColor = UIColor.whiteColor(); | ||
photoViewer.summaryColor = UIColor.brownColor(); | ||
photoViewer.creditColor = UIColor.orangeColor(); | ||
photoViewer.titleColor = new colorModule.Color("#fff").ios; | ||
photoViewer.summaryColor = new colorModule.Color("#99813c").ios; | ||
photoViewer.creditColor = new colorModule.Color("#fed700").ios; | ||
photoViewer.completitionCallback = galleryLoaded; // iOS only | ||
photoViewer.paletteType = "LIGHT_MUTED"; // Android only | ||
photoViewer.showAlbum = false; // Android only (true = shows album first, false = shows fullscreen gallery directly) | ||
photoViewer.startIndex = 0; // start index for the fullscreen gallery | ||
// Image from object (iOS only) | ||
@@ -71,7 +93,20 @@ var testImage1 = { | ||
photoViewer.showViewer(myImages); | ||
function galleryShowing(){ | ||
console.log(`gallery Loaded`); | ||
} | ||
``` | ||
## Changelog | ||
** 1.3.0 ** | ||
**1.4.0** | ||
- Moved param for index to a property: `startIndex` | ||
- (iOS) Added property to set completitionCallback | ||
- (Android) Added option to show album first or go directly to fullscreen slides. More similar to iOS. | ||
- (Android) Added property to set background color palette for fullscreen slides. | ||
- Fixed demo app | ||
- Changed license to MIT | ||
**1.3.0** | ||
- Updated iOS pod to newer version (fixed minor breaking changes) | ||
- Added a second paramter to the `showViewer(ARRAY, INDEX?)` function. Makes the gallery init on that image: `photoViewer.showViewer(myImages, 2);` | ||
- Added a second paramter to the `showViewer(ARRAY, INDEX?)` function. Makes the gallery init on that image: `photoViewer.showViewer(myImages,1);` | ||
@@ -84,18 +119,2 @@ | ||
## Help | ||
I will accept pull requests that improve this and assign credit. | ||
All code is Apache 2.0 licensed. | ||
## License | ||
Copyright 2016 Nedim Erkocevic | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
I will accept pull requests that improve this and assign credit. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
18679
0
268
116