Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ControlValueAccessor } from "@angular/forms";
import { View } from "tns-core-modules/ui/core/view";
import { View, unsetValue } from "tns-core-modules/ui/core/view";

import { isBlank } from "../../lang-facade";

export class BaseValueAccessor<TView extends View> implements ControlValueAccessor {
private pendingChangeNotification: any = 0;
Expand Down Expand Up @@ -28,5 +30,9 @@ export class BaseValueAccessor<TView extends View> implements ControlValueAccess
this.view.isEnabled = !isDisabled;
}

writeValue(_: any) { }
writeValue(_: any) {}

protected normalizeValue(value: any): any {
return isBlank(value) ? unsetValue : value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class CheckedValueAccessor extends BaseValueAccessor<Switch> { // tslint:
}

writeValue(value: any): void {
this.view.checked = value;
const normalized = super.normalizeValue(value);
this.view.checked = normalized;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class DateValueAccessor extends BaseValueAccessor<DatePicker> { // tslint
}

writeValue(value: any): void {
this.view.date = value;
const normalized = super.normalizeValue(value);
this.view.date = normalized;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class NumberValueAccessor extends BaseValueAccessor<Slider> { // tslint:d
}

writeValue(value: any): void {
this.view.value = value;
const normalized = super.normalizeValue(value);
this.view.value = normalized;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export class SelectedIndexValueAccessor extends BaseValueAccessor<SelectableView
private viewInitialized: boolean;

writeValue(value: any): void {
this.value = value;
const normalized = super.normalizeValue(value);
this.value = normalized;

if (this.viewInitialized) {
this.view.selectedIndex = this.value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class TextValueAccessor extends BaseValueAccessor<TextView> { // tslint:d
}

writeValue(value: any): void {
this.view.text = value;
const normalized = super.normalizeValue(value);
this.view.text = normalized;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class TimeValueAccessor extends BaseValueAccessor<TimePicker> { // tslint
}

writeValue(value: any): void {
this.view.time = value;
const normalized = super.normalizeValue(value);
this.view.time = normalized;
}
}