Skip to content

Commit f2e3cb7

Browse files
committed
fix passing props to HeaderButton
1 parent fbb6251 commit f2e3cb7

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ static navigationOptions = {
6464

6565
`HeaderButton` accepts:
6666

67-
| prop and type | description | note |
68-
| --------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
69-
| IconComponent?: React.ComponentType<\*> | component to use for the icons, foe example from `react-native-vector-icons` | |
70-
| iconSize?: number | iconSize | |
71-
| color?: string | color of icons and buttons | |
72-
| touchableBackground?: any | the lib internally uses `react-native-platform-touchable` for rendering touchables. You may use this prop to specify the android ripple effect. | Defaults to `Touchable.SelectableBackgroundBorderless()`, valid values are [here](https://github.com/react-community/react-native-platform-touchable#statics). |
73-
| touchableForeground?: any | the lib internally uses `react-native-platform-touchable` for rendering touchables. You may use this prop to specify the android ripple effect. | Not defined by default, valid values are [here](https://github.com/react-community/react-native-platform-touchable#statics). |
67+
| prop and type | description | note |
68+
| --------------------------------------- | ---------------------------------------------------------------------------- | ---- |
69+
| IconComponent?: React.ComponentType<\*> | component to use for the icons, foe example from `react-native-vector-icons` | |
70+
| iconSize?: number | iconSize | |
71+
| color?: string | color of icons and buttons | |
72+
73+
You may also pass other props that will be passed to the underlying `react-native-platform-touchable`. For example, pass [`background`](https://github.com/react-community/react-native-platform-touchable#additional-props-used-by-touchablenativefeedback--default-android) prop for different ripple effects.
7474

7575
Please note that `HeaderButton` also requires other props to function correctly. Some of these props are passed from `<Item .. />` (such as `iconName`) and also `<HeaderButtons ... />`. When wrapping `HeaderButton` it is thus important to not forget to pass down all props the wrapping component receives (this is easy using the spread operator), as documented in the [quick example](#quick-example).
7676

example/navbar-buttons-demo/screens/UsageCustomRipple.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Touchable from 'react-native-platform-touchable';
1010
const DisableableHeaderButton = props => (
1111
<HeaderButton
1212
{...props}
13-
touchableBackground={Touchable.Ripple('red', true)}
13+
background={Touchable.Ripple('red', true)}
1414
IconComponent={Ionicons}
1515
iconSize={23}
1616
color="blue"

src/HeaderButton.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,15 @@ export type VisibleButtonProps = $Exact<{
2828
}>;
2929

3030
type OtherProps = {
31-
touchableBackground: any,
32-
touchableForeground: any,
31+
background: any,
3332
getButtonElement: VisibleButtonProps => React.Element<any>,
3433
};
3534

3635
export class HeaderButton extends React.PureComponent<
3736
HeaderButtonProps & VisibleButtonProps & OtherProps
3837
> {
3938
static defaultProps = {
40-
touchableBackground: Touchable.SelectableBackgroundBorderless(),
39+
background: Touchable.SelectableBackgroundBorderless(),
4140
};
4241
render() {
4342
const {
@@ -46,28 +45,32 @@ export class HeaderButton extends React.PureComponent<
4645
testID,
4746
getButtonElement,
4847
ButtonElement: ButtonElementOverride,
49-
touchableBackground,
50-
touchableForeground,
48+
background,
49+
iconName,
50+
title,
51+
buttonStyle,
52+
IconComponent,
53+
iconSize,
54+
color,
55+
other,
5156
} = this.props;
5257

53-
const { iconName, title, buttonStyle, IconComponent, iconSize, color } = this.props;
54-
5558
const ButtonElement =
5659
ButtonElementOverride ||
5760
getButtonElement({ iconName, title, buttonStyle, IconComponent, iconSize, color });
5861

5962
return (
6063
<Touchable
61-
background={touchableBackground}
62-
foreground={touchableForeground}
64+
background={background}
6365
disabled={!onPress}
6466
onPress={onPress}
6567
hitSlop={BUTTON_HIT_SLOP}
6668
style={[styles.buttonContainer, buttonWrapperStyle]}
6769
testID={testID}
70+
{...other}
6871
>
6972
<View>{ButtonElement}</View>
70-
</RenderedComponent>
73+
</Touchable>
7174
);
7275
}
7376
}

0 commit comments

Comments
 (0)