Skip to content

Commit 1873c66

Browse files
committed
fix: 🐛 Disable long press for onPress
1 parent bbd43b9 commit 1873c66

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/containers/ToastRender.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +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;
29+
private _pressStart: null | { startY: number; startAt: number };
3030
private _countdown: null | Function;
3131

3232
constructor(props: IProps) {
3333
super(props);
3434
this._heightContainer = 0;
35-
this._pressStartY = null;
35+
this._pressStart = null;
3636
this._positionToast = new Animated.Value(0);
3737
this._countdown = null;
3838
this.state = {
@@ -94,15 +94,15 @@ export class ToastRender extends React.Component<IProps, IState> {
9494
}
9595
},
9696
onPanResponderTerminationRequest: () => true,
97-
onPanResponderStart: (_, { dy }) => {
98-
this._pressStartY = dy;
97+
onPanResponderStart: (_, { dy: startY }) => {
98+
this._pressStart = { startY, startAt: Date.now() };
9999
this._countdown?.();
100100
},
101101
onPanResponderEnd: async (_, { dy }) => {
102102
let heightContainer = this._heightContainer;
103-
const startY = this._pressStartY!;
104-
this._pressStartY = null;
105-
if (Math.abs(dy - startY) < 7) {
103+
const { startY, startAt } = this._pressStart!;
104+
this._pressStart = null;
105+
if (startAt + 500 >= Date.now() && Math.abs(dy - startY) < 7) {
106106
this.props?.onPress?.();
107107
this._autoCloseHandler();
108108
} else if (dy < -(heightContainer / 3)) {

0 commit comments

Comments
 (0)