Skip to content

Commit

Permalink
feat(ios): support new date picker styles
Browse files Browse the repository at this point in the history
Note: Without these, default pickers will look off on iOS 14+, so
developers should very carefully check their apps for pickers.

Fixes TIMOB-28104
  • Loading branch information
hansemannn authored and sgtcoolguy committed Sep 2, 2020
1 parent f7776a7 commit 78bce40
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
11 changes: 11 additions & 0 deletions apidoc/Titanium/UI/Picker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: <Titanium.UI.iOS.DATE_PICKER_STYLE_AUTOMATIC>
osver: { ios: { min: "13.4" } }

- name: type
summary: Determines the type of picker displayed
description: |
Expand Down
35 changes: 35 additions & 0 deletions apidoc/Titanium/UI/iOS/iOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,41 @@ properties:
since: "3.2.0"
osver: {ios: {min: "7.0"}}

- name: DATE_PICKER_STYLE_AUTOMATIC
summary: |
Use with <Titanium.UI.Picker.datePickerStyle> 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 <Titanium.UI.Picker.datePickerStyle> 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 <Titanium.UI.Picker.datePickerStyle> 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 <Titanium.UI.Picker.datePickerStyle> 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: |
Expand Down
8 changes: 8 additions & 0 deletions iphone/Classes/TiUIPicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions iphone/Classes/TiUIiOSProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit 78bce40

Please sign in to comment.