FLEXArgumentInputDateView.m 1.5 KB

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