Skip to content

Commit b817415

Browse files
committed
fix: 🐛 Fixed press action and open press
1 parent 9528f44 commit b817415

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/containers/ToastRender.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { Animated, Image, LayoutChangeEvent, PanResponder, Platform, StyleSheet, Text, View, TouchableOpacity, StyleProp, TextStyle } from 'react-native';
2+
import { Animated, Image, LayoutChangeEvent, PanResponder, Platform, StyleSheet, Text, View, StyleProp, TextStyle } from 'react-native';
33
import { Color, getImage } from '../service';
44
import { ALERT_TYPE } from '../config';
55

@@ -26,11 +26,13 @@ interface IState {
2626
export class ToastRender extends React.Component<IProps, IState> {
2727
private _heightContainer: number;
2828
private _positionToast: Animated.Value;
29+
private _pressStartY: null | number;
2930
private _countdown: null | Function;
3031

3132
constructor(props: IProps) {
3233
super(props);
3334
this._heightContainer = 0;
35+
this._pressStartY = null;
3436
this._positionToast = new Animated.Value(0);
3537
this._countdown = null;
3638
this.state = {
@@ -92,12 +94,18 @@ export class ToastRender extends React.Component<IProps, IState> {
9294
}
9395
},
9496
onPanResponderTerminationRequest: () => true,
95-
onPanResponderStart: () => {
97+
onPanResponderStart: (_, { dy }) => {
98+
this._pressStartY = dy;
9699
this._countdown?.();
97100
},
98101
onPanResponderEnd: async (_, { dy }) => {
99102
let heightContainer = this._heightContainer;
100-
if (dy < -(heightContainer / 3)) {
103+
const startY = this._pressStartY!;
104+
this._pressStartY = null;
105+
if (Math.abs(dy - startY) < 7) {
106+
this.props?.onPress?.();
107+
this._autoCloseHandler();
108+
} else if (dy < -(heightContainer / 3)) {
101109
this._animatedTiming(-heightContainer).start(this.props.onClose);
102110
} else {
103111
this._animatedTiming(0).start(this._autoCloseHandler);
@@ -106,13 +114,13 @@ export class ToastRender extends React.Component<IProps, IState> {
106114
});
107115

108116
private _ModelRender = () => {
109-
const { type, title, description, onPress, titleStyle, textBodyStyle } = this.props;
117+
const { type, title, description, titleStyle, textBodyStyle } = this.props;
110118
const { styles } = this.state;
111119
// if (model) {
112120
// return model({ isDark, type, title, description });
113121
// }
114122
return (
115-
<TouchableOpacity activeOpacity={1} style={styles.cardContainer} onPress={onPress}>
123+
<View style={styles.cardContainer}>
116124
{type && (
117125
<React.Fragment>
118126
<View style={styles.backendImage} />
@@ -123,7 +131,7 @@ export class ToastRender extends React.Component<IProps, IState> {
123131
{title && <Text style={StyleSheet.flatten([styles.titleLabel, titleStyle])}>{title}</Text>}
124132
{description && <Text style={StyleSheet.flatten([styles.descLabel, textBodyStyle])}>{description}</Text>}
125133
</View>
126-
</TouchableOpacity>
134+
</View>
127135
);
128136
};
129137

0 commit comments

Comments
 (0)