Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add custom color for iOS13 segmented control #27643

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -33,6 +33,8 @@ type NativeProps = $ReadOnly<{|
selectedIndex?: WithDefault<Int32, 0>,
enabled?: WithDefault<boolean, true>,
tintColor?: ?ColorValue,
textColor?: ?ColorValue,
backgroundColor?: ?ColorValue,
momentary?: WithDefault<boolean, false>,

// Events
Expand Down
21 changes: 21 additions & 0 deletions React/Views/RCTSegmentedControl.m
Expand Up @@ -39,6 +39,27 @@ - (void)setSelectedIndex:(NSInteger)selectedIndex
super.selectedSegmentIndex = selectedIndex;
}

- (void)setBackgroundColor:(UIColor *)backgroundColor
{
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
if (@available(iOS 13.0, *)) {
[super setBackgroundColor:backgroundColor];
}
#endif
}

- (void)setTextColor:(UIColor *)textColor
{
#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 setTitleTextAttributes:@{NSForegroundColorAttributeName: textColor}
forState:UIControlStateNormal];
}
#endif
}

- (void)setTintColor:(UIColor *)tintColor
{
[super setTintColor:tintColor];
Expand Down
2 changes: 2 additions & 0 deletions React/Views/RCTSegmentedControlManager.m
Expand Up @@ -23,6 +23,8 @@ - (UIView *)view
RCT_EXPORT_VIEW_PROPERTY(values, NSArray<NSString *>)
RCT_EXPORT_VIEW_PROPERTY(selectedIndex, NSInteger)
RCT_EXPORT_VIEW_PROPERTY(tintColor, UIColor)
RCT_EXPORT_VIEW_PROPERTY(backgroundColor, UIColor)
RCT_EXPORT_VIEW_PROPERTY(textColor, UIColor)
RCT_EXPORT_VIEW_PROPERTY(momentary, BOOL)
RCT_EXPORT_VIEW_PROPERTY(enabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
Expand Down