@@ -63,16 +63,18 @@ export default class DefaultPopup extends Component {
63
63
// onPress Feedback
64
64
containerScale : new Animated . Value ( 1 ) , // Directly set a scale
65
65
66
- onPress : null ,
66
+ onPressAndSlideOut : null ,
67
67
appIconSource : null ,
68
68
appTitle : null ,
69
69
timeText : null ,
70
70
title : null ,
71
71
body : null ,
72
72
} ;
73
73
this . _panResponder = PanResponder . create ( {
74
- onMoveShouldSetResponderCapture : ( ) => true ,
75
- onMoveShouldSetPanResponderCapture : ( ) => true ,
74
+ onStartShouldSetPanResponder : ( e , gestureState ) => true ,
75
+ // onStartShouldSetPanResponderCapture: (e, gestureState) => false,
76
+ onMoveShouldSetPanResponder : ( e , gestureState ) => true ,
77
+ // onMoveShouldSetPanResponderCapture: (e, gestureState) => false,
76
78
onPanResponderGrant : this . _onPanResponderGrant ,
77
79
onPanResponderMove : this . _onPanResponderMove ,
78
80
onPanResponderRelease : this . _onPanResponderRelease ,
@@ -81,20 +83,31 @@ export default class DefaultPopup extends Component {
81
83
82
84
_onPanResponderGrant = ( e , gestureState ) => {
83
85
// console.log('_onPanResponderGrant', gestureState); // DEBUG
86
+ this . onPressInFeedback ( ) ;
84
87
}
85
88
86
89
// https://facebook.github.io/react-native/docs/animations.html#tracking-gestures
87
90
_onPanResponderMove = ( e , gestureState ) => {
88
91
// console.log('_onPanResponderMove', gestureState); // DEBUG
89
92
const { containerDragOffsetY } = this . state ;
90
93
// Prevent dragging down too much
91
- if ( containerDragOffsetY . _value > 50 ) return ; // TODO: customize
92
- containerDragOffsetY . setValue ( gestureState . dy ) ;
94
+ const newDragOffset = gestureState . dy < 100 ? gestureState . dy : 100 ; // TODO: customize
95
+ containerDragOffsetY . setValue ( newDragOffset ) ;
93
96
}
94
97
95
98
_onPanResponderRelease = ( e , gestureState ) => {
96
99
// console.log('_onPanResponderRelease', gestureState); // DEBUG
97
- const { containerDragOffsetY } = this . state ;
100
+ const { onPressAndSlideOut, containerDragOffsetY } = this . state ;
101
+
102
+ // Present feedback
103
+ this . onPressOutFeedback ( ) ;
104
+
105
+ // Check if it is onPress
106
+ if ( gestureState . dx === 0 && gestureState . dy === 0 ) {
107
+ onPressAndSlideOut ( ) ;
108
+ }
109
+
110
+ // Check if it is leaving the screen
98
111
if ( containerDragOffsetY . _value < - 30 ) { // TODO: turn into constant
99
112
// 1. If leaving screen -> slide out
100
113
this . slideOutAndDismiss ( 200 ) ;
@@ -112,54 +125,54 @@ export default class DefaultPopup extends Component {
112
125
render ( ) {
113
126
const {
114
127
show, containerSlideOffsetY, containerDragOffsetY, containerScale,
115
- onPress , appIconSource, appTitle, timeText, title, body
128
+ onPressAndSlideOut , appIconSource, appTitle, timeText, title, body
116
129
} = this . state ;
117
130
131
+ if ( ! show ) {
132
+ return null ;
133
+ }
134
+
118
135
return (
119
- < View style = { styles . fullScreenContainer } >
120
- {
121
- ! ! show &&
122
- < Animated . View
123
- style = { getAnimatedContainerStyle ( { containerSlideOffsetY, containerDragOffsetY, containerScale} ) }
124
- { ...this . _panResponder . panHandlers } >
125
- < TouchableWithoutFeedback onPress = { onPress } onPressIn = { this . onPressInFeedback } onPressOut = { this . onPressOutFeedback } >
126
- < View >
127
- < View style = { styles . popupHeaderContainer } >
128
- < View style = { styles . headerIconContainer } >
129
- < Image style = { styles . headerIcon } source = { appIconSource || null } />
130
- </ View >
131
- < View style = { styles . headerTextContainer } >
132
- < Text style = { styles . headerText } numberOfLines = { 1 } > { appTitle || '' } </ Text >
133
- </ View >
134
- < View style = { styles . headerTimeContainer } >
135
- < Text style = { styles . headerTime } numberOfLines = { 1 } > { timeText || '' } </ Text >
136
- </ View >
137
- </ View >
138
- < View style = { styles . contentContainer } >
139
- < View style = { styles . contentTitleContainer } >
140
- < Text style = { styles . contentTitle } > { title || '' } </ Text >
141
- </ View >
142
- < View style = { styles . contentTextContainer } >
143
- < Text style = { styles . contentText } > { body || '' } </ Text >
144
- </ View >
145
- </ View >
136
+ < Animated . View
137
+ style = { getAnimatedContainerStyle ( { containerSlideOffsetY, containerDragOffsetY, containerScale} ) }
138
+ { ...this . _panResponder . panHandlers } >
139
+ < TouchableWithoutFeedback onPress = { onPressAndSlideOut } >
140
+ < View >
141
+ < View style = { styles . popupHeaderContainer } >
142
+ < View style = { styles . headerIconContainer } >
143
+ < Image style = { styles . headerIcon } source = { appIconSource || null } />
146
144
</ View >
147
- </ TouchableWithoutFeedback >
148
- </ Animated . View >
149
- }
150
-
151
- </ View >
145
+ < View style = { styles . headerTextContainer } >
146
+ < Text style = { styles . headerText } numberOfLines = { 1 } > { appTitle || '' } </ Text >
147
+ </ View >
148
+ < View style = { styles . headerTimeContainer } >
149
+ < Text style = { styles . headerTime } numberOfLines = { 1 } > { timeText || '' } </ Text >
150
+ </ View >
151
+ </ View >
152
+ < View style = { styles . contentContainer } >
153
+ < View style = { styles . contentTitleContainer } >
154
+ < Text style = { styles . contentTitle } > { title || '' } </ Text >
155
+ </ View >
156
+ < View style = { styles . contentTextContainer } >
157
+ < Text style = { styles . contentText } > { body || '' } </ Text >
158
+ </ View >
159
+ </ View >
160
+ </ View >
161
+ </ TouchableWithoutFeedback >
162
+ </ Animated . View >
152
163
) ;
153
164
}
154
165
155
166
onPressInFeedback = ( ) => {
167
+ // console.log('PressIn!'); // DEBUG
156
168
// Show feedback as soon as user press down
157
169
const { containerScale } = this . state ;
158
170
Animated . spring ( containerScale , { toValue : 0.95 , friction : 8 } )
159
171
. start ( ) ;
160
172
}
161
173
162
174
onPressOutFeedback = ( ) => {
175
+ // console.log('PressOut!'); // DEBUG
163
176
// Show feedback as soon as user press down
164
177
const { containerScale } = this . state ;
165
178
Animated . spring ( containerScale , { toValue : 1 , friction : 8 } )
@@ -192,7 +205,7 @@ export default class DefaultPopup extends Component {
192
205
193
206
countdownToSlideOut = ( ) => {
194
207
const slideOutTimer = setTimeout ( ( ) => {
195
- // this.slideOutAndDismiss(); // TEMP
208
+ this . slideOutAndDismiss ( ) ;
196
209
} , 4000 ) ; // TODO: customize
197
210
this . setState ( { slideOutTimer } ) ;
198
211
}
@@ -215,39 +228,27 @@ export default class DefaultPopup extends Component {
215
228
// Put message configs into state && show popup
216
229
const _messageConfig = messageConfig || { } ;
217
230
const { onPress : onPressCallback , appIconSource, appTitle, timeText, title, body } = _messageConfig ;
218
- const onPress = this . createOnPressWithCallback ( onPressCallback ) ;
231
+ const onPressAndSlideOut = this . createOnPressWithCallback ( onPressCallback ) ;
219
232
this . setState ( {
220
233
show : true ,
221
234
containerSlideOffsetY : new Animated . Value ( 0 ) ,
222
235
slideOutTimer : null ,
223
236
containerDragOffsetY : new Animated . Value ( 0 ) ,
224
237
containerScale : new Animated . Value ( 1 ) ,
225
- onPress , appIconSource, appTitle, timeText, title, body
238
+ onPressAndSlideOut , appIconSource, appTitle, timeText, title, body
226
239
} , this . slideIn ) ;
227
240
}
228
241
}
229
242
230
243
const styles = StyleSheet . create ( {
231
- fullScreenContainer : {
232
- ...StyleSheet . absoluteFillObject ,
233
- width : deviceWidth ,
234
- height : deviceHeight ,
235
- flex : 1 ,
236
- justifyContent : 'flex-start' ,
237
- alignItems : 'center' ,
238
- zIndex : 1000 ,
239
- } ,
240
- // fullScreenOverlay: {
241
- // ...StyleSheet.absoluteFillObject,
242
- // backgroundColor: 'grey', // DEBUG
243
- // },
244
244
popupContainer : {
245
+ position : 'absolute' ,
245
246
minHeight : 86 ,
246
247
width : deviceWidth - ( 8 * 2 ) ,
247
248
top : CONTAINER_MARGIN_TOP ,
248
249
backgroundColor : 'white' , // TEMP
249
250
borderRadius : 12 ,
250
- // overflow: 'hidden' ,
251
+ zIndex : 1000 ,
251
252
252
253
// === Shadows ===
253
254
// Android
0 commit comments