Skip to content

Commit

Permalink
Implement setNativeSelectedIndex command for Picker component
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Oct 7, 2019
1 parent 3560093 commit 62cbdce
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions React/Views/RCTPickerManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "RCTBridge.h"
#import "RCTPicker.h"
#import "RCTFont.h"
#import <React/RCTUIManager.h>

@implementation RCTPickerManager

Expand Down Expand Up @@ -42,4 +43,22 @@ - (UIView *)view
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

0 comments on commit 62cbdce

Please sign in to comment.