Skip to content

Commit 9b86a09

Browse files
committed
add onPress to show method
1 parent 10e1206 commit 9b86a09

File tree

4 files changed

+35
-16
lines changed

4 files changed

+35
-16
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ Headers are one of:
99

1010
- `Added`, `Changed`, `Removed` or `Fixed`.
1111

12+
## [next]
13+
14+
### Added
15+
16+
- Add `onPress` to `Toast.show` method
17+
- Export `BaseToast` component to allow styling
18+
1219
## [1.3.7]
1320

1421
### Added

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ Toast.show({
7171
topOffset: 30,
7272
bottomOffset: 40,
7373
onShow: () => {},
74-
onHide: () => {}
74+
onHide: () => {},
75+
onPress: () => {}
7576
});
7677
```
7778

src/components/base/index.js

+16-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function BaseToast({
1111
trailingIcon,
1212
text1,
1313
text2,
14+
onPress,
1415
onLeadingIconPress,
1516
onTrailingIconPress,
1617
style,
@@ -20,15 +21,19 @@ function BaseToast({
2021
trailingIconStyle,
2122
contentContainerStyle,
2223
text1Style,
23-
text2Style
24+
text2Style,
25+
activeOpacity
2426
}) {
2527
return (
26-
<View style={[styles.base, styles.borderLeft, style]}>
28+
<TouchableOpacity
29+
style={[styles.base, styles.borderLeft, style]}
30+
onPress={onPress}
31+
activeOpacity={activeOpacity}>
2732
{leadingIcon && (
2833
<TouchableOpacity
2934
style={[styles.leadingIconContainer, leadingIconContainerStyle]}
3035
onPress={onLeadingIconPress}
31-
activeOpacity={1}>
36+
activeOpacity={activeOpacity}>
3237
<Icon
3338
style={[styles.leadingIcon, leadingIconStyle]}
3439
source={leadingIcon}
@@ -57,14 +62,14 @@ function BaseToast({
5762
<TouchableOpacity
5863
style={[styles.trailingIconContainer, trailingIconContainerStyle]}
5964
onPress={onTrailingIconPress}
60-
activeOpacity={1}>
65+
activeOpacity={activeOpacity}>
6166
<Icon
6267
style={[styles.trailingIcon, trailingIconStyle]}
6368
source={trailingIcon}
6469
/>
6570
</TouchableOpacity>
6671
)}
67-
</View>
72+
</TouchableOpacity>
6873
);
6974
}
7075

@@ -75,6 +80,7 @@ BaseToast.propTypes = {
7580
trailingIcon: Icon.propTypes.source,
7681
text1: PropTypes.string,
7782
text2: PropTypes.string,
83+
onPress: PropTypes.func,
7884
onTrailingIconPress: PropTypes.func,
7985
onLeadingIconPress: PropTypes.func,
8086
style: ViewPropTypes.style,
@@ -84,14 +90,16 @@ BaseToast.propTypes = {
8490
trailingIconStyle: ViewPropTypes.style,
8591
contentContainerStyle: ViewPropTypes.style,
8692
text1Style: ViewPropTypes.style,
87-
text2Style: ViewPropTypes.style
93+
text2Style: ViewPropTypes.style,
94+
activeOpacity: PropTypes.number
8895
};
8996

9097
BaseToast.defaultProps = {
9198
leadingIcon: undefined,
9299
trailingIcon: icons.close,
93100
text1: undefined,
94101
text2: undefined,
102+
onPress: undefined,
95103
onLeadingIconPress: undefined,
96104
onTrailingIconPress: undefined,
97105
style: undefined,
@@ -101,7 +109,8 @@ BaseToast.defaultProps = {
101109
trailingIconStyle: undefined,
102110
contentContainerStyle: undefined,
103111
text1Style: undefined,
104-
text2Style: undefined
112+
text2Style: undefined,
113+
activeOpacity: 0.8
105114
};
106115

107116
export default BaseToast;

src/index.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import styles from './styles';
1111
const FRICTION = 8;
1212

1313
const defaultComponentsConfig = {
14-
success: ({ hide, text1, text2 }) => (
15-
<SuccessToast onTrailingIconPress={hide} text1={text1} text2={text2} />
14+
success: ({ hide, ...rest }) => (
15+
<SuccessToast {...rest} onTrailingIconPress={hide} />
1616
),
17-
error: ({ hide, text1, text2 }) => (
18-
<ErrorToast onTrailingIconPress={hide} text1={text1} text2={text2} />
17+
error: ({ hide, ...rest }) => (
18+
<ErrorToast {...rest} onTrailingIconPress={hide} />
1919
),
20-
info: ({ hide, text1, text2 }) => (
21-
<InfoToast onTrailingIconPress={hide} text1={text1} text2={text2} />
20+
info: ({ hide, ...rest }) => (
21+
<InfoToast {...rest} onTrailingIconPress={hide} />
2222
)
2323
};
2424

@@ -47,6 +47,7 @@ const getInitialState = (props) => {
4747
text1: undefined,
4848
text2: undefined,
4949

50+
onPress: undefined,
5051
onShow,
5152
onHide
5253
};
@@ -98,7 +99,7 @@ class Toast extends Component {
9899
};
99100

100101
this.panResponder = PanResponder.create({
101-
onStartShouldSetPanResponder: () => true,
102+
onMoveShouldSetPanResponder: () => true,
102103
onPanResponderMove: (event, gesture) => {
103104
this._animateMovement(gesture);
104105
},
@@ -272,7 +273,8 @@ class Toast extends Component {
272273
'text1',
273274
'text2',
274275
'hide',
275-
'show'
276+
'show',
277+
'onPress'
276278
]
277279
}),
278280
props: { ...customProps },

0 commit comments

Comments
 (0)