Skip to content

Commit 0ce5f69

Browse files
committed
Fix/ hint container position (#1891)
* fix container position * remove zindex * set zIndex and elevation to hint with overlay
1 parent 9b4bd32 commit 0ce5f69

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
};
@@ -306,9 +306,8 @@ class Hint extends Component<HintProps, HintState> {
306306

307307
getContainerPosition() {
308308
if (this.targetLayout) {
309-
return {top: this.targetLayout.y || 0, left: this.targetLayout.x || 0};
309+
return {top: this.targetLayout.y, left: this.targetLayout.x};
310310
}
311-
return {top: 0, left: 0};
312311
}
313312

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

406+
isUsingModal = () => {
407+
const {onBackgroundPress, useModal} = this.props;
408+
return onBackgroundPress && useModal;
409+
};
410+
407411
renderOverlay() {
408412
const {targetLayoutInWindow} = this.state;
409413
const {onBackgroundPress, backdropColor, testID} = this.props;
410414
if (targetLayoutInWindow) {
411-
const containerPosition = this.getContainerPosition();
415+
const containerPosition = this.getContainerPosition() as {top: number; left: number};
412416
return (
413417
<Animated.View
414418
style={[
@@ -516,7 +520,7 @@ class Hint extends Component<HintProps, HintState> {
516520
// this view must be collapsable, don't pass testID or backgroundColor etc'.
517521
collapsable
518522
testID={undefined}
519-
style={[styles.container, style, this.getContainerPosition()]}
523+
style={[styles.container, style, this.getContainerPosition(), !this.isUsingModal() && styles.overlayContainer]}
520524
>
521525
{this.renderHint()}
522526
</View>
@@ -559,7 +563,7 @@ class Hint extends Component<HintProps, HintState> {
559563
}
560564

561565
render() {
562-
const {onBackgroundPress, backdropColor, useModal, testID} = this.props;
566+
const {onBackgroundPress, backdropColor, testID} = this.props;
563567

564568
if (!this.props.visible && this.state.hintUnmounted) {
565569
return this.props.children || null;
@@ -568,7 +572,7 @@ class Hint extends Component<HintProps, HintState> {
568572
return (
569573
<>
570574
{this.renderChildren()}
571-
{onBackgroundPress && useModal ? (
575+
{this.isUsingModal() ? (
572576
<Modal
573577
visible={this.showHint}
574578
animationType={backdropColor ? 'fade' : 'none'}
@@ -595,8 +599,11 @@ class Hint extends Component<HintProps, HintState> {
595599

596600
const styles = StyleSheet.create({
597601
container: {
598-
position: 'absolute',
599-
zIndex: 1
602+
position: 'absolute'
603+
},
604+
overlayContainer: {
605+
zIndex: 10,
606+
elevation: 10
600607
},
601608
mockChildrenContainer: {
602609
position: 'absolute'

0 commit comments

Comments
 (0)