-
-
Notifications
You must be signed in to change notification settings - Fork 61
/
Separator.tsx
71 lines (66 loc) · 1.57 KB
/
Separator.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import React, { useContext } from 'react';
import {
Platform,
SafeAreaView,
StyleSheet,
View,
ViewStyle,
} from 'react-native';
import { ThemeContext } from './Theme';
export interface SeparatorInterface {
backgroundColor?: ViewStyle['backgroundColor'];
tintColor?: ViewStyle['backgroundColor'];
isHidden?: boolean;
insetLeft?: ViewStyle['marginLeft'];
insetRight?: ViewStyle['marginRight'];
withSafeAreaView?: boolean;
}
const Separator: React.FC<SeparatorInterface> = ({
backgroundColor,
tintColor,
isHidden = false,
insetLeft = 15,
insetRight = 0,
withSafeAreaView = Platform.OS === 'ios'
? parseInt(`${Platform.Version}`, 10) <= 10
? false
: true
: true,
}) => {
const theme = useContext(ThemeContext);
const localStyles = {
separator: [
styles.separator,
{ backgroundColor: backgroundColor || theme.colors.background },
],
separatorInner: [
styles.separatorInner,
{
backgroundColor: isHidden
? 'transparent'
: tintColor || theme.colors.separatorColor,
marginLeft: insetLeft,
marginRight: insetRight,
},
],
};
if (withSafeAreaView) {
return (
<SafeAreaView style={localStyles.separator}>
<View style={localStyles.separatorInner} />
</SafeAreaView>
);
}
return (
<View style={localStyles.separator}>
<View style={localStyles.separatorInner} />
</View>
);
};
const styles = StyleSheet.create({
separator: {},
separatorInner: {
height: StyleSheet.hairlineWidth,
},
});
export default Separator;