1
1
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' ;
3
3
import { Color , getImage } from '../service' ;
4
4
import { ALERT_TYPE } from '../config' ;
5
5
@@ -26,11 +26,13 @@ interface IState {
26
26
export class ToastRender extends React . Component < IProps , IState > {
27
27
private _heightContainer : number ;
28
28
private _positionToast : Animated . Value ;
29
+ private _pressStartY : null | number ;
29
30
private _countdown : null | Function ;
30
31
31
32
constructor ( props : IProps ) {
32
33
super ( props ) ;
33
34
this . _heightContainer = 0 ;
35
+ this . _pressStartY = null ;
34
36
this . _positionToast = new Animated . Value ( 0 ) ;
35
37
this . _countdown = null ;
36
38
this . state = {
@@ -92,12 +94,18 @@ export class ToastRender extends React.Component<IProps, IState> {
92
94
}
93
95
} ,
94
96
onPanResponderTerminationRequest : ( ) => true ,
95
- onPanResponderStart : ( ) => {
97
+ onPanResponderStart : ( _ , { dy } ) => {
98
+ this . _pressStartY = dy ;
96
99
this . _countdown ?.( ) ;
97
100
} ,
98
101
onPanResponderEnd : async ( _ , { dy } ) => {
99
102
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 ) ) {
101
109
this . _animatedTiming ( - heightContainer ) . start ( this . props . onClose ) ;
102
110
} else {
103
111
this . _animatedTiming ( 0 ) . start ( this . _autoCloseHandler ) ;
@@ -106,13 +114,13 @@ export class ToastRender extends React.Component<IProps, IState> {
106
114
} ) ;
107
115
108
116
private _ModelRender = ( ) => {
109
- const { type, title, description, onPress , titleStyle, textBodyStyle } = this . props ;
117
+ const { type, title, description, titleStyle, textBodyStyle } = this . props ;
110
118
const { styles } = this . state ;
111
119
// if (model) {
112
120
// return model({ isDark, type, title, description });
113
121
// }
114
122
return (
115
- < TouchableOpacity activeOpacity = { 1 } style = { styles . cardContainer } onPress = { onPress } >
123
+ < View style = { styles . cardContainer } >
116
124
{ type && (
117
125
< React . Fragment >
118
126
< View style = { styles . backendImage } />
@@ -123,7 +131,7 @@ export class ToastRender extends React.Component<IProps, IState> {
123
131
{ title && < Text style = { StyleSheet . flatten ( [ styles . titleLabel , titleStyle ] ) } > { title } </ Text > }
124
132
{ description && < Text style = { StyleSheet . flatten ( [ styles . descLabel , textBodyStyle ] ) } > { description } </ Text > }
125
133
</ View >
126
- </ TouchableOpacity >
134
+ </ View >
127
135
) ;
128
136
} ;
129
137
0 commit comments