Skip to content

Commit 0386c33

Browse files
Naturalclararjndr
andauthored
feat: add Appearance Props
* Add appearance feature * feat: add appearance type in flowtype Co-authored-by: Akash Rajendra <[email protected]>
1 parent 63edf59 commit 0386c33

4 files changed

+26
-0
lines changed

index.d.ts

+6
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ export interface SegmentedControlIOSProps extends ViewProps {
6767
* The labels for the control's segment buttons, in order.
6868
*/
6969
values?: string[];
70+
71+
/**
72+
* (iOS 13 only)
73+
* Overrides the control's appearance irrespective of the OS theme
74+
*/
75+
appearance?: 'dark' | 'light'
7076
}
7177

7278
/**

ios/RNCSegmentedControl.m

+14
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,18 @@ - (void)didChange
9494
}
9595
}
9696

97+
- (void)setAppearance:(NSString *)appearanceString
98+
{
99+
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
100+
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
101+
if (@available(iOS 13.0, *)) {
102+
if ([appearanceString isEqual: @"dark"]) {
103+
[self setOverrideUserInterfaceStyle:UIUserInterfaceStyleDark];
104+
} else if ([appearanceString isEqual: @"light"]) {
105+
[self setOverrideUserInterfaceStyle:UIUserInterfaceStyleLight];
106+
}
107+
}
108+
#endif
109+
}
110+
97111
@end

ios/RNCSegmentedControlManager.m

+1
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ - (UIView *)view
2929
RCT_EXPORT_VIEW_PROPERTY(momentary, BOOL)
3030
RCT_EXPORT_VIEW_PROPERTY(enabled, BOOL)
3131
RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
32+
RCT_EXPORT_VIEW_PROPERTY(appearance, NSString)
3233

3334
@end

js/RNCSegmentedControlNativeComponent.js

+5
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ export type SegmentedControlIOSProps = $ReadOnly<{|
7272
* The `onValueChange` callback will still work as expected.
7373
*/
7474
momentary?: ?boolean,
75+
/**
76+
* (iOS 13 only)
77+
* Overrides the control's appearance irrespective of the OS theme
78+
*/
79+
appearance?: 'dark' | 'light',
7580
|}>;
7681

7782
type NativeSegmentedControlIOS = Class<

0 commit comments

Comments
 (0)