Files
react-native/packages/react-native/React/Views/RCTSegmentedControl.m
T
Riccardo Cipolleschi 610b14e4f3 Move min ios version to 13.4 for OSS (#36795)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/36795

This change bump the min iOS version for React Native to 13.4, to align with company guidelines.

## Changelog:
[iOS][Changed] - Moved the min iOS version to 13.4

Reviewed By: cortinico

Differential Revision: D44634663

fbshipit-source-id: 035e8fcbb395f7394f8253e3ec485ad9937531c2
2023-04-06 12:07:26 -07:00

69 lines
1.8 KiB
Objective-C

/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RCTSegmentedControl.h"
#import "RCTConvert.h"
#import "UIView+React.h"
@implementation RCTSegmentedControl
- (instancetype)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame])) {
_selectedIndex = self.selectedSegmentIndex;
[self addTarget:self action:@selector(didChange) forControlEvents:UIControlEventValueChanged];
}
return self;
}
- (void)setValues:(NSArray<NSString *> *)values
{
_values = [values copy];
[self removeAllSegments];
for (NSString *value in values) {
[self insertSegmentWithTitle:value atIndex:self.numberOfSegments animated:NO];
}
super.selectedSegmentIndex = _selectedIndex;
}
- (void)setSelectedIndex:(NSInteger)selectedIndex
{
_selectedIndex = selectedIndex;
super.selectedSegmentIndex = selectedIndex;
}
- (void)setBackgroundColor:(UIColor *)backgroundColor
{
[super setBackgroundColor:backgroundColor];
}
- (void)setTextColor:(UIColor *)textColor
{
[self setTitleTextAttributes:@{NSForegroundColorAttributeName : textColor} forState:UIControlStateNormal];
}
- (void)setTintColor:(UIColor *)tintColor
{
[super setTintColor:tintColor];
[self setSelectedSegmentTintColor:tintColor];
[self setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}
forState:UIControlStateSelected];
[self setTitleTextAttributes:@{NSForegroundColorAttributeName : tintColor} forState:UIControlStateNormal];
}
- (void)didChange
{
_selectedIndex = self.selectedSegmentIndex;
if (_onChange) {
_onChange(@{@"value" : [self titleForSegmentAtIndex:_selectedIndex], @"selectedSegmentIndex" : @(_selectedIndex)});
}
}
@end