-
-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathUsageWithOverflowComplex.tsx
69 lines (64 loc) · 2.12 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
import * as React from 'react';
import { MaterialIcons } from '@expo/vector-icons';
import { View, Text } from 'react-native';
import {
HiddenItem,
OverflowMenu,
Divider,
overflowMenuPressHandlerActionSheet,
overflowMenuPressHandlerPopupMenu,
overflowMenuPressHandlerDropdownMenu,
} from 'react-navigation-header-buttons';
import { Button } from './PaddedButton';
const ReusableItem = ({ title, disabled = false }) => {
return <HiddenItem title={title} disabled={disabled} onPress={() => alert(title)} />;
};
const handlers = {
overflowMenuPressHandlerActionSheet,
overflowMenuPressHandlerPopupMenu,
overflowMenuPressHandlerDropdownMenu,
custom: function custom(obj) {
alert('you custom function will receive:' + Object.keys(obj));
},
};
export function UsageWithOverflowComplex({ navigation }) {
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')} />]}
<View style={{ backgroundColor: 'orange', maxWidth: 200 }}>
<Text>
custom view that will only be considered for overflowMenuPressHandlerDropdownMenu
</Text>
</View>
</OverflowMenu>
),
});
}, [navigation, index]);
return (
<View style={{ flex: 1 }}>
<Text>behavior is platform-dependent</Text>
<Text>current mode: {Object.keys(handlers)[index]}</Text>
<Button
onPress={() => {
setIndex((index + 1) % Object.keys(handlers).length);
}}
title="next overflow mode"
/>
</View>
);
}