forked from Mobilecn-UI/nativecn-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Switch.tsx
29 lines (24 loc) · 778 Bytes
/
Switch.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { Switch as NativeSwitch, useColorScheme } from 'react-native';
import { theme } from '../styles/theme';
function Switch({
...props
}: React.ComponentPropsWithoutRef<typeof NativeSwitch>) {
const colorScheme = useColorScheme();
const currentTheme = colorScheme === 'dark' ? theme.dark : theme.light;
const trackColor = props.trackColor || {
false: currentTheme.background,
true: currentTheme.foreground,
};
const thumbColor = props.thumbColor || currentTheme.background;
const ios_backgroundColor =
props.ios_backgroundColor || currentTheme.background;
return (
<NativeSwitch
trackColor={trackColor}
thumbColor={thumbColor}
ios_backgroundColor={ios_backgroundColor}
{...props}
/>
);
}
export { Switch };