mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
Fixed issue with binding when binding to a falsy object (also added types.isNullOrundefined function).
This commit is contained in:
@ -2,6 +2,7 @@
|
|||||||
import appModule = require("application");
|
import appModule = require("application");
|
||||||
import fileSystem = require("file-system");
|
import fileSystem = require("file-system");
|
||||||
import utils = require("utils/utils");
|
import utils = require("utils/utils");
|
||||||
|
import types = require("utils/types");
|
||||||
import definition = require("camera");
|
import definition = require("camera");
|
||||||
import common = require("./camera-common");
|
import common = require("./camera-common");
|
||||||
|
|
||||||
@ -14,7 +15,7 @@ export var takePicture = function (options?: definition.CameraOptions): Promise<
|
|||||||
if (options) {
|
if (options) {
|
||||||
var reqWidth = options.width ? options.width * density : 0;
|
var reqWidth = options.width ? options.width * density : 0;
|
||||||
var reqHeight = options.height ? options.height * density : reqWidth;
|
var reqHeight = options.height ? options.height * density : reqWidth;
|
||||||
var shouldKeepAspectRatio = (options.keepAspectRatio === null || options.keepAspectRatio === undefined) ? true : options.keepAspectRatio;
|
var shouldKeepAspectRatio = types.isNullOrUndefined(options.keepAspectRatio) ? true : options.keepAspectRatio;
|
||||||
}
|
}
|
||||||
var takePictureIntent = new android.content.Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
|
var takePictureIntent = new android.content.Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
|
||||||
var dateStamp = createDateTimeStamp();
|
var dateStamp = createDateTimeStamp();
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
import frame = require("ui/frame");
|
import frame = require("ui/frame");
|
||||||
import definition = require("camera");
|
import definition = require("camera");
|
||||||
import common = require("./camera-common");
|
import common = require("./camera-common");
|
||||||
|
import types = require("utils/types");
|
||||||
|
|
||||||
class UIImagePickerControllerDelegateImpl extends NSObject implements UIImagePickerControllerDelegate {
|
class UIImagePickerControllerDelegateImpl extends NSObject implements UIImagePickerControllerDelegate {
|
||||||
public static ObjCProtocols = [UIImagePickerControllerDelegate];
|
public static ObjCProtocols = [UIImagePickerControllerDelegate];
|
||||||
@ -26,7 +27,7 @@ class UIImagePickerControllerDelegateImpl extends NSObject implements UIImagePic
|
|||||||
if (options) {
|
if (options) {
|
||||||
this._width = options.width;
|
this._width = options.width;
|
||||||
this._height = options.height;
|
this._height = options.height;
|
||||||
this._keepAspectRatio = (options.keepAspectRatio === null || options.keepAspectRatio === undefined) ? true : options.keepAspectRatio;
|
this._keepAspectRatio = types.isNullOrUndefined(options.keepAspectRatio) ? true : options.keepAspectRatio;
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -76,7 +77,7 @@ export var takePicture = function (options?: definition.CameraOptions): Promise<
|
|||||||
if (options) {
|
if (options) {
|
||||||
reqWidth = options.width || 0;
|
reqWidth = options.width || 0;
|
||||||
reqHeight = options.height || reqWidth;
|
reqHeight = options.height || reqWidth;
|
||||||
keepAspectRatio = (options.keepAspectRatio === null || options.keepAspectRatio === undefined) ? true : options.keepAspectRatio;
|
keepAspectRatio = types.isNullOrUndefined(options.keepAspectRatio) ? true : options.keepAspectRatio;
|
||||||
}
|
}
|
||||||
if (reqWidth && reqHeight) {
|
if (reqWidth && reqHeight) {
|
||||||
listener = UIImagePickerControllerDelegateImpl.new().initWithCallbackAndOptions(resolve, { width: reqWidth, height: reqHeight, keepAspectRatio: keepAspectRatio });
|
listener = UIImagePickerControllerDelegateImpl.new().initWithCallbackAndOptions(resolve, { width: reqWidth, height: reqHeight, keepAspectRatio: keepAspectRatio });
|
||||||
|
@ -44,7 +44,7 @@ export class Bindable extends dependencyObservable.DependencyObservable implemen
|
|||||||
if (!bindingSource) {
|
if (!bindingSource) {
|
||||||
bindingSource = this.bindingContext;
|
bindingSource = this.bindingContext;
|
||||||
}
|
}
|
||||||
if (bindingSource) {
|
if (!types.isNullOrUndefined(bindingSource)) {
|
||||||
binding.bind(bindingSource);
|
binding.bind(bindingSource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -109,7 +109,7 @@ export class Bindable extends dependencyObservable.DependencyObservable implemen
|
|||||||
" targetProperty: " + binding.options.targetProperty +
|
" targetProperty: " + binding.options.targetProperty +
|
||||||
" to the changed context: " + newValue, trace.categories.Binding);
|
" to the changed context: " + newValue, trace.categories.Binding);
|
||||||
binding.unbind();
|
binding.unbind();
|
||||||
if (newValue) {
|
if (!types.isNullOrUndefined(newValue)) {
|
||||||
binding.bind(newValue);
|
binding.bind(newValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -134,7 +134,7 @@ export class Binding {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public bind(obj: Object) {
|
public bind(obj: Object) {
|
||||||
if (!obj) {
|
if (types.isNullOrUndefined(obj)) {
|
||||||
throw new Error("Expected valid object reference as a source in the Binding.bind method.");
|
throw new Error("Expected valid object reference as a source in the Binding.bind method.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -344,7 +344,7 @@ export class Binding {
|
|||||||
currentObject = currentObject[properties[i]];
|
currentObject = currentObject[properties[i]];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentObject !== undefined && currentObject !== null) {
|
if (!types.isNullOrUndefined(currentObject)) {
|
||||||
options = {
|
options = {
|
||||||
instance: new WeakRef(currentObject),
|
instance: new WeakRef(currentObject),
|
||||||
property: properties[properties.length - 1]
|
property: properties[properties.length - 1]
|
||||||
|
@ -4,6 +4,7 @@ import dependencyObservable = require("ui/core/dependency-observable");
|
|||||||
import view = require("ui/core/view");
|
import view = require("ui/core/view");
|
||||||
import trace = require("trace");
|
import trace = require("trace");
|
||||||
import imageSource = require("image-source");
|
import imageSource = require("image-source");
|
||||||
|
import types = require("utils/types");
|
||||||
|
|
||||||
var VIEWS_STATES = "_viewStates";
|
var VIEWS_STATES = "_viewStates";
|
||||||
|
|
||||||
@ -436,7 +437,7 @@ export class TabView extends common.TabView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _setNativeSelectedIndex(index: number) {
|
private _setNativeSelectedIndex(index: number) {
|
||||||
if (index === undefined || index === null) {
|
if (types.isNullOrUndefined(index)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import trace = require("trace");
|
|||||||
import utils = require("utils/utils");
|
import utils = require("utils/utils");
|
||||||
import view = require("ui/core/view");
|
import view = require("ui/core/view");
|
||||||
import imageSource = require("image-source");
|
import imageSource = require("image-source");
|
||||||
|
import types = require("utils/types");
|
||||||
|
|
||||||
// merge the exports of the common file with the exports of this file
|
// merge the exports of the common file with the exports of this file
|
||||||
declare var exports;
|
declare var exports;
|
||||||
@ -206,7 +207,7 @@ export class TabView extends common.TabView {
|
|||||||
|
|
||||||
var newIndex = data.newValue;
|
var newIndex = data.newValue;
|
||||||
trace.write("TabView._onSelectedIndexPropertyChangedSetNativeValue(" + newIndex + ")", trace.categories.Debug);
|
trace.write("TabView._onSelectedIndexPropertyChangedSetNativeValue(" + newIndex + ")", trace.categories.Debug);
|
||||||
if (newIndex === undefined || newIndex === null) {
|
if (types.isNullOrUndefined(newIndex)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
9
utils/types.d.ts
vendored
9
utils/types.d.ts
vendored
@ -28,12 +28,19 @@
|
|||||||
export function isUndefined(value: any): boolean;
|
export function isUndefined(value: any): boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function that checks if something is defined (not null and not undefined).
|
* A function that checks if something is defined (not undefined).
|
||||||
* @param value The value which will be checked.
|
* @param value The value which will be checked.
|
||||||
* Returns true if value is defined.
|
* Returns true if value is defined.
|
||||||
*/
|
*/
|
||||||
export function isDefined(value: any): boolean;
|
export function isDefined(value: any): boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A function that checks if something is not defined (null or undefined).
|
||||||
|
* @param value The value which will be checked.
|
||||||
|
* Returns true if value is null or undefined.
|
||||||
|
*/
|
||||||
|
export function isNullOrUndefined(value: any): boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function that checks if something is a valid function.
|
* A function that checks if something is a valid function.
|
||||||
* @param value The value which will be checked.
|
* @param value The value which will be checked.
|
||||||
|
@ -21,6 +21,10 @@ export function isDefined(value: any): boolean {
|
|||||||
return typeof value !== "undefined";
|
return typeof value !== "undefined";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isNullOrUndefined(value: any): boolean {
|
||||||
|
return (typeof value === "undefined") || (value === null);
|
||||||
|
}
|
||||||
|
|
||||||
export function verifyCallback(value: any) {
|
export function verifyCallback(value: any) {
|
||||||
if (value && !isFunction(value)) {
|
if (value && !isFunction(value)) {
|
||||||
throw new TypeError("Callback must be a valid function.");
|
throw new TypeError("Callback must be a valid function.");
|
||||||
|
Reference in New Issue
Block a user