Skip to content

Fix/ Hint renders on wrong screen #1818

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions generatedTypes/src/components/hint/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export interface HintProps {
* Provide custom target position instead of wrapping a child
*/
targetFrame?: HintTargetFrame;
/**
* Open the hint using a Modal component
*/
useModal?: boolean;
/**
* Show side tips instead of the middle tip
*/
Expand Down Expand Up @@ -119,13 +123,19 @@ declare class Hint extends Component<HintProps, HintState> {
static displayName: string;
static defaultProps: {
position: HintPositions;
useModal: boolean;
};
static positions: typeof HintPositions;
targetRef: ElementRef<typeof RNView> | null;
hintRef: ElementRef<typeof RNView> | null;
animationDuration: number;
state: {
targetLayoutInWindow: undefined;
targetLayoutInWindow: {
x: number;
y: number;
width: number;
height: number;
} | undefined;
targetLayout: HintTargetFrame | undefined;
hintUnmounted: boolean;
};
Expand Down Expand Up @@ -153,9 +163,9 @@ declare class Hint extends Component<HintProps, HintState> {
get useSideTip(): boolean;
getTargetPositionOnScreen(): TARGET_POSITIONS;
getContainerPosition(): {
top: number | undefined;
left: number | undefined;
} | undefined;
top: number;
left: number;
};
getHintPosition(): HintPositionStyle;
getHintPadding(): Paddings;
getHintAnimatedStyle: () => {
Expand All @@ -165,6 +175,7 @@ declare class Hint extends Component<HintProps, HintState> {
}[];
};
getTipPosition(): Position;
renderOverlay(): JSX.Element | undefined;
renderHintTip(): JSX.Element;
renderContent(): JSX.Element;
renderHint(): JSX.Element | undefined;
Expand Down
1 change: 1 addition & 0 deletions src/components/hint/hint.api.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"type": "{x?: number, y?: number, width?: number, height?: number}",
"description": "Provide custom target position instead of wrapping a child"
},
{"name": "useModal", "type": "boolean", "description": "Open the hint using a Modal component"},
{"name": "useSideTip", "type": "boolean", "description": "Show side tips instead of the middle tip"},
{"name": "borderRadius", "type": "number", "description": "The hint's border radius"},
{"name": "edgeMargins", "type": "number", "description": "Hint margins from screen edges"},
Expand Down
94 changes: 54 additions & 40 deletions src/components/hint/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
findNodeHandle,
GestureResponderEvent,
ImageSourcePropType,
TouchableWithoutFeedback,
ImageStyle,
StyleProp,
TextStyle,
Expand Down Expand Up @@ -87,6 +88,10 @@ export interface HintProps {
* Provide custom target position instead of wrapping a child
*/
targetFrame?: HintTargetFrame;
/**
* Open the hint using a Modal component
*/
useModal?: boolean;
/**
* Show side tips instead of the middle tip
*/
Expand Down Expand Up @@ -157,7 +162,8 @@ class Hint extends Component<HintProps, HintState> {
static displayName = 'Hint';

static defaultProps = {
position: HintPositions.BOTTOM
position: HintPositions.BOTTOM,
useModal: true
};

static positions = HintPositions;
Expand All @@ -167,7 +173,7 @@ class Hint extends Component<HintProps, HintState> {
animationDuration = 170;

state = {
targetLayoutInWindow: undefined,
targetLayoutInWindow: undefined as {x: number, y: number, width: number, height: number} | undefined,
targetLayout: this.props.targetFrame,
hintUnmounted: !this.props.visible
};
Expand Down Expand Up @@ -246,14 +252,14 @@ class Hint extends Component<HintProps, HintState> {
}

get targetLayout() {
const {onBackgroundPress, targetFrame} = this.props;
const {onBackgroundPress, useModal, targetFrame} = this.props;
const {targetLayout, targetLayoutInWindow} = this.state;

if (targetFrame) {
return targetFrame;
}

return onBackgroundPress ? targetLayoutInWindow : targetLayout;
return onBackgroundPress && useModal ? targetLayoutInWindow : targetLayout;
}

get showHint() {
Expand Down Expand Up @@ -300,8 +306,9 @@ class Hint extends Component<HintProps, HintState> {

getContainerPosition() {
if (this.targetLayout) {
return {top: this.targetLayout.y, left: this.targetLayout.x};
return {top: this.targetLayout.y || 0, left: this.targetLayout.x || 0};
}
return {top: 0, left: 0};
}

getHintPosition() {
Expand Down Expand Up @@ -397,31 +404,34 @@ class Hint extends Component<HintProps, HintState> {
return tipPositionStyle;
}

// renderOverlay() {
// const {targetLayoutInWindow} = this.state;
// const {onBackgroundPress} = this.props;
// if (targetLayoutInWindow) {
// const containerPosition = this.getContainerPosition();
// return (
// <View
// style={[
// styles.overlay,
// {
// top: containerPosition.top - targetLayoutInWindow.y,
// left: containerPosition.left - targetLayoutInWindow.x,
// },
// ]}
// pointerEvents="box-none"
// >
// {onBackgroundPress && (
// <TouchableWithoutFeedback style={[StyleSheet.absoluteFillObject]} onPress={onBackgroundPress}>
// <View flex />
// </TouchableWithoutFeedback>
// )}
// </View>
// );
// }
// }
renderOverlay() {
const {targetLayoutInWindow} = this.state;
const {onBackgroundPress, backdropColor, testID} = this.props;
if (targetLayoutInWindow) {
const containerPosition = this.getContainerPosition();
return (
<Animated.View
style={[
styles.overlay,
{
top: containerPosition.top - targetLayoutInWindow.y,
left: containerPosition.left - targetLayoutInWindow.x,
backgroundColor: backdropColor,
opacity: this.visibleAnimated
}
]}
pointerEvents="box-none"
testID={`${testID}.overlay`}
>
{onBackgroundPress && (
<TouchableWithoutFeedback style={StyleSheet.absoluteFillObject} onPress={onBackgroundPress}>
<View flex/>
</TouchableWithoutFeedback>
)}
</Animated.View>
);
}
}

renderHintTip() {
const {position, color = DEFAULT_COLOR} = this.props;
Expand Down Expand Up @@ -549,7 +559,7 @@ class Hint extends Component<HintProps, HintState> {
}

render() {
const {onBackgroundPress, backdropColor, testID} = this.props;
const {onBackgroundPress, backdropColor, useModal, testID} = this.props;

if (!this.props.visible && this.state.hintUnmounted) {
return this.props.children || null;
Expand All @@ -558,7 +568,7 @@ class Hint extends Component<HintProps, HintState> {
return (
<>
{this.renderChildren()}
{onBackgroundPress ? (
{onBackgroundPress && useModal ? (
<Modal
visible={this.showHint}
animationType={backdropColor ? 'fade' : 'none'}
Expand All @@ -572,8 +582,11 @@ class Hint extends Component<HintProps, HintState> {
{this.renderHintContainer()}
</Modal>
) : (
// this.renderOverlay(),
this.renderHintContainer()
<>
{this.renderOverlay()}
{this.renderMockChildren()}
{this.renderHintContainer()}
</>
)}
</>
);
Expand All @@ -582,7 +595,8 @@ class Hint extends Component<HintProps, HintState> {

const styles = StyleSheet.create({
container: {
position: 'absolute'
position: 'absolute',
zIndex: 1
},
mockChildrenContainer: {
position: 'absolute'
Expand All @@ -601,11 +615,11 @@ const styles = StyleSheet.create({
right: undefined,
bottom: undefined
},
// overlay: {
// position: 'absolute',
// width: Constants.screenWidth,
// height: Constants.screenHeight
// },
overlay: {
position: 'absolute',
width: Constants.screenWidth,
height: Constants.screenHeight
},
animatedContainer: {
position: 'absolute'
},
Expand Down