Skip to content

Commit

Permalink
Add command to set date on RCTDatePickerManager
Browse files Browse the repository at this point in the history
Summary: We are moving away from setNativeProps, this adds necessary method on native to leverage commands API

Reviewed By: shergin

Differential Revision: D17787877

fbshipit-source-id: 8f06cdd85c96bce4ea9bb7a8cd5f6c1a1d68b20a
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Oct 7, 2019
1 parent 62cbdce commit f580409
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions React/Views/RCTDatePickerManager.m
Expand Up @@ -11,6 +11,7 @@
#import "RCTDatePicker.h"
#import "RCTEventDispatcher.h"
#import "UIView+React.h"
#import <React/RCTUIManager.h>

@implementation RCTConvert(UIDatePicker)

Expand Down Expand Up @@ -41,4 +42,22 @@ - (UIView *)view
RCT_REMAP_VIEW_PROPERTY(mode, datePickerMode, UIDatePickerMode)
RCT_REMAP_VIEW_PROPERTY(timeZoneOffsetInMinutes, timeZone, NSTimeZone)

RCT_EXPORT_METHOD(setNativeDate : (nonnull NSNumber *)viewTag toDate : (NSDate *)date)
{
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
UIView *view = viewRegistry[viewTag];

if ([view isKindOfClass:[RCTDatePicker class]]) {
[(RCTDatePicker *)view setDate:date];
} else {
UIView *subview = view.subviews.firstObject;
if ([subview isKindOfClass:[RCTDatePicker class]]) {
[(RCTDatePicker *)subview setDate:date];
} else {
RCTLogError(@"view type must be RCTPicker");
}
}
}];
}

@end

0 comments on commit f580409

Please sign in to comment.