Skip to content

Commit f2c4339

Browse files
authored
fix hint animation (#1363)
* fix hint animation * fix android error * Fix android tapping issue + remove hint on animation done * typing * lint * Fix iOS behaviour * typing * Fix removal after animation timing * removed log * Using now a single toggle to remove Hint component when hidden
1 parent 94548e5 commit f2c4339

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

generatedTypes/components/hint/index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export interface HintProps {
107107
interface HintState {
108108
targetLayout?: HintTargetFrame;
109109
targetLayoutInWindow?: HintTargetFrame;
110+
animationEnded: boolean;
110111
}
111112
/**
112113
* @description: Hint component for displaying a tooltip over wrapped component
@@ -122,12 +123,16 @@ declare class Hint extends Component<HintProps, HintState> {
122123
static positions: typeof HintPositions;
123124
targetRef: ElementRef<typeof RNView> | null;
124125
hintRef: ElementRef<typeof RNView> | null;
126+
animationDuration: number;
125127
state: {
126128
targetLayoutInWindow: undefined;
127129
targetLayout: HintTargetFrame | undefined;
130+
animationEnded: boolean;
128131
};
129132
visibleAnimated: Animated.Value;
130133
componentDidUpdate(prevProps: HintProps): void;
134+
animateHint: () => void;
135+
toggleAnimationEndedToRemoveHint: () => void;
131136
focusAccessibilityOnHint: () => void;
132137
setTargetRef: (ref: ElementRef<typeof RNView>) => void;
133138
setHintRef: (ref: ElementRef<typeof RNView>) => void;

src/components/hint/index.tsx

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export interface HintProps {
146146
interface HintState {
147147
targetLayout?: HintTargetFrame;
148148
targetLayoutInWindow?: HintTargetFrame;
149+
hintUnmounted: boolean;
149150
}
150151

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

166167
targetRef: ElementRef<typeof RNView> | null = null;
167168
hintRef: ElementRef<typeof RNView> | null = null;
169+
animationDuration = 170;
168170

169171
state = {
170172
targetLayoutInWindow: undefined,
171-
targetLayout: this.props.targetFrame
173+
targetLayout: this.props.targetFrame,
174+
hintUnmounted: false
172175
};
173176

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

176179
componentDidUpdate(prevProps: HintProps) {
177180
if (prevProps.visible !== this.props.visible) {
178-
Animated.timing(this.visibleAnimated, {
179-
toValue: Number(!!this.props.visible),
180-
duration: 170,
181-
useNativeDriver: true
182-
}).start();
181+
this.animateHint();
183182
}
184183
}
185184

185+
animateHint = () => {
186+
Animated.timing(this.visibleAnimated, {
187+
toValue: Number(!!this.props.visible),
188+
duration: this.animationDuration,
189+
useNativeDriver: true
190+
}).start(this.toggleAnimationEndedToRemoveHint);
191+
};
192+
193+
toggleAnimationEndedToRemoveHint = () => {
194+
this.setState({hintUnmounted: !this.props.visible});
195+
};
196+
186197
focusAccessibilityOnHint = () => {
187198
const {message} = this.props;
188199
const targetRefTag = findNodeHandle(this.targetRef);
@@ -444,13 +455,10 @@ class Hint extends Component<HintProps, HintState> {
444455
renderHint() {
445456
const {onPress, testID} = this.props;
446457
const opacity = onPress ? 0.9 : 1.0;
447-
const Container = onPress ? TouchableOpacity : View;
448-
458+
449459
if (this.showHint) {
450460
return (
451-
<Container
452-
activeOpacity={opacity}
453-
onPress={onPress}
461+
<View
454462
animated
455463
style={[
456464
{width: this.containerWidth},
@@ -462,19 +470,23 @@ class Hint extends Component<HintProps, HintState> {
462470
pointerEvents="box-none"
463471
testID={testID}
464472
>
473+
<TouchableOpacity activeOpacity={opacity} onPress={onPress}>
474+
{this.renderContent()}
475+
</TouchableOpacity>
465476
{this.renderHintTip()}
466-
{this.renderContent()}
467-
</Container>
477+
</View>
468478
);
469479
}
470480
}
471481

472482
renderHintContainer() {
473-
const {style, testID, ...others} = this.props;
483+
const {style, ...others} = this.props;
474484
return (
475485
<View
476486
{...others}
477-
testID={`${testID}.container`}
487+
// this view must be collapsable, don't pass testID or backgroundColor etc'.
488+
collapsable
489+
testID={undefined}
478490
style={[styles.container, style, this.getContainerPosition()]}
479491
>
480492
{this.renderHint()}
@@ -496,9 +508,8 @@ class Hint extends Component<HintProps, HintState> {
496508
}
497509

498510
render() {
499-
const {visible, onBackgroundPress, testID} = this.props;
500-
501-
if (!visible) {
511+
const {onBackgroundPress, testID} = this.props;
512+
if (!this.props.visible && this.state.hintUnmounted) {
502513
return this.props.children;
503514
}
504515

0 commit comments

Comments
 (0)