Implement setNativeSelectedIndex command for Picker component

Summary:
This is required so we can switch to using commands instead of `setNativeProps`.
`setNativeProps` are not supported in Fabric, we are moving away from it.

Reviewed By: JoshuaGross

Differential Revision: D17764967

fbshipit-source-id: 16e54ebe1f0c58b80a6491db970a60c01fec8a15
This commit is contained in:
Samuel Susla 2019-10-07 04:22:25 -07:00 коммит произвёл Facebook Github Bot
Родитель 3560093115
Коммит 62cbdceedd
1 изменённых файлов: 19 добавлений и 0 удалений

Просмотреть файл

@ -10,6 +10,7 @@
#import "RCTBridge.h"
#import "RCTPicker.h"
#import "RCTFont.h"
#import <React/RCTUIManager.h>
@implementation RCTPickerManager
@ -42,4 +43,22 @@ RCT_CUSTOM_VIEW_PROPERTY(fontFamily, NSString, RCTPicker)
view.font = [RCTFont updateFont:view.font withFamily:json ?: defaultView.font.familyName];
}
RCT_EXPORT_METHOD(setNativeSelectedIndex : (nonnull NSNumber *)viewTag toIndex : (NSNumber *)index)
{
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
UIView *view = viewRegistry[viewTag];
if ([view isKindOfClass:[RCTPicker class]]) {
[(RCTPicker *)view setSelectedIndex:index.integerValue];
} else {
UIView *subview = view.subviews.firstObject;
if ([subview isKindOfClass:[RCTPicker class]]) {
[(RCTPicker *)subview setSelectedIndex:index.integerValue];
} else {
RCTLogError(@"view type must be RCTPicker");
}
}
}];
}
@end