1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | #import "RCTDatePicker.h"
|
9 |
|
10 | #import "RCTUtils.h"
|
11 | #import "UIView+React.h"
|
12 |
|
13 | @interface RCTDatePicker ()
|
14 |
|
15 | @property (nonatomic, copy) RCTBubblingEventBlock onChange;
|
16 | @property (nonatomic, assign) NSInteger reactMinuteInterval;
|
17 |
|
18 | @end
|
19 |
|
20 | @implementation RCTDatePicker
|
21 |
|
22 | - (instancetype)initWithFrame:(CGRect)frame
|
23 | {
|
24 | if ((self = [super initWithFrame:frame])) {
|
25 | [self addTarget:self action:@selector(didChange)
|
26 | forControlEvents:UIControlEventValueChanged];
|
27 | _reactMinuteInterval = 1;
|
28 | }
|
29 | return self;
|
30 | }
|
31 |
|
32 | RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
|
33 |
|
34 | - (void)didChange
|
35 | {
|
36 | if (_onChange) {
|
37 | _onChange(@{ @"timestamp": @(self.date.timeIntervalSince1970 * 1000.0) });
|
38 | }
|
39 | }
|
40 |
|
41 | - (void)setDatePickerMode:(UIDatePickerMode)datePickerMode
|
42 | {
|
43 | [super setDatePickerMode:datePickerMode];
|
44 | // We need to set minuteInterval after setting datePickerMode, otherwise minuteInterval is invalid in time mode.
|
45 | self.minuteInterval = _reactMinuteInterval;
|
46 | }
|
47 |
|
48 | - (void)setMinuteInterval:(NSInteger)minuteInterval
|
49 | {
|
50 | [super setMinuteInterval:minuteInterval];
|
51 | _reactMinuteInterval = minuteInterval;
|
52 | }
|
53 |
|
54 | @end
|