@@ -146,6 +146,7 @@ export interface HintProps {
146
146
interface HintState {
147
147
targetLayout ?: HintTargetFrame ;
148
148
targetLayoutInWindow ?: HintTargetFrame ;
149
+ hintUnmounted : boolean ;
149
150
}
150
151
151
152
/**
@@ -165,24 +166,34 @@ class Hint extends Component<HintProps, HintState> {
165
166
166
167
targetRef : ElementRef < typeof RNView > | null = null ;
167
168
hintRef : ElementRef < typeof RNView > | null = null ;
169
+ animationDuration = 170 ;
168
170
169
171
state = {
170
172
targetLayoutInWindow : undefined ,
171
- targetLayout : this . props . targetFrame
173
+ targetLayout : this . props . targetFrame ,
174
+ hintUnmounted : false
172
175
} ;
173
176
174
177
visibleAnimated = new Animated . Value ( Number ( ! ! this . props . visible ) ) ;
175
178
176
179
componentDidUpdate ( prevProps : HintProps ) {
177
180
if ( prevProps . visible !== this . props . visible ) {
178
- Animated . timing ( this . visibleAnimated , {
179
- toValue : Number ( ! ! this . props . visible ) ,
180
- duration : 170 ,
181
- useNativeDriver : true
182
- } ) . start ( ) ;
181
+ this . animateHint ( ) ;
183
182
}
184
183
}
185
184
185
+ animateHint = ( ) => {
186
+ Animated . timing ( this . visibleAnimated , {
187
+ toValue : Number ( ! ! this . props . visible ) ,
188
+ duration : this . animationDuration ,
189
+ useNativeDriver : true
190
+ } ) . start ( this . toggleAnimationEndedToRemoveHint ) ;
191
+ } ;
192
+
193
+ toggleAnimationEndedToRemoveHint = ( ) => {
194
+ this . setState ( { hintUnmounted : ! this . props . visible } ) ;
195
+ } ;
196
+
186
197
focusAccessibilityOnHint = ( ) => {
187
198
const { message} = this . props ;
188
199
const targetRefTag = findNodeHandle ( this . targetRef ) ;
@@ -444,13 +455,10 @@ class Hint extends Component<HintProps, HintState> {
444
455
renderHint ( ) {
445
456
const { onPress, testID} = this . props ;
446
457
const opacity = onPress ? 0.9 : 1.0 ;
447
- const Container = onPress ? TouchableOpacity : View ;
448
-
458
+
449
459
if ( this . showHint ) {
450
460
return (
451
- < Container
452
- activeOpacity = { opacity }
453
- onPress = { onPress }
461
+ < View
454
462
animated
455
463
style = { [
456
464
{ width : this . containerWidth } ,
@@ -462,19 +470,23 @@ class Hint extends Component<HintProps, HintState> {
462
470
pointerEvents = "box-none"
463
471
testID = { testID }
464
472
>
473
+ < TouchableOpacity activeOpacity = { opacity } onPress = { onPress } >
474
+ { this . renderContent ( ) }
475
+ </ TouchableOpacity >
465
476
{ this . renderHintTip ( ) }
466
- { this . renderContent ( ) }
467
- </ Container >
477
+ </ View >
468
478
) ;
469
479
}
470
480
}
471
481
472
482
renderHintContainer ( ) {
473
- const { style, testID , ...others } = this . props ;
483
+ const { style, ...others } = this . props ;
474
484
return (
475
485
< View
476
486
{ ...others }
477
- testID = { `${ testID } .container` }
487
+ // this view must be collapsable, don't pass testID or backgroundColor etc'.
488
+ collapsable
489
+ testID = { undefined }
478
490
style = { [ styles . container , style , this . getContainerPosition ( ) ] }
479
491
>
480
492
{ this . renderHint ( ) }
@@ -496,9 +508,8 @@ class Hint extends Component<HintProps, HintState> {
496
508
}
497
509
498
510
render ( ) {
499
- const { visible, onBackgroundPress, testID} = this . props ;
500
-
501
- if ( ! visible ) {
511
+ const { onBackgroundPress, testID} = this . props ;
512
+ if ( ! this . props . visible && this . state . hintUnmounted ) {
502
513
return this . props . children ;
503
514
}
504
515
0 commit comments