-
-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathButtonsWrapper.tsx
68 lines (62 loc) · 1.64 KB
/
ButtonsWrapper.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
import * as React from 'react';
import { Platform, StyleProp, StyleSheet, View, ViewStyle } from 'react-native';
/*
* the `left` prop can be provided to HeaderButtons as well as OverflowMenu
* this will render some extra margins on the corresponding side
* but must be considered only once which is the job of this Context
* */
export const ButtonsExtraMarginContext = React.createContext<
'toBeHandled' | 'alreadyHandled'
>('toBeHandled');
type Props = {
left: boolean;
children: React.ReactNode;
style?: StyleProp<ViewStyle>;
};
export const ButtonsWrapper = ({ left, children, style }: Props) => {
const marginStatus = React.useContext(ButtonsExtraMarginContext);
const extraSideMargin =
marginStatus === 'alreadyHandled' ? undefined : getMargin(left);
return (
<ButtonsExtraMarginContext.Provider value="alreadyHandled">
<View style={[styles.row, extraSideMargin, style]}>{children}</View>
</ButtonsExtraMarginContext.Provider>
);
};
const getMargin = (left: boolean) => {
return left ? styles.extraEdgeMarginOnLeft : styles.extraEdgeMarginOnRight;
};
const styles = StyleSheet.create({
row: {
flexDirection: 'row',
justifyContent: 'flex-end',
...Platform.select({
android: {
columnGap: 18,
},
default: {
columnGap: 24,
},
}),
},
extraEdgeMarginOnLeft: {
...Platform.select({
android: {
marginLeft: 5,
},
default: {
marginLeft: 4,
},
}),
},
extraEdgeMarginOnRight: {
...Platform.select({
android: {
marginRight: 14,
},
default: {
marginRight: 15,
},
}),
},
});