-
-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathUsageWithOverflowComplex.tsx
104 lines (97 loc) · 2.72 KB
/
UsageWithOverflowComplex.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import * as React from 'react';
import { MaterialIcons } from '@expo/vector-icons';
import { View, Text } from 'react-native';
import {
HiddenItem,
OverflowMenu,
overflowMenuPressHandlerActionSheet,
overflowMenuPressHandlerPopupMenu,
overflowMenuPressHandlerDropdownMenu,
HiddenItemProps,
OnOverflowMenuPressParams,
useOverflowMenu,
Divider,
} from 'react-navigation-header-buttons';
import type { ScreenProps } from '../NavTypes';
import { Button } from '../components/PaddedButton';
import { ScreenBody } from '../components/ScreenBody';
const ReusableItem = ({ title, disabled = false }: HiddenItemProps) => {
return (
<HiddenItem
title={title}
disabled={disabled}
onPress={() => alert(title)}
/>
);
};
const handlers = {
overflowMenuPressHandlerDropdownMenu,
overflowMenuPressHandlerActionSheet,
overflowMenuPressHandlerPopupMenu,
custom: function custom(obj: OnOverflowMenuPressParams) {
alert('you custom function will receive:' + Object.keys(obj).join(', '));
},
};
const CustomViewInOverflow = () => {
const { closeMenu } = useOverflowMenu();
return (
<View style={{ backgroundColor: 'orange', maxWidth: 200 }}>
<Text onPress={closeMenu}>
custom view that will only be considered for
overflowMenuPressHandlerDropdownMenu
</Text>
</View>
);
};
export function UsageWithOverflowComplex({
navigation,
}: ScreenProps<'UsageWithOverflowComplex'>) {
const [index, setIndex] = React.useState(0);
React.useLayoutEffect(() => {
navigation.setOptions({
headerRight: () => (
<OverflowMenu
OverflowIcon={
<MaterialIcons name="more-vert" size={23} color="blue" />
}
onPress={Object.values(handlers)[index]}
>
<HiddenItem
icon={<MaterialIcons name="search" size={23} />}
title="search"
onPress={() => alert('search')}
/>
<ReusableItem title="hidden2" />
<ReusableItem title="hidden3" disabled />
<Divider />
{/*Arrays as children also work*/}
{[
<HiddenItem
key="hidden4"
title="hidden4"
onPress={() => alert('hidden4')}
/>,
]}
<CustomViewInOverflow />
</OverflowMenu>
),
});
}, [navigation, index]);
return (
<ScreenBody>
<Text>current mode: {Object.keys(handlers)[index]}</Text>
{Object.keys(handlers).map((key, i) => {
return (
<Button
key={i}
onPress={() => {
setIndex(i);
}}
title={key}
/>
);
})}
<Text>behavior is platform-dependent</Text>
</ScreenBody>
);
}