FLEXArgumentInputDateView.m 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //
  2. // FLEXArgumentInputDataView.m
  3. // Flipboard
  4. //
  5. // Created by Daniel Rodriguez Troitino on 2/14/15.
  6. // Copyright (c) 2020 FLEX Team. All rights reserved.
  7. //
  8. #import "FLEXArgumentInputDateView.h"
  9. #import "FLEXRuntimeUtility.h"
  10. #import "fakes.h"
  11. #import <TargetConditionals.h>
  12. @interface FLEXArgumentInputDateView ()
  13. #if TARGET_OS_TV
  14. @property (nonatomic) KBDatePickerView *datePicker;
  15. #else
  16. @property (nonatomic) UIDatePicker *datePicker;
  17. #endif
  18. @end
  19. @implementation FLEXArgumentInputDateView
  20. - (instancetype)initWithArgumentTypeEncoding:(const char *)typeEncoding {
  21. self = [super initWithArgumentTypeEncoding:typeEncoding];
  22. if (self) {
  23. #if !TARGET_OS_TV
  24. self.datePicker = [UIDatePicker new];
  25. self.datePicker.datePickerMode = UIDatePickerModeDateAndTime;
  26. // Using UTC, because that's what the NSDate description prints
  27. self.datePicker.calendar = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];
  28. self.datePicker.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];
  29. #else
  30. self.datePicker = [[KBDatePickerView alloc] init];
  31. #endif
  32. [self addSubview:self.datePicker];
  33. }
  34. return self;
  35. }
  36. - (void)setInputValue:(id)inputValue {
  37. if ([inputValue isKindOfClass:[NSDate class]]) {
  38. self.datePicker.date = inputValue;
  39. }
  40. }
  41. - (id)inputValue {
  42. return self.datePicker.date;
  43. }
  44. - (void)layoutSubviews {
  45. [super layoutSubviews];
  46. self.datePicker.frame = self.bounds;
  47. }
  48. - (CGSize)sizeThatFits:(CGSize)size {
  49. CGFloat height = [self.datePicker sizeThatFits:size].height;
  50. return CGSizeMake(size.width, height);
  51. }
  52. + (BOOL)supportsObjCType:(const char *)type withCurrentValue:(id)value {
  53. NSParameterAssert(type);
  54. return strcmp(type, FLEXEncodeClass(NSDate)) == 0;
  55. }
  56. @end