@momo-kits/foundation 0.160.1-beta.8 → 0.160.1-beta.9
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/Layout/FloatingButton.tsx +11 -11
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useContext, useEffect,
|
|
1
|
+
import React, { useContext, useEffect, useState } from 'react';
|
|
2
2
|
import {
|
|
3
3
|
LayoutChangeEvent,
|
|
4
4
|
StyleSheet,
|
|
@@ -43,12 +43,12 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
|
|
|
43
43
|
const { theme } = useContext(ApplicationContext);
|
|
44
44
|
const scaledFontSize = useScaleSize(16);
|
|
45
45
|
const scaledLineHeight = useScaleSize(22);
|
|
46
|
-
const maxWidth =
|
|
46
|
+
const maxWidth = useSharedValue(0);
|
|
47
47
|
const minWidth = size === 'small' ? 36 : 48;
|
|
48
48
|
const opacityAnimated = useSharedValue(0);
|
|
49
49
|
const widthAnimated = useSharedValue<number | null>(null);
|
|
50
|
-
const lastOffset =
|
|
51
|
-
const lastDirection =
|
|
50
|
+
const lastOffset = useSharedValue(0);
|
|
51
|
+
const lastDirection = useSharedValue<string | null>(null);
|
|
52
52
|
const [showText, setShowText] = useState(true);
|
|
53
53
|
|
|
54
54
|
useEffect(() => {
|
|
@@ -61,11 +61,11 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
|
|
|
61
61
|
(value) => {
|
|
62
62
|
'worklet';
|
|
63
63
|
if (!label || !animatedValue) return;
|
|
64
|
-
if (value !== lastOffset.
|
|
65
|
-
const direction = value > lastOffset.
|
|
66
|
-
lastOffset.
|
|
67
|
-
if (lastDirection.
|
|
68
|
-
lastDirection.
|
|
64
|
+
if (value !== lastOffset.value && value > 0) {
|
|
65
|
+
const direction = value > lastOffset.value ? 'down' : 'up';
|
|
66
|
+
lastOffset.value = value;
|
|
67
|
+
if (lastDirection.value !== direction) {
|
|
68
|
+
lastDirection.value = direction;
|
|
69
69
|
if (direction === 'down') {
|
|
70
70
|
opacityAnimated.value = withTiming(0, { duration: 100 });
|
|
71
71
|
widthAnimated.value = withTiming(
|
|
@@ -78,7 +78,7 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
|
|
|
78
78
|
} else {
|
|
79
79
|
opacityAnimated.value = withTiming(1, { duration: 100 });
|
|
80
80
|
widthAnimated.value = withTiming(
|
|
81
|
-
maxWidth.
|
|
81
|
+
maxWidth.value,
|
|
82
82
|
{ duration: 100 },
|
|
83
83
|
(finished) => {
|
|
84
84
|
if (finished) runOnJS(setShowText)(true);
|
|
@@ -102,7 +102,7 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
|
|
|
102
102
|
const handleLayout = (event: LayoutChangeEvent) => {
|
|
103
103
|
const layout = event.nativeEvent.layout;
|
|
104
104
|
if (widthAnimated.value != null) return;
|
|
105
|
-
maxWidth.
|
|
105
|
+
maxWidth.value = layout.width;
|
|
106
106
|
widthAnimated.value = layout.width;
|
|
107
107
|
};
|
|
108
108
|
|