@@ -76,17 +76,28 @@ export function Toast({ delay = consts.DEFAULT_DELAY, ...props }: Props) {
76
76
timer . current = setTimeout ( ( ) => props . setIsVisible ( false ) , delay ) ;
77
77
}
78
78
const isBelowFinalPosition = gestureState . dy > 0 ; // use 0 as event gives relative position to where view was
79
+ const newPosition = FINAL_POSITION + gestureState . dy ;
79
80
if ( isBelowFinalPosition ) {
80
81
// add resistance when moving down
81
- const newPosition =
82
- FINAL_POSITION + gestureState . dy ** DRAG_RESISTANCE ;
82
+ y . current . setValue ( newPosition ** DRAG_RESISTANCE ) ;
83
+ } else {
84
+ // is going up
85
+ // make fling gesture)
83
86
y . current . setValue ( newPosition ) ;
84
87
}
85
88
} ,
86
89
onStartShouldSetPanResponder : ( ) => true ,
87
90
onPanResponderRelease : ( _ , gestureState ) => {
88
91
if ( gestureState . dy > 0 ) {
92
+ // going down
89
93
Animated . spring ( y . current , SHOW_ANIM_CONFIG ) . start ( ) ;
94
+ } else {
95
+ // going up
96
+ console . log ( { vY : gestureState . vy } ) ;
97
+ Animated . decay ( y . current , {
98
+ velocity : gestureState . vy * 0.3 ,
99
+ useNativeDriver : true ,
100
+ } ) . start ( ) ;
90
101
}
91
102
} ,
92
103
} )
@@ -114,21 +125,28 @@ export function Toast({ delay = consts.DEFAULT_DELAY, ...props }: Props) {
114
125
} ) ;
115
126
} , [ props ] ) ;
116
127
117
- // useEffect necessary otherwise causes too many pending callbacks issue.
128
+ const isFirstMount = useRef ( true ) ;
129
+
130
+ // useEffect necessary otherwise causes bad setState issue
118
131
useEffect ( ( ) => {
132
+ // create a copy because current value will have changed (react-warning)
133
+ const yCopy = y . current ;
134
+ yCopy . addListener ( ( { value } ) => {
135
+ // call hide function if above screen without animation.
136
+ if ( value < TOP_OF_SCREEN && ! isFirstMount ) hide ( ) ;
137
+ } ) ;
119
138
if ( props . isVisible ) {
120
139
show ( ) ;
121
140
if ( props . autoDismiss !== false ) {
122
141
timer . current = setTimeout ( ( ) => props . setIsVisible ( false ) , delay ) ;
123
142
}
124
143
}
125
-
144
+ // need a way for it to not call hide when it is initially mounted.
126
145
if ( ! props . isVisible ) {
127
146
if ( timer . current ) clearTimeout ( timer . current ) ;
128
- // check this works - may need a listener instead of number conversion
129
- if ( Number ( y . current ) !== INITIAL_POSITION ) hide ( ) ;
147
+ // @todo fix this.
148
+ if ( yCopy !== INITIAL_POSITION ) hide ( ) ;
130
149
}
131
-
132
150
// eslint-disable-next-line react-hooks/exhaustive-deps
133
151
} , [ props . isVisible ] ) ;
134
152
@@ -192,7 +210,7 @@ const getToastTypeColor = (toastType: ToastType | undefined) => {
192
210
}
193
211
} ;
194
212
195
- const BORDER_RADIUS = 12 ;
213
+ const BORDER_RADIUS = 8 ;
196
214
197
215
const styles = StyleSheet . create ( {
198
216
container : {
@@ -210,7 +228,7 @@ const styles = StyleSheet.create({
210
228
borderColor : '#BBB' ,
211
229
} ,
212
230
accentColumn : {
213
- width : 10 ,
231
+ width : 8 ,
214
232
backgroundColor : 'white' ,
215
233
borderTopLeftRadius : BORDER_RADIUS ,
216
234
borderBottomLeftRadius : BORDER_RADIUS ,
0 commit comments