Skip to content

Commit 438b1d1

Browse files
authored
Stop using AnimatableManager in Hint (#1125)
1 parent 1ff8e19 commit 438b1d1

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

src/components/hint/index.js

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
import _ from 'lodash';
33
import PropTypes from 'prop-types';
44
import React from 'react';
5-
import {StyleSheet, AccessibilityInfo, findNodeHandle} from 'react-native';
6-
import {View as AnimatableView} from 'react-native-animatable';
7-
import {Typography, Spacings, Colors, BorderRadiuses, AnimatableManager} from '../../style';
5+
import {Animated, StyleSheet, AccessibilityInfo, findNodeHandle} from 'react-native';
6+
import {Typography, Spacings, Colors, BorderRadiuses} from '../../style';
87
import {Constants} from '../../helpers';
98
import {BaseComponent} from '../../commons';
109
import View from '../view';
@@ -15,7 +14,7 @@ import Modal from '../modal';
1514
const sideTip = require('./assets/hintTipSide.png');
1615
const middleTip = require('./assets/hintTipMiddle.png');
1716

18-
const DEFAULT_COLOR = Colors.blue30;
17+
const DEFAULT_COLOR = Colors.primary;
1918
const DEFAULT_HINT_OFFSET = Spacings.s4;
2019
const DEFAULT_EDGE_MARGINS = Spacings.s5;
2120
const HINT_POSITIONS = {
@@ -28,17 +27,6 @@ const TARGET_POSITIONS = {
2827
CENTER: 'center'
2928
};
3029

31-
AnimatableManager.loadAnimationDefinitions({
32-
hintAppearDown: {
33-
from: {opacity: 0, translateY: 20},
34-
to: {opacity: 1, translateY: 0}
35-
},
36-
hintAppearUp: {
37-
from: {opacity: 0, translateY: -20},
38-
to: {opacity: 1, translateY: 0}
39-
}
40-
});
41-
4230
/**
4331
* @description: Hint component for displaying a tooltip over wrapped component
4432
* @example: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/HintsScreen.js
@@ -125,6 +113,17 @@ class Hint extends BaseComponent {
125113
targetLayout: this.props.targetFrame
126114
};
127115

116+
visibleAnimated = new Animated.Value(Number(!!this.props.visible))
117+
118+
componentDidUpdate(prevProps) {
119+
if (prevProps.visible !== this.props.visible) {
120+
Animated.timing(this.visibleAnimated, {
121+
toValue: Number(!!this.props.visible),
122+
duration: 170
123+
}).start();
124+
}
125+
}
126+
128127
focusAccessibilityOnHint = () => {
129128
const {message} = this.props;
130129
const targetRefTag = findNodeHandle(this.targetRef);
@@ -264,6 +263,17 @@ class Hint extends BaseComponent {
264263
return paddings;
265264
}
266265

266+
getHintAnimatedStyle = () => {
267+
const {position} = this.props;
268+
const translateY = position === HINT_POSITIONS.TOP ? -10 : 10;
269+
return {
270+
opacity: this.visibleAnimated,
271+
transform: [{
272+
translateY: this.visibleAnimated.interpolate({inputRange: [0, 1], outputRange: [translateY, 0]})
273+
}]
274+
};
275+
}
276+
267277
getTipPosition() {
268278
const {position} = this.getThemeProps();
269279
const tipPositionStyle = {};
@@ -343,19 +353,18 @@ class Hint extends BaseComponent {
343353
}
344354

345355
renderHint() {
346-
const {position, message, messageStyle, icon, iconStyle, borderRadius, color, testID} = this.getThemeProps();
347-
const shownUp = position === HINT_POSITIONS.TOP;
356+
const {message, messageStyle, icon, iconStyle, borderRadius, color, testID} = this.getThemeProps();
348357

349358
if (this.showHint) {
350359
return (
351-
<AnimatableView
352-
animation={shownUp ? AnimatableManager.animations.hintAppearUp : AnimatableManager.animations.hintAppearDown}
353-
duration={200}
360+
<View
361+
animated
354362
style={[
355363
{width: this.containerWidth},
356364
styles.animatedContainer,
357365
this.getHintPosition(),
358-
this.getHintPadding()
366+
this.getHintPadding(),
367+
this.getHintAnimatedStyle()
359368
]}
360369
pointerEvents="box-none"
361370
testID={testID}
@@ -371,7 +380,7 @@ class Hint extends BaseComponent {
371380
{icon && <Image source={icon} style={[styles.icon, iconStyle]}/>}
372381
<Text style={[styles.hintMessage, messageStyle]}>{message}</Text>
373382
</View>
374-
</AnimatableView>
383+
</View>
375384
);
376385
}
377386
}

0 commit comments

Comments
 (0)