2
2
import _ from 'lodash' ;
3
3
import PropTypes from 'prop-types' ;
4
4
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' ;
8
7
import { Constants } from '../../helpers' ;
9
8
import { BaseComponent } from '../../commons' ;
10
9
import View from '../view' ;
@@ -15,7 +14,7 @@ import Modal from '../modal';
15
14
const sideTip = require ( './assets/hintTipSide.png' ) ;
16
15
const middleTip = require ( './assets/hintTipMiddle.png' ) ;
17
16
18
- const DEFAULT_COLOR = Colors . blue30 ;
17
+ const DEFAULT_COLOR = Colors . primary ;
19
18
const DEFAULT_HINT_OFFSET = Spacings . s4 ;
20
19
const DEFAULT_EDGE_MARGINS = Spacings . s5 ;
21
20
const HINT_POSITIONS = {
@@ -28,17 +27,6 @@ const TARGET_POSITIONS = {
28
27
CENTER : 'center'
29
28
} ;
30
29
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
-
42
30
/**
43
31
* @description : Hint component for displaying a tooltip over wrapped component
44
32
* @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 {
125
113
targetLayout : this . props . targetFrame
126
114
} ;
127
115
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
+
128
127
focusAccessibilityOnHint = ( ) => {
129
128
const { message} = this . props ;
130
129
const targetRefTag = findNodeHandle ( this . targetRef ) ;
@@ -264,6 +263,17 @@ class Hint extends BaseComponent {
264
263
return paddings ;
265
264
}
266
265
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
+
267
277
getTipPosition ( ) {
268
278
const { position} = this . getThemeProps ( ) ;
269
279
const tipPositionStyle = { } ;
@@ -343,19 +353,18 @@ class Hint extends BaseComponent {
343
353
}
344
354
345
355
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 ( ) ;
348
357
349
358
if ( this . showHint ) {
350
359
return (
351
- < AnimatableView
352
- animation = { shownUp ? AnimatableManager . animations . hintAppearUp : AnimatableManager . animations . hintAppearDown }
353
- duration = { 200 }
360
+ < View
361
+ animated
354
362
style = { [
355
363
{ width : this . containerWidth } ,
356
364
styles . animatedContainer ,
357
365
this . getHintPosition ( ) ,
358
- this . getHintPadding ( )
366
+ this . getHintPadding ( ) ,
367
+ this . getHintAnimatedStyle ( )
359
368
] }
360
369
pointerEvents = "box-none"
361
370
testID = { testID }
@@ -371,7 +380,7 @@ class Hint extends BaseComponent {
371
380
{ icon && < Image source = { icon } style = { [ styles . icon , iconStyle ] } /> }
372
381
< Text style = { [ styles . hintMessage , messageStyle ] } > { message } </ Text >
373
382
</ View >
374
- </ AnimatableView >
383
+ </ View >
375
384
) ;
376
385
}
377
386
}
0 commit comments