Skip to content

Commit 4bdffee

Browse files
authored
Merge pull request #42 from NativeScript/tsonevn_orientationchange
check device orientation
2 parents 5ca9435 + 1223d37 commit 4bdffee

File tree

4 files changed

+33
-14
lines changed

4 files changed

+33
-14
lines changed

nativescript-imagepicker/images.ios.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
"use strict";
22
var ui_frame = require("ui/frame");
3+
var application = require("application");
4+
var platform = require("platform");
35
var page;
46
var list;
57
var album;
68
function pageLoaded(args) {
79
page = args.object;
810
page.bindingContext = page.navigationContext;
911
list = page.getViewById("images-list");
12+
list.listViewLayout.spanCount = Math.floor(platform.screen.mainScreen.widthDIPs / 80);
13+
application.on("orientationChanged", function (e) {
14+
var currentPageWidth = platform.screen.mainScreen.heightDIPs;
15+
console.log(currentPageWidth);
16+
console.log(currentPageWidth);
17+
list.listViewLayout.spanCount = Math.floor(currentPageWidth / 80);
18+
});
1019
}
1120
exports.pageLoaded = pageLoaded;
1221
function done(args) {
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import ui_frame = require("ui/frame");
2+
import application = require("application");
3+
import platform = require("platform");
24

35
var page;
46
var list;
@@ -10,9 +12,14 @@ export function pageLoaded(args) {
1012
list = page.getViewById("images-list");
1113

1214
// Get the current Size, and then adjust the number of columns based on it...
13-
var size = iOSProperty(UIScreen, UIScreen.mainScreen).bounds.size.width;
14-
list.listViewLayout.spanCount = Math.floor(size / 80);
15+
list.listViewLayout.spanCount = Math.floor(platform.screen.mainScreen.widthDIPs/80);
1516

17+
application.on("orientationChanged", function(e:application.OrientationChangedEventData){
18+
var currentPageWidth = platform.screen.mainScreen.heightDIPs
19+
console.log(currentPageWidth);
20+
console.log(currentPageWidth);
21+
list.listViewLayout.spanCount = Math.floor(currentPageWidth/80);
22+
});
1623
}
1724

1825
export function done(args) {
@@ -21,13 +28,4 @@ export function done(args) {
2128
topmost.goBack();
2229

2330
page.bindingContext.imagePicker.done();
24-
}
25-
26-
function iOSProperty(_this, property) {
27-
if (typeof property === "function") {
28-
return property.call(_this);
29-
}
30-
else {
31-
return property;
32-
}
3331
}

nativescript-imagepicker/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
"main": "viewmodel.js",
2020
"devDependencies": {
21-
"tns-platform-declarations": "*",
21+
"tns-platform-declarations": "next",
2222
"typescript": "^2.0.3"
2323
},
2424
"scripts": {

nativescript-imagepicker/viewmodel.ios.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var ImagePicker = (function (_super) {
2828
ImagePicker.prototype.present = function () {
2929
var _this = this;
3030
if (this._resolve || this._reject) {
31-
return Promise.reject(new Error("Selection is allready in progress..."));
31+
return Promise.reject(new Error("Selection is already in progress..."));
3232
}
3333
else {
3434
return new Promise(function (resolve, reject) {
@@ -83,6 +83,13 @@ var ImagePicker = (function (_super) {
8383
enumerable: true,
8484
configurable: true
8585
});
86+
Object.defineProperty(ImagePicker.prototype, "newestFirst", {
87+
get: function () {
88+
return this._options && !!this._options.newestFirst;
89+
},
90+
enumerable: true,
91+
configurable: true
92+
});
8693
ImagePicker.prototype.cancel = function () {
8794
this.notifyCanceled();
8895
};
@@ -367,7 +374,12 @@ var AlbumPH = (function (_super) {
367374
this._setThumb = true;
368375
this.imagePicker.createPHImageThumb(this, asset);
369376
}
370-
this.assets.push(item);
377+
if (this.imagePicker.newestFirst) {
378+
this.assets.unshift(item);
379+
}
380+
else {
381+
this.assets.push(item);
382+
}
371383
};
372384
return AlbumPH;
373385
}(Album));

0 commit comments

Comments
 (0)