7
7
findNodeHandle ,
8
8
GestureResponderEvent ,
9
9
ImageSourcePropType ,
10
+ TouchableWithoutFeedback ,
10
11
ImageStyle ,
11
12
StyleProp ,
12
13
TextStyle ,
@@ -87,6 +88,10 @@ export interface HintProps {
87
88
* Provide custom target position instead of wrapping a child
88
89
*/
89
90
targetFrame ?: HintTargetFrame ;
91
+ /**
92
+ * Open the hint using a Modal component
93
+ */
94
+ useModal ?: boolean ;
90
95
/**
91
96
* Show side tips instead of the middle tip
92
97
*/
@@ -157,7 +162,8 @@ class Hint extends Component<HintProps, HintState> {
157
162
static displayName = 'Hint' ;
158
163
159
164
static defaultProps = {
160
- position : HintPositions . BOTTOM
165
+ position : HintPositions . BOTTOM ,
166
+ useModal : true
161
167
} ;
162
168
163
169
static positions = HintPositions ;
@@ -167,7 +173,7 @@ class Hint extends Component<HintProps, HintState> {
167
173
animationDuration = 170 ;
168
174
169
175
state = {
170
- targetLayoutInWindow : undefined ,
176
+ targetLayoutInWindow : undefined as { x : number , y : number , width : number , height : number } | undefined ,
171
177
targetLayout : this . props . targetFrame ,
172
178
hintUnmounted : ! this . props . visible
173
179
} ;
@@ -246,14 +252,14 @@ class Hint extends Component<HintProps, HintState> {
246
252
}
247
253
248
254
get targetLayout ( ) {
249
- const { onBackgroundPress, targetFrame} = this . props ;
255
+ const { onBackgroundPress, useModal , targetFrame} = this . props ;
250
256
const { targetLayout, targetLayoutInWindow} = this . state ;
251
257
252
258
if ( targetFrame ) {
253
259
return targetFrame ;
254
260
}
255
261
256
- return onBackgroundPress ? targetLayoutInWindow : targetLayout ;
262
+ return onBackgroundPress && useModal ? targetLayoutInWindow : targetLayout ;
257
263
}
258
264
259
265
get showHint ( ) {
@@ -300,8 +306,9 @@ class Hint extends Component<HintProps, HintState> {
300
306
301
307
getContainerPosition ( ) {
302
308
if ( this . targetLayout ) {
303
- return { top : this . targetLayout . y , left : this . targetLayout . x } ;
309
+ return { top : this . targetLayout . y || 0 , left : this . targetLayout . x || 0 } ;
304
310
}
311
+ return { top : 0 , left : 0 } ;
305
312
}
306
313
307
314
getHintPosition ( ) {
@@ -397,31 +404,34 @@ class Hint extends Component<HintProps, HintState> {
397
404
return tipPositionStyle ;
398
405
}
399
406
400
- // renderOverlay() {
401
- // const {targetLayoutInWindow} = this.state;
402
- // const {onBackgroundPress} = this.props;
403
- // if (targetLayoutInWindow) {
404
- // const containerPosition = this.getContainerPosition();
405
- // return (
406
- // <View
407
- // style={[
408
- // styles.overlay,
409
- // {
410
- // top: containerPosition.top - targetLayoutInWindow.y,
411
- // left: containerPosition.left - targetLayoutInWindow.x,
412
- // },
413
- // ]}
414
- // pointerEvents="box-none"
415
- // >
416
- // {onBackgroundPress && (
417
- // <TouchableWithoutFeedback style={[StyleSheet.absoluteFillObject]} onPress={onBackgroundPress}>
418
- // <View flex />
419
- // </TouchableWithoutFeedback>
420
- // )}
421
- // </View>
422
- // );
423
- // }
424
- // }
407
+ renderOverlay ( ) {
408
+ const { targetLayoutInWindow} = this . state ;
409
+ const { onBackgroundPress, backdropColor, testID} = this . props ;
410
+ if ( targetLayoutInWindow ) {
411
+ const containerPosition = this . getContainerPosition ( ) ;
412
+ return (
413
+ < Animated . View
414
+ style = { [
415
+ styles . overlay ,
416
+ {
417
+ top : containerPosition . top - targetLayoutInWindow . y ,
418
+ left : containerPosition . left - targetLayoutInWindow . x ,
419
+ backgroundColor : backdropColor ,
420
+ opacity : this . visibleAnimated
421
+ }
422
+ ] }
423
+ pointerEvents = "box-none"
424
+ testID = { `${ testID } .overlay` }
425
+ >
426
+ { onBackgroundPress && (
427
+ < TouchableWithoutFeedback style = { StyleSheet . absoluteFillObject } onPress = { onBackgroundPress } >
428
+ < View flex />
429
+ </ TouchableWithoutFeedback >
430
+ ) }
431
+ </ Animated . View >
432
+ ) ;
433
+ }
434
+ }
425
435
426
436
renderHintTip ( ) {
427
437
const { position, color = DEFAULT_COLOR } = this . props ;
@@ -549,7 +559,7 @@ class Hint extends Component<HintProps, HintState> {
549
559
}
550
560
551
561
render ( ) {
552
- const { onBackgroundPress, backdropColor, testID} = this . props ;
562
+ const { onBackgroundPress, backdropColor, useModal , testID} = this . props ;
553
563
554
564
if ( ! this . props . visible && this . state . hintUnmounted ) {
555
565
return this . props . children || null ;
@@ -558,7 +568,7 @@ class Hint extends Component<HintProps, HintState> {
558
568
return (
559
569
< >
560
570
{ this . renderChildren ( ) }
561
- { onBackgroundPress ? (
571
+ { onBackgroundPress && useModal ? (
562
572
< Modal
563
573
visible = { this . showHint }
564
574
animationType = { backdropColor ? 'fade' : 'none' }
@@ -572,8 +582,11 @@ class Hint extends Component<HintProps, HintState> {
572
582
{ this . renderHintContainer ( ) }
573
583
</ Modal >
574
584
) : (
575
- // this.renderOverlay(),
576
- this . renderHintContainer ( )
585
+ < >
586
+ { this . renderOverlay ( ) }
587
+ { this . renderMockChildren ( ) }
588
+ { this . renderHintContainer ( ) }
589
+ </ >
577
590
) }
578
591
</ >
579
592
) ;
@@ -582,7 +595,8 @@ class Hint extends Component<HintProps, HintState> {
582
595
583
596
const styles = StyleSheet . create ( {
584
597
container : {
585
- position : 'absolute'
598
+ position : 'absolute' ,
599
+ zIndex : 1
586
600
} ,
587
601
mockChildrenContainer : {
588
602
position : 'absolute'
@@ -601,11 +615,11 @@ const styles = StyleSheet.create({
601
615
right : undefined ,
602
616
bottom : undefined
603
617
} ,
604
- // overlay: {
605
- // position: 'absolute',
606
- // width: Constants.screenWidth,
607
- // height: Constants.screenHeight
608
- // },
618
+ overlay : {
619
+ position : 'absolute' ,
620
+ width : Constants . screenWidth ,
621
+ height : Constants . screenHeight
622
+ } ,
609
623
animatedContainer : {
610
624
position : 'absolute'
611
625
} ,
0 commit comments