Skip to content

fix hint animation #1363

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 11 commits into from
Jul 4, 2021
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
5 changes: 5 additions & 0 deletions generatedTypes/components/hint/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export interface HintProps {
interface HintState {
targetLayout?: HintTargetFrame;
targetLayoutInWindow?: HintTargetFrame;
animationEnded: boolean;
}
/**
* @description: Hint component for displaying a tooltip over wrapped component
Expand All @@ -122,12 +123,16 @@ declare class Hint extends Component<HintProps, HintState> {
static positions: typeof HintPositions;
targetRef: ElementRef<typeof RNView> | null;
hintRef: ElementRef<typeof RNView> | null;
animationDuration: number;
state: {
targetLayoutInWindow: undefined;
targetLayout: HintTargetFrame | undefined;
animationEnded: boolean;
};
visibleAnimated: Animated.Value;
componentDidUpdate(prevProps: HintProps): void;
animateHint: () => void;
toggleAnimationEndedToRemoveHint: () => void;
focusAccessibilityOnHint: () => void;
setTargetRef: (ref: ElementRef<typeof RNView>) => void;
setHintRef: (ref: ElementRef<typeof RNView>) => void;
Expand Down
47 changes: 29 additions & 18 deletions src/components/hint/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export interface HintProps {
interface HintState {
targetLayout?: HintTargetFrame;
targetLayoutInWindow?: HintTargetFrame;
hintUnmounted: boolean;
}

/**
Expand All @@ -165,24 +166,34 @@ class Hint extends Component<HintProps, HintState> {

targetRef: ElementRef<typeof RNView> | null = null;
hintRef: ElementRef<typeof RNView> | null = null;
animationDuration = 170;

state = {
targetLayoutInWindow: undefined,
targetLayout: this.props.targetFrame
targetLayout: this.props.targetFrame,
hintUnmounted: false
};

visibleAnimated = new Animated.Value(Number(!!this.props.visible));

componentDidUpdate(prevProps: HintProps) {
if (prevProps.visible !== this.props.visible) {
Animated.timing(this.visibleAnimated, {
toValue: Number(!!this.props.visible),
duration: 170,
useNativeDriver: true
}).start();
this.animateHint();
}
}

animateHint = () => {
Animated.timing(this.visibleAnimated, {
toValue: Number(!!this.props.visible),
duration: this.animationDuration,
useNativeDriver: true
}).start(this.toggleAnimationEndedToRemoveHint);
};

toggleAnimationEndedToRemoveHint = () => {
this.setState({hintUnmounted: !this.props.visible});
};

focusAccessibilityOnHint = () => {
const {message} = this.props;
const targetRefTag = findNodeHandle(this.targetRef);
Expand Down Expand Up @@ -444,13 +455,10 @@ class Hint extends Component<HintProps, HintState> {
renderHint() {
const {onPress, testID} = this.props;
const opacity = onPress ? 0.9 : 1.0;
const Container = onPress ? TouchableOpacity : View;


if (this.showHint) {
return (
<Container
activeOpacity={opacity}
onPress={onPress}
<View
animated
style={[
{width: this.containerWidth},
Expand All @@ -462,19 +470,23 @@ class Hint extends Component<HintProps, HintState> {
pointerEvents="box-none"
testID={testID}
>
<TouchableOpacity activeOpacity={opacity} onPress={onPress}>
{this.renderContent()}
</TouchableOpacity>
{this.renderHintTip()}
{this.renderContent()}
</Container>
</View>
);
}
}

renderHintContainer() {
const {style, testID, ...others} = this.props;
const {style, ...others} = this.props;
return (
<View
{...others}
testID={`${testID}.container`}
// this view must be collapsable, don't pass testID or backgroundColor etc'.
collapsable
testID={undefined}
style={[styles.container, style, this.getContainerPosition()]}
>
{this.renderHint()}
Expand All @@ -496,9 +508,8 @@ class Hint extends Component<HintProps, HintState> {
}

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

if (!visible) {
const {onBackgroundPress, testID} = this.props;
if (!this.props.visible && this.state.hintUnmounted) {
return this.props.children;
}

Expand Down