forked from vonovak/react-navigation-header-buttons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUsageWithIcons.tsx
60 lines (55 loc) · 1.94 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
60
import React from 'react';
import { MaterialIcons } from '@expo/vector-icons';
import { Text } from 'react-native';
import {
HeaderButtons,
HeaderButton,
Item,
HiddenItem,
OverflowMenu,
Divider,
} from 'react-navigation-header-buttons';
const MaterialHeaderButton = (props) => {
// the `props` here come from <Item ... />
// you may access them and pass something else to `HeaderButton` if you like
return (
<HeaderButton
IconComponent={MaterialIcons}
iconSize={23}
// you can customize the colors, by default colors from react navigation theme will be used
// color="red"
// pressColor="blue"
{...props}
/>
);
};
// normally, on android, text is UPPERCASED
const ReusableCapitalizedEditItem = ({ onPress }) => {
return <Item title="edit" onPress={onPress} buttonStyle={{ textTransform: 'capitalize' }} />;
};
const ReusableItem = ({ onPress }) => <HiddenItem title="hidden2" onPress={onPress} disabled />;
export function UsageWithIcons({ navigation }) {
React.useLayoutEffect(() => {
navigation.setOptions({
// in your app, extract the arrow function into a separate component
// to avoid creating a new one every time
headerRight: () => (
<HeaderButtons HeaderButtonComponent={MaterialHeaderButton}>
<Item title="search" iconName="search" onPress={() => alert('search')} />
<ReusableCapitalizedEditItem onPress={() => alert('Edit')} />
<OverflowMenu
style={{ marginHorizontal: 10 }}
OverflowIcon={({ color }) => (
<MaterialIcons name="more-horiz" size={23} color={color} />
)}
>
<HiddenItem title="hidden1" onPress={() => alert('hidden1')} />
<Divider />
<ReusableItem onPress={() => alert('hidden2')} />
</OverflowMenu>
</HeaderButtons>
),
});
}, [navigation]);
return <Text style={{ flex: 1, margin: 20 }}>demo!</Text>;
}