mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00

* chore: move tns-core-modules to nativescript-core * chore: preparing compat generate script * chore: add missing definitions * chore: no need for http-request to be private * chore: packages chore * test: generate tests for tns-core-modules * chore: add anroid module for consistency * chore: add .npmignore * chore: added privateModulesWhitelist * chore(webpack): added bundle-entry-points * chore: scripts * chore: tests changed to use @ns/core * test: add scoped-packages test project * test: fix types * test: update test project * chore: build scripts * chore: update build script * chore: npm scripts cleanup * chore: make the compat pgk work with old wp config * test: generate diff friendly tests * chore: create barrel exports * chore: move files after rebase * chore: typedoc config * chore: compat mode * chore: review of barrels * chore: remove tns-core-modules import after rebase * chore: dev workflow setup * chore: update developer-workflow * docs: experiment with API extractor * chore: api-extractor and barrel exports * chore: api-extractor configs * chore: generate d.ts rollup with api-extractor * refactor: move methods inside Frame * chore: fic tests to use Frame static methods * refactor: create Builder class * refactor: use Builder class in tests * refactor: include Style in ui barrel * chore: separate compat build script * chore: fix tslint errors * chore: update NATIVESCRIPT_CORE_ARGS * chore: fix compat pack * chore: fix ui-test-app build with linked modules * chore: Application, ApplicationSettings, Connectivity and Http * chore: export Trace, Profiling and Utils * refactor: Static create methods for ImageSource * chore: fix deprecated usages of ImageSource * chore: move Span and FormattedString to ui * chore: add events-args and ImageSource to index files * chore: check for CLI >= 6.2 when building for IOS * chore: update travis build * chore: copy Pod file to compat package * chore: update error msg ui-tests-app * refactor: Apply suggestions from code review Co-Authored-By: Martin Yankov <m.i.yankov@gmail.com> * chore: typings and refs * chore: add missing d.ts files for public API * chore: adress code review FB * chore: update api-report * chore: dev-workflow for other apps * chore: api update * chore: update api-report
158 lines
5.1 KiB
TypeScript
158 lines
5.1 KiB
TypeScript
import {
|
|
TimePickerBase, timeProperty, minuteIntervalProperty,
|
|
minuteProperty, minMinuteProperty, maxMinuteProperty,
|
|
hourProperty, minHourProperty, maxHourProperty, colorProperty, Color
|
|
} from "./time-picker-common";
|
|
|
|
export * from "./time-picker-common";
|
|
|
|
function getDate(hour: number, minute: number): Date {
|
|
let components = NSDateComponents.alloc().init();
|
|
components.hour = hour;
|
|
components.minute = minute;
|
|
|
|
return NSCalendar.currentCalendar.dateFromComponents(<any>components);
|
|
}
|
|
|
|
function getComponents(date: Date | NSDate): NSDateComponents {
|
|
return NSCalendar.currentCalendar.componentsFromDate(NSCalendarUnit.CalendarUnitHour | NSCalendarUnit.CalendarUnitMinute, <any>date);
|
|
}
|
|
|
|
export class TimePicker extends TimePickerBase {
|
|
nativeViewProtected: UIDatePicker;
|
|
private _changeHandler: NSObject;
|
|
|
|
constructor() {
|
|
super();
|
|
let components = getComponents(NSDate.date());
|
|
this.hour = components.hour;
|
|
this.minute = components.minute;
|
|
}
|
|
|
|
createNativeView() {
|
|
const picker = UIDatePicker.new();
|
|
picker.datePickerMode = UIDatePickerMode.Time;
|
|
|
|
return picker;
|
|
}
|
|
|
|
initNativeView() {
|
|
super.initNativeView();
|
|
this._changeHandler = UITimePickerChangeHandlerImpl.initWithOwner(new WeakRef(this));
|
|
this.nativeViewProtected.addTargetActionForControlEvents(this._changeHandler, "valueChanged", UIControlEvents.ValueChanged);
|
|
}
|
|
|
|
disposeNativeView() {
|
|
this._changeHandler = null;
|
|
super.initNativeView();
|
|
}
|
|
|
|
get ios(): UIDatePicker {
|
|
return this.nativeViewProtected;
|
|
}
|
|
|
|
[timeProperty.getDefault](): Date {
|
|
return this.nativeViewProtected.date;
|
|
}
|
|
[timeProperty.setNative](value: Date) {
|
|
this.nativeViewProtected.date = getDate(this.hour, this.minute);
|
|
}
|
|
|
|
[minuteProperty.getDefault](): number {
|
|
return this.nativeViewProtected.date.getMinutes();
|
|
}
|
|
[minuteProperty.setNative](value: number) {
|
|
this.nativeViewProtected.date = getDate(this.hour, value);
|
|
}
|
|
|
|
[hourProperty.getDefault](): number {
|
|
return this.nativeViewProtected.date.getHours();
|
|
}
|
|
[hourProperty.setNative](value: number) {
|
|
this.nativeViewProtected.date = getDate(value, this.minute);
|
|
}
|
|
|
|
[minHourProperty.getDefault](): number {
|
|
return this.nativeViewProtected.minimumDate ? this.nativeViewProtected.minimumDate.getHours() : 0;
|
|
}
|
|
[minHourProperty.setNative](value: number) {
|
|
this.nativeViewProtected.minimumDate = getDate(value, this.minute);
|
|
}
|
|
|
|
[maxHourProperty.getDefault](): number {
|
|
return this.nativeViewProtected.maximumDate ? this.nativeViewProtected.maximumDate.getHours() : 24;
|
|
}
|
|
[maxHourProperty.setNative](value: number) {
|
|
this.nativeViewProtected.maximumDate = getDate(value, this.minute);
|
|
}
|
|
|
|
[minMinuteProperty.getDefault](): number {
|
|
return this.nativeViewProtected.minimumDate ? this.nativeViewProtected.minimumDate.getMinutes() : 0;
|
|
}
|
|
[minMinuteProperty.setNative](value: number) {
|
|
this.nativeViewProtected.minimumDate = getDate(this.hour, value);
|
|
}
|
|
|
|
[maxMinuteProperty.getDefault](): number {
|
|
return this.nativeViewProtected.maximumDate ? this.nativeViewProtected.maximumDate.getMinutes() : 60;
|
|
}
|
|
[maxMinuteProperty.setNative](value: number) {
|
|
this.nativeViewProtected.maximumDate = getDate(this.hour, value);
|
|
}
|
|
|
|
[minuteIntervalProperty.getDefault](): number {
|
|
return this.nativeViewProtected.minuteInterval;
|
|
}
|
|
[minuteIntervalProperty.setNative](value: number) {
|
|
this.nativeViewProtected.minuteInterval = value;
|
|
}
|
|
|
|
[colorProperty.getDefault](): UIColor {
|
|
return this.nativeViewProtected.valueForKey("textColor");
|
|
}
|
|
[colorProperty.setNative](value: Color | UIColor) {
|
|
const color = value instanceof Color ? value.ios : value;
|
|
this.nativeViewProtected.setValueForKey(color, "textColor");
|
|
}
|
|
}
|
|
|
|
class UITimePickerChangeHandlerImpl extends NSObject {
|
|
|
|
private _owner: WeakRef<TimePicker>;
|
|
|
|
public static initWithOwner(owner: WeakRef<TimePicker>): UITimePickerChangeHandlerImpl {
|
|
let handler = <UITimePickerChangeHandlerImpl>UITimePickerChangeHandlerImpl.new();
|
|
handler._owner = owner;
|
|
|
|
return handler;
|
|
}
|
|
|
|
public valueChanged(sender: UIDatePicker) {
|
|
let owner = this._owner.get();
|
|
if (!owner) {
|
|
return;
|
|
}
|
|
|
|
let components = getComponents(sender.date);
|
|
|
|
let timeChanged = false;
|
|
if (components.hour !== owner.hour) {
|
|
hourProperty.nativeValueChange(owner, components.hour);
|
|
timeChanged = true;
|
|
}
|
|
|
|
if (components.minute !== owner.minute) {
|
|
minuteProperty.nativeValueChange(owner, components.minute);
|
|
timeChanged = true;
|
|
}
|
|
|
|
if (timeChanged) {
|
|
timeProperty.nativeValueChange(owner, new Date(0, 0, 0, components.hour, components.minute));
|
|
}
|
|
}
|
|
|
|
public static ObjCExposedMethods = {
|
|
"valueChanged": { returns: interop.types.void, params: [UIDatePicker] }
|
|
};
|
|
}
|