@@ -27,34 +27,41 @@ Contains many examples in the [example folder](https://github.com/vonovak/react-
27
27
The corresponding code:
28
28
29
29
``` tsx
30
- import React from ' react' ;
30
+ import * as React from ' react' ;
31
31
import MaterialIcons from ' @expo/vector-icons/MaterialIcons' ;
32
- import { Text } from ' react-native' ;
33
32
import {
34
33
HeaderButtons ,
35
- HeaderButton ,
36
34
Item ,
37
35
HiddenItem ,
38
36
OverflowMenu ,
37
+ Divider ,
38
+ ItemProps ,
39
+ HiddenItemProps ,
39
40
HeaderButtonProps ,
41
+ HeaderButton ,
40
42
} from ' react-navigation-header-buttons' ;
43
+ import { Text } from ' react-native' ;
41
44
42
45
const MaterialHeaderButton = (props : HeaderButtonProps ) => (
43
46
// the `props` here come from <Item ... />
44
47
// you may access them and pass something else to `HeaderButton` if you like
45
48
<HeaderButton IconComponent = { MaterialIcons } iconSize = { 23 } { ... props } />
46
49
);
47
50
48
- const ReusableItem = ({ onPress }) => <Item title = " Edit" onPress = { onPress } />;
51
+ const EditItem = ({ onPress }: Pick <ItemProps , ' onPress' >) => {
52
+ return <Item title = " edit" onPress = { onPress } />;
53
+ };
49
54
50
- const ReusableHiddenItem = ({ onPress }) => (
51
- <HiddenItem title = " hidden2" onPress = { onPress } />
55
+ const ReusableHiddenItem = ({ onPress }: Pick < HiddenItemProps , ' onPress ' > ) => (
56
+ <HiddenItem title = " hidden2" onPress = { onPress } disabled />
52
57
);
53
58
54
59
export function UsageWithIcons({ navigation }) {
55
- useLayoutEffect (() => {
60
+ React . useLayoutEffect (() => {
56
61
navigation .setOptions ({
57
62
title: ' Demo' ,
63
+ // in your app, extract the arrow function into a separate component
64
+ // to avoid creating a new one every time
58
65
headerRight : () => (
59
66
<HeaderButtons HeaderButtonComponent = { MaterialHeaderButton } >
60
67
<EditItem onPress = { () => alert (' Edit' )} />
@@ -77,7 +84,7 @@ export function UsageWithIcons({ navigation }) {
77
84
});
78
85
}, [navigation ]);
79
86
80
- return <Text style = { { flex: 1 } } >demo!</Text >;
87
+ return <Text >demo!</Text >;
81
88
}
82
89
```
83
90
0 commit comments