1/** 2 * Copyright (c) Facebook, Inc. and its affiliates. 3 * 4 * This source code is licensed under the MIT license found in the 5 * LICENSE file in the root directory of this source tree. 6 */ 7 8#import "RNCSegmentedControlManager.h" 9 10#import "RNCSegmentedControl.h" 11#import <React/RCTBridge.h> 12#import <React/RCTConvert.h> 13 14@implementation RNCSegmentedControlManager 15 16RCT_EXPORT_MODULE() 17 18- (UIView *)view { 19 return [RNCSegmentedControl new]; 20} 21 22RCT_EXPORT_VIEW_PROPERTY(values, NSArray) 23RCT_EXPORT_VIEW_PROPERTY(selectedIndex, NSInteger) 24RCT_EXPORT_VIEW_PROPERTY(tintColor, UIColor) 25RCT_EXPORT_VIEW_PROPERTY(backgroundColor, UIColor) 26RCT_EXPORT_VIEW_PROPERTY(momentary, BOOL) 27RCT_EXPORT_VIEW_PROPERTY(enabled, BOOL) 28RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock) 29RCT_EXPORT_VIEW_PROPERTY(appearance, NSString) 30 31RCT_CUSTOM_VIEW_PROPERTY(fontStyle, NSObject, RNCSegmentedControl) { 32#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \ 33 __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0 34 if (@available(iOS 13.0, *)) { 35 if (json) { 36 UIColor *color = json[@"color"] ? [RCTConvert UIColor:json[@"color"]] 37 : UIColor.labelColor; 38 NSInteger fontSize = 39 json[@"fontSize"] ? [RCTConvert NSInteger:json[@"fontSize"]] : 13.0; 40 UIFont *font = [UIFont systemFontOfSize:fontSize]; 41 if (json[@"fontFamily"]) { 42 UIFont *tempFont = [UIFont fontWithName:json[@"fontFamily"] 43 size:fontSize]; 44 if (tempFont != nil) { 45 font = tempFont; 46 } 47 } 48 49 NSDictionary *attributes = [NSDictionary 50 dictionaryWithObjectsAndKeys:font, NSFontAttributeName, color, 51 NSForegroundColorAttributeName, nil]; 52 [view setTitleTextAttributes:attributes forState:UIControlStateNormal]; 53 } 54 } 55#endif 56} 57 58RCT_CUSTOM_VIEW_PROPERTY(activeFontStyle, NSObject, RNCSegmentedControl) { 59#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \ 60 __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0 61 if (@available(iOS 13.0, *)) { 62 if (json) { 63 UIColor *color = json[@"color"] ? [RCTConvert UIColor:json[@"color"]] 64 : UIColor.labelColor; 65 NSInteger fontSize = 66 json[@"fontSize"] ? [RCTConvert NSInteger:json[@"fontSize"]] : 13.0; 67 UIFont *font = [UIFont boldSystemFontOfSize:fontSize]; 68 if (json[@"fontFamily"]) { 69 font = [UIFont fontWithName:json[@"fontFamily"] size:fontSize]; 70 } 71 NSDictionary *attributes = [NSDictionary 72 dictionaryWithObjectsAndKeys:font, NSFontAttributeName, color, 73 NSForegroundColorAttributeName, nil]; 74 [view setTitleTextAttributes:attributes forState:UIControlStateSelected]; 75 } 76 } 77#endif 78} 79 80@end 81