@momo-kits/animated-tooltip 0.167.2-beta.1 → 0.168.1-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.tsx +23 -48
- package/package.json +1 -1
package/index.tsx
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
TouchableWithoutFeedback,
|
|
16
16
|
useWindowDimensions,
|
|
17
17
|
View,
|
|
18
|
+
ViewStyle,
|
|
18
19
|
} from 'react-native';
|
|
19
20
|
import {
|
|
20
21
|
Colors,
|
|
@@ -255,34 +256,13 @@ const Tooltip = forwardRef<TooltipRef, TooltipProps>(function Tooltip(
|
|
|
255
256
|
[handleHide, handleShow],
|
|
256
257
|
);
|
|
257
258
|
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
-
: placement === 'bottom'
|
|
267
|
-
? {
|
|
268
|
-
translateY: animatedValue.interpolate({
|
|
269
|
-
inputRange: [0, 1],
|
|
270
|
-
outputRange: [-4, 0],
|
|
271
|
-
}),
|
|
272
|
-
}
|
|
273
|
-
: placement === 'left'
|
|
274
|
-
? {
|
|
275
|
-
translateX: animatedValue.interpolate({
|
|
276
|
-
inputRange: [0, 1],
|
|
277
|
-
outputRange: [4, 0],
|
|
278
|
-
}),
|
|
279
|
-
}
|
|
280
|
-
: {
|
|
281
|
-
translateX: animatedValue.interpolate({
|
|
282
|
-
inputRange: [0, 1],
|
|
283
|
-
outputRange: [-4, 0],
|
|
284
|
-
}),
|
|
285
|
-
};
|
|
259
|
+
const isVertical = placement === 'top' || placement === 'bottom';
|
|
260
|
+
const slideFrom = placement === 'top' || placement === 'left' ? 4 : -4;
|
|
261
|
+
const slide = animatedValue.interpolate({
|
|
262
|
+
inputRange: [0, 1],
|
|
263
|
+
outputRange: [slideFrom, 0],
|
|
264
|
+
});
|
|
265
|
+
const translate = isVertical ? { translateY: slide } : { translateX: slide };
|
|
286
266
|
|
|
287
267
|
const placementStyle = useMemo((): {
|
|
288
268
|
top?: number;
|
|
@@ -474,6 +454,17 @@ const Tooltip = forwardRef<TooltipRef, TooltipProps>(function Tooltip(
|
|
|
474
454
|
borderRadius: size / 2,
|
|
475
455
|
},
|
|
476
456
|
];
|
|
457
|
+
const inset = size + Spacing.M;
|
|
458
|
+
const centerTop = (tooltipSize.height || 0) / 2 - size;
|
|
459
|
+
let horizontalAlign: ViewStyle = { alignSelf: 'center' };
|
|
460
|
+
let verticalAlign: ViewStyle = { top: centerTop };
|
|
461
|
+
if (align === 'start') {
|
|
462
|
+
horizontalAlign = { left: inset };
|
|
463
|
+
verticalAlign = { top: inset };
|
|
464
|
+
} else if (align === 'end') {
|
|
465
|
+
horizontalAlign = { right: inset };
|
|
466
|
+
verticalAlign = { bottom: inset };
|
|
467
|
+
}
|
|
477
468
|
|
|
478
469
|
switch (placement) {
|
|
479
470
|
case 'top':
|
|
@@ -481,11 +472,7 @@ const Tooltip = forwardRef<TooltipRef, TooltipProps>(function Tooltip(
|
|
|
481
472
|
...common,
|
|
482
473
|
{
|
|
483
474
|
bottom: -(size - 1),
|
|
484
|
-
...
|
|
485
|
-
? { left: size + Spacing.M }
|
|
486
|
-
: align === 'end'
|
|
487
|
-
? { right: size + Spacing.M }
|
|
488
|
-
: { alignSelf: 'center' }),
|
|
475
|
+
...horizontalAlign,
|
|
489
476
|
},
|
|
490
477
|
];
|
|
491
478
|
case 'bottom':
|
|
@@ -493,11 +480,7 @@ const Tooltip = forwardRef<TooltipRef, TooltipProps>(function Tooltip(
|
|
|
493
480
|
...common,
|
|
494
481
|
{
|
|
495
482
|
top: -(size - 1),
|
|
496
|
-
...
|
|
497
|
-
? { left: size + Spacing.M }
|
|
498
|
-
: align === 'end'
|
|
499
|
-
? { right: size + Spacing.M }
|
|
500
|
-
: { alignSelf: 'center' }),
|
|
483
|
+
...horizontalAlign,
|
|
501
484
|
},
|
|
502
485
|
];
|
|
503
486
|
case 'left':
|
|
@@ -505,11 +488,7 @@ const Tooltip = forwardRef<TooltipRef, TooltipProps>(function Tooltip(
|
|
|
505
488
|
...common,
|
|
506
489
|
{
|
|
507
490
|
right: -(size - 1),
|
|
508
|
-
...
|
|
509
|
-
? { top: size + Spacing.M }
|
|
510
|
-
: align === 'end'
|
|
511
|
-
? { bottom: size + Spacing.M }
|
|
512
|
-
: { top: (tooltipSize.height || 0) / 2 - size }),
|
|
491
|
+
...verticalAlign,
|
|
513
492
|
},
|
|
514
493
|
];
|
|
515
494
|
case 'right':
|
|
@@ -518,11 +497,7 @@ const Tooltip = forwardRef<TooltipRef, TooltipProps>(function Tooltip(
|
|
|
518
497
|
...common,
|
|
519
498
|
{
|
|
520
499
|
left: -(size - 1),
|
|
521
|
-
...
|
|
522
|
-
? { top: size + Spacing.M }
|
|
523
|
-
: align === 'end'
|
|
524
|
-
? { bottom: size + Spacing.M }
|
|
525
|
-
: { top: (tooltipSize.height || 0) / 2 - size }),
|
|
500
|
+
...verticalAlign,
|
|
526
501
|
},
|
|
527
502
|
];
|
|
528
503
|
}
|