From d3cdfc59bd7707ca2d5a1c27420e91f85019cf3f Mon Sep 17 00:00:00 2001 From: hansemannn Date: Fri, 28 Aug 2020 14:52:28 +0200 Subject: [PATCH] feat(ios): support new date picker styles Note: Without these, default pickers will look off on iOS 14+, so developers should very carefully check their apps for pickers. Fixes TIMOB-28104 --- apidoc/Titanium/UI/Picker.yml | 11 +++++++++ apidoc/Titanium/UI/iOS/iOS.yml | 35 ++++++++++++++++++++++++++++ iphone/Classes/TiUIPicker.m | 8 +++++++ iphone/Classes/TiUIiOSProxy.m | 42 ++++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+) diff --git a/apidoc/Titanium/UI/Picker.yml b/apidoc/Titanium/UI/Picker.yml index 6370176c4d8..3c4f0e532bd 100644 --- a/apidoc/Titanium/UI/Picker.yml +++ b/apidoc/Titanium/UI/Picker.yml @@ -364,6 +364,17 @@ properties: platforms: [android] since: "5.0.0" + - name: datePickerStyle + summary: Request a style if the picker is a date picker (`PICKER_TYPE_DATE`). + description: | + If the style changed, then the date picker may need to be resized and will + generate a layout pass to display correctly. + type: Number + platforms: [iphone, ipad] + constants: Titanium.UI.iOS.DATE_PICKER_STYLE_* + default: + osver: { ios: { min: "13.4" } } + - name: type summary: Determines the type of picker displayed description: | diff --git a/apidoc/Titanium/UI/iOS/iOS.yml b/apidoc/Titanium/UI/iOS/iOS.yml index bf78ffd9c9e..7bf409242e5 100644 --- a/apidoc/Titanium/UI/iOS/iOS.yml +++ b/apidoc/Titanium/UI/iOS/iOS.yml @@ -1348,6 +1348,41 @@ properties: since: "3.2.0" osver: {ios: {min: "7.0"}} + - name: DATE_PICKER_STYLE_AUTOMATIC + summary: | + Use with to automatically pick the best style + available for the current platform & mode. + description: "Note: Prior to iOS 14, this property is only used on iOS Catalyst apps." + type: Number + permission: read-only + since: "9.2.0" + osver: { ios: { min: "13.4" } } + + - name: DATE_PICKER_STYLE_WHEELS + summary: | + Use with to show the picker the wheels. Editing occurs inline. + type: Number + permission: read-only + since: "9.2.0" + osver: { ios: { min: "13.4" } } + + - name: DATE_PICKER_STYLE_COMPACT + summary: | + Use with to show the picker with a compact style. Editing occurs in an overlay. + description: "Note: Prior to iOS 14, this property is only used on iOS Catalyst apps." + type: Number + permission: read-only + since: "9.2.0" + osver: { ios: { min: "13.4" } } + + - name: DATE_PICKER_STYLE_INLINE + summary: | + Use with to allow editing in place (as a calendar). + type: Number + permission: read-only + since: "9.2.0" + osver: { ios: { min: "14.0" } } + - name: forceTouchSupported summary: Determines if the 3D-Touch capability "Force Touch" is supported (`true`) or not (`false`) by the device. description: | diff --git a/iphone/Classes/TiUIPicker.m b/iphone/Classes/TiUIPicker.m index 296c8963494..e22b61902dc 100644 --- a/iphone/Classes/TiUIPicker.m +++ b/iphone/Classes/TiUIPicker.m @@ -177,6 +177,14 @@ - (void)setType_:(id)type_ } } +- (void)setDatePickerStyle_:(id)style +{ + UIControl *picker = [self picker]; + if ([self isDatePicker]) { + [(UIDatePicker *)picker setPreferredDatePickerStyle:[TiUtils intValue:style]]; + } +} + // We're order-dependent on type being set first, so we need to make sure that anything that relies // on whether or not this is a date picker needs to be set AFTER the initial configuration. - (void)setSelectionIndicator_:(id)value diff --git a/iphone/Classes/TiUIiOSProxy.m b/iphone/Classes/TiUIiOSProxy.m index bcf05f47f99..78249e50f12 100644 --- a/iphone/Classes/TiUIiOSProxy.m +++ b/iphone/Classes/TiUIiOSProxy.m @@ -190,6 +190,48 @@ - (NSNumber *)ROW_ACTION_STYLE_NORMAL } #endif +#ifdef USE_TI_UIPICKER + +- (NSNumber *)DATE_PICKER_STYLE_AUTOMATIC +{ + if (![TiUtils isIOSVersionOrGreater:@"13.4"]) { + return @(-1); + } + + return @(UIDatePickerStyleAutomatic); +} + +- (NSNumber *)DATE_PICKER_STYLE_WHEELS +{ + if (![TiUtils isIOSVersionOrGreater:@"13.4"]) { + return @(-1); + } + + return @(UIDatePickerStyleWheels); +} + +- (NSNumber *)DATE_PICKER_STYLE_COMPACT +{ + if (![TiUtils isIOSVersionOrGreater:@"13.4"]) { + return @(-1); + } + + return @(UIDatePickerStyleCompact); +} + +#if IS_SDK_IOS_14 +- (NSNumber *)DATE_PICKER_STYLE_INLINE +{ + if (![TiUtils isIOSVersionOrGreater:@"14.0"]) { + return @(-1); + } + + return @(UIDatePickerStyleInline); +} +#endif + +#endif + #ifdef USE_TI_UIIOSPREVIEWCONTEXT - (NSNumber *)PREVIEW_ACTION_STYLE_DEFAULT {