Skip to content

Commit

Permalink
Fix tintColor in SegmentedControlIOS component
Browse files Browse the repository at this point in the history
Summary:
iOS 13 introduced a new design for `UISegmentedControl` and new APIs to control this. `[UISegmentedControl tintColor]` is now ignored.

We try to maintain backwards compatibility so the appearance is as close as possible to iOS 12.

Changelog:
Fix `tintColor` on SegmentedControlIOS

Reviewed By: shergin

Differential Revision: D17905892

fbshipit-source-id: 964ac64c8543660929c43b427dce4f78094b1255
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Oct 15, 2019
1 parent 8bce9c5 commit be89e4d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions React/Views/RCTSegmentedControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ - (void)setSelectedIndex:(NSInteger)selectedIndex
super.selectedSegmentIndex = selectedIndex;
}

- (void)setTintColor:(UIColor *)tintColor
{
[super setTintColor:tintColor];
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
if (@available(iOS 13.0, *)) {
[self setSelectedSegmentTintColor:tintColor];
[self setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}
forState:UIControlStateSelected];
[self setTitleTextAttributes:@{NSForegroundColorAttributeName: tintColor}
forState:UIControlStateNormal];
}
#endif
}

- (void)didChange
{
_selectedIndex = self.selectedSegmentIndex;
Expand Down

0 comments on commit be89e4d

Please sign in to comment.