-
-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathUsageWithIcons.tsx
59 lines (55 loc) · 1.77 KB
/
UsageWithIcons.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
import * as React from 'react';
import { MaterialIcons } from '@expo/vector-icons';
import {
HeaderButtons,
Item,
HiddenItem,
OverflowMenu,
ItemProps,
HiddenItemProps,
Divider,
} from 'react-navigation-header-buttons';
import type { ScreenProps } from '../NavTypes';
import { MaterialHeaderButton } from '../components/MaterialHeaderButton';
import { ScreenBody } from '../components/ScreenBody';
import { Text } from 'react-native';
import { useLayoutEffect } from 'react';
const EditItem = ({ onPress }: Pick<ItemProps, 'onPress'>) => {
return <Item title="edit" onPress={onPress} />;
};
const ReusableHiddenItem = ({ onPress }: Pick<HiddenItemProps, 'onPress'>) => (
<HiddenItem title="hidden2" onPress={onPress} disabled />
);
export function UsageWithIcons({ navigation }: ScreenProps<'UsageWithIcons'>) {
useLayoutEffect(() => {
navigation.setOptions({
title: 'Demo',
// in your app, extract the arrow function into a separate component
// to avoid creating a new one every time
headerRight: () => (
<HeaderButtons HeaderButtonComponent={MaterialHeaderButton}>
<EditItem onPress={() => alert('Edit')} />
<Item
title="search"
iconName="search"
onPress={() => alert('search')}
/>
<OverflowMenu
OverflowIcon={({ color }) => (
<MaterialIcons name="more-horiz" size={23} color={color} />
)}
>
<HiddenItem title="hidden1" onPress={() => alert('hidden1')} />
<Divider />
<ReusableHiddenItem onPress={() => alert('hidden2')} />
</OverflowMenu>
</HeaderButtons>
),
});
}, [navigation]);
return (
<ScreenBody>
<Text>demo!</Text>
</ScreenBody>
);
}