-
-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathUsageCustomOverflow.tsx
65 lines (60 loc) · 1.97 KB
/
UsageCustomOverflow.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
import * as React from 'react';
import { MaterialIcons } from '@expo/vector-icons';
import { Text } from 'react-native';
import {
HeaderButtons,
Item,
HiddenItem,
OverflowMenu,
OnOverflowMenuPressParams,
} from 'react-navigation-header-buttons';
import { connectActionSheet } from '@expo/react-native-action-sheet';
import type { ScreenProps } from '../NavTypes';
import { ScreenBody } from '../components/ScreenBody';
import { MaterialHeaderButton } from '../components/MaterialHeaderButton';
function RightHeaderButtons(props: any) {
const _onOpenActionSheet = ({ hiddenButtons }: OnOverflowMenuPressParams) => {
// Same interface as https://facebook.github.io/react-native/docs/actionsheetios.html
const options = hiddenButtons.map((it) => it.title);
const destructiveButtonIndex = 1;
props.showActionSheetWithOptions(
{
options,
destructiveButtonIndex,
},
(buttonIndex: number) => {
hiddenButtons[buttonIndex]?.onPress?.();
}
);
};
return (
<HeaderButtons HeaderButtonComponent={MaterialHeaderButton}>
<Item title="person" iconName="person" onPress={() => alert('person')} />
<Item title="edit" onPress={() => alert('edit')} />
<OverflowMenu
OverflowIcon={
<MaterialIcons name="more-horiz" size={23} color="blue" />
}
onPress={_onOpenActionSheet}
>
<HiddenItem title="hidden1" onPress={() => alert('hidden1')} />
<HiddenItem title="delete" onPress={() => alert('delete')} />
</OverflowMenu>
</HeaderButtons>
);
}
const ConnectedButtons = connectActionSheet(RightHeaderButtons);
export function UsageWithCustomOverflow({
navigation,
}: ScreenProps<'UsageWithCustomOverflow'>) {
React.useLayoutEffect(() => {
navigation.setOptions({
headerRight: () => <ConnectedButtons />,
});
}, [navigation]);
return (
<ScreenBody>
<Text>custom sheet from @expo/react-native-action-sheet</Text>
</ScreenBody>
);
}