Skip to content

Commit 856bc83

Browse files
authored
Fix/ hint container position (#1891)
* fix container position * remove zindex * set zIndex and elevation to hint with overlay
1 parent bb4ca86 commit 856bc83

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

generatedTypes/src/components/hint/index.d.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ declare class Hint extends Component<HintProps, HintState> {
163163
get useSideTip(): boolean;
164164
getTargetPositionOnScreen(): TARGET_POSITIONS;
165165
getContainerPosition(): {
166-
top: number;
167-
left: number;
168-
};
166+
top: number | undefined;
167+
left: number | undefined;
168+
} | undefined;
169169
getHintPosition(): HintPositionStyle;
170170
getHintPadding(): Paddings;
171171
getHintAnimatedStyle: () => {
@@ -175,6 +175,7 @@ declare class Hint extends Component<HintProps, HintState> {
175175
}[];
176176
};
177177
getTipPosition(): Position;
178+
isUsingModal: () => boolean | undefined;
178179
renderOverlay(): JSX.Element | undefined;
179180
renderHintTip(): JSX.Element;
180181
renderContent(): JSX.Element;

src/components/hint/index.tsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class Hint extends Component<HintProps, HintState> {
173173
animationDuration = 170;
174174

175175
state = {
176-
targetLayoutInWindow: undefined as {x: number, y: number, width: number, height: number} | undefined,
176+
targetLayoutInWindow: undefined as {x: number; y: number; width: number; height: number} | undefined,
177177
targetLayout: this.props.targetFrame,
178178
hintUnmounted: !this.props.visible
179179
};
@@ -305,9 +305,8 @@ class Hint extends Component<HintProps, HintState> {
305305

306306
getContainerPosition() {
307307
if (this.targetLayout) {
308-
return {top: this.targetLayout.y || 0, left: this.targetLayout.x || 0};
308+
return {top: this.targetLayout.y, left: this.targetLayout.x};
309309
}
310-
return {top: 0, left: 0};
311310
}
312311

313312
getHintPosition() {
@@ -403,11 +402,16 @@ class Hint extends Component<HintProps, HintState> {
403402
return tipPositionStyle;
404403
}
405404

405+
isUsingModal = () => {
406+
const {onBackgroundPress, useModal} = this.props;
407+
return onBackgroundPress && useModal;
408+
};
409+
406410
renderOverlay() {
407411
const {targetLayoutInWindow} = this.state;
408412
const {onBackgroundPress, backdropColor, testID} = this.props;
409413
if (targetLayoutInWindow) {
410-
const containerPosition = this.getContainerPosition();
414+
const containerPosition = this.getContainerPosition() as {top: number; left: number};
411415
return (
412416
<Animated.View
413417
style={[
@@ -515,7 +519,7 @@ class Hint extends Component<HintProps, HintState> {
515519
// this view must be collapsable, don't pass testID or backgroundColor etc'.
516520
collapsable
517521
testID={undefined}
518-
style={[styles.container, style, this.getContainerPosition()]}
522+
style={[styles.container, style, this.getContainerPosition(), !this.isUsingModal() && styles.overlayContainer]}
519523
>
520524
{this.renderHint()}
521525
</View>
@@ -558,7 +562,7 @@ class Hint extends Component<HintProps, HintState> {
558562
}
559563

560564
render() {
561-
const {onBackgroundPress, backdropColor, useModal, testID} = this.props;
565+
const {onBackgroundPress, backdropColor, testID} = this.props;
562566

563567
if (!this.props.visible && this.state.hintUnmounted) {
564568
return this.props.children || null;
@@ -567,7 +571,7 @@ class Hint extends Component<HintProps, HintState> {
567571
return (
568572
<>
569573
{this.renderChildren()}
570-
{onBackgroundPress && useModal ? (
574+
{this.isUsingModal() ? (
571575
<Modal
572576
visible={this.showHint}
573577
animationType={backdropColor ? 'fade' : 'none'}
@@ -594,8 +598,11 @@ class Hint extends Component<HintProps, HintState> {
594598

595599
const styles = StyleSheet.create({
596600
container: {
597-
position: 'absolute',
598-
zIndex: 1
601+
position: 'absolute'
602+
},
603+
overlayContainer: {
604+
zIndex: 10,
605+
elevation: 10
599606
},
600607
mockChildrenContainer: {
601608
position: 'absolute'

0 commit comments

Comments
 (0)