@fountain-ui/core 2.0.0-beta.12 → 2.0.0-beta.13
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/build/commonjs/ButtonBase/ButtonBase.js +56 -52
- package/build/commonjs/ButtonBase/ButtonBase.js.map +1 -1
- package/build/commonjs/CircularProgress/CircularProgress.js +10 -12
- package/build/commonjs/CircularProgress/CircularProgress.js.map +1 -1
- package/build/commonjs/ImageCore/ImageCoreNative.js +24 -26
- package/build/commonjs/ImageCore/ImageCoreNative.js.map +1 -1
- package/build/commonjs/Tooltip/Tooltip.js +14 -18
- package/build/commonjs/Tooltip/Tooltip.js.map +1 -1
- package/build/commonjs/animated/AnimatedPressable.js +2 -3
- package/build/commonjs/animated/AnimatedPressable.js.map +1 -1
- package/build/commonjs/hooks/useThrottle.js +3 -7
- package/build/commonjs/hooks/useThrottle.js.map +1 -1
- package/build/commonjs/internal/hooks/useHeight.js +2 -6
- package/build/commonjs/internal/hooks/useHeight.js.map +1 -1
- package/build/module/ButtonBase/ButtonBase.js +54 -48
- package/build/module/ButtonBase/ButtonBase.js.map +1 -1
- package/build/module/CircularProgress/CircularProgress.js +10 -11
- package/build/module/CircularProgress/CircularProgress.js.map +1 -1
- package/build/module/ImageCore/ImageCoreNative.js +20 -23
- package/build/module/ImageCore/ImageCoreNative.js.map +1 -1
- package/build/module/Tooltip/Tooltip.js +11 -11
- package/build/module/Tooltip/Tooltip.js.map +1 -1
- package/build/module/animated/AnimatedPressable.js +2 -3
- package/build/module/animated/AnimatedPressable.js.map +1 -1
- package/build/module/hooks/useThrottle.js +3 -3
- package/build/module/hooks/useThrottle.js.map +1 -1
- package/build/module/internal/hooks/useHeight.js +2 -2
- package/build/module/internal/hooks/useHeight.js.map +1 -1
- package/build/typescript/animated/AnimatedPressable.d.ts +2 -2
- package/package.json +2 -2
- package/src/ButtonBase/ButtonBase.tsx +65 -43
- package/src/CircularProgress/CircularProgress.tsx +15 -16
- package/src/ImageCore/ImageCoreNative.tsx +17 -19
- package/src/Tooltip/Tooltip.tsx +12 -12
- package/src/animated/AnimatedPressable.tsx +1 -2
- package/src/hooks/useThrottle.ts +3 -3
- package/src/internal/hooks/useHeight.ts +2 -2
- package/build/commonjs/ButtonBase/ButtonBase.ios.js +0 -101
- package/build/commonjs/ButtonBase/ButtonBase.ios.js.map +0 -1
- package/build/commonjs/ButtonBase/useDisabledReaction/index.js +0 -21
- package/build/commonjs/ButtonBase/useDisabledReaction/index.js.map +0 -1
- package/build/commonjs/ButtonBase/useDisabledReaction/index.native.js +0 -9
- package/build/commonjs/ButtonBase/useDisabledReaction/index.native.js.map +0 -1
- package/build/commonjs/ImageCore/ImageCoreNative.ios.js +0 -60
- package/build/commonjs/ImageCore/ImageCoreNative.ios.js.map +0 -1
- package/build/module/ButtonBase/ButtonBase.ios.js +0 -82
- package/build/module/ButtonBase/ButtonBase.ios.js.map +0 -1
- package/build/module/ButtonBase/useDisabledReaction/index.js +0 -12
- package/build/module/ButtonBase/useDisabledReaction/index.js.map +0 -1
- package/build/module/ButtonBase/useDisabledReaction/index.native.js +0 -2
- package/build/module/ButtonBase/useDisabledReaction/index.native.js.map +0 -1
- package/build/module/ImageCore/ImageCoreNative.ios.js +0 -45
- package/build/module/ImageCore/ImageCoreNative.ios.js.map +0 -1
- package/build/typescript/ButtonBase/ButtonBase.ios.d.ts +0 -2
- package/build/typescript/ButtonBase/useDisabledReaction/index.d.ts +0 -2
- package/build/typescript/ButtonBase/useDisabledReaction/index.native.d.ts +0 -2
- package/build/typescript/ImageCore/ImageCoreNative.ios.d.ts +0 -2
- package/src/ButtonBase/ButtonBase.ios.tsx +0 -95
- package/src/ButtonBase/useDisabledReaction/index.native.ts +0 -4
- package/src/ButtonBase/useDisabledReaction/index.ts +0 -17
- package/src/ImageCore/ImageCoreNative.ios.tsx +0 -46
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import
|
|
3
|
-
import { useAnimatedStyle, useSharedValue, withDelay, withTiming } from 'react-native-reanimated';
|
|
1
|
+
import React, { useCallback, useEffect, useRef } from 'react';
|
|
2
|
+
import { Animated } from 'react-native';
|
|
4
3
|
import { useThrottle } from '../hooks';
|
|
5
4
|
import { AnimatedPressable } from '../animated';
|
|
6
|
-
import { StyleSheet } from '../styles';
|
|
7
5
|
import type ButtonBaseProps from './ButtonBaseProps';
|
|
8
|
-
|
|
6
|
+
|
|
7
|
+
interface StartPressAnimation {
|
|
8
|
+
(pressIn: boolean, isHover: boolean): void;
|
|
9
|
+
}
|
|
9
10
|
|
|
10
11
|
export const ORIGINAL_OPACITY = 1;
|
|
11
12
|
export const DISABLED_OPACITY = .3;
|
|
@@ -14,14 +15,23 @@ const ACTIVE_OPACITY = .65;
|
|
|
14
15
|
const ORIGINAL_SCALE = 1;
|
|
15
16
|
const MINIFIED_SCALE = .96;
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
// at "node_modules/react-native/Libraries/Pressability.js"
|
|
19
|
+
// const DEFAULT_MIN_PRESS_DURATION = 130;
|
|
20
|
+
const PRESS_IN_DELAY = 130;
|
|
21
|
+
|
|
22
|
+
type TimingAnimationValue = Animated.Value | Animated.ValueXY;
|
|
23
|
+
type TimingAnimationToValue = Animated.TimingAnimationConfig['toValue'];
|
|
18
24
|
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
const startTimingAnimationWithDefaults = (
|
|
26
|
+
value: TimingAnimationValue,
|
|
27
|
+
toValue: TimingAnimationToValue,
|
|
28
|
+
) => {
|
|
29
|
+
Animated.timing(value, {
|
|
30
|
+
toValue,
|
|
31
|
+
duration: 150,
|
|
32
|
+
useNativeDriver: true,
|
|
33
|
+
}).start();
|
|
34
|
+
};
|
|
25
35
|
|
|
26
36
|
export default function ButtonBase(props: ButtonBaseProps) {
|
|
27
37
|
const {
|
|
@@ -30,7 +40,7 @@ export default function ButtonBase(props: ButtonBaseProps) {
|
|
|
30
40
|
disableThrottle = false,
|
|
31
41
|
onPress,
|
|
32
42
|
pressEffect = 'opacity',
|
|
33
|
-
style,
|
|
43
|
+
style: styleProp,
|
|
34
44
|
throttleMillis = 650,
|
|
35
45
|
...otherProps
|
|
36
46
|
} = props;
|
|
@@ -40,56 +50,68 @@ export default function ButtonBase(props: ButtonBaseProps) {
|
|
|
40
50
|
callback: onPress,
|
|
41
51
|
});
|
|
42
52
|
|
|
43
|
-
const opacity =
|
|
44
|
-
const scale =
|
|
53
|
+
const opacity = useRef<Animated.Value>(new Animated.Value(ORIGINAL_OPACITY)).current;
|
|
54
|
+
const scale = useRef<Animated.Value>(new Animated.Value(ORIGINAL_SCALE)).current;
|
|
45
55
|
|
|
46
|
-
|
|
47
|
-
opacity:
|
|
48
|
-
|
|
49
|
-
}), []);
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
opacity.setValue(disabled ? DISABLED_OPACITY : ORIGINAL_OPACITY);
|
|
58
|
+
}, [disabled]);
|
|
50
59
|
|
|
51
|
-
|
|
60
|
+
const startScaleAnimation = useCallback<StartPressAnimation>((pressIn, isHover) => {
|
|
61
|
+
if (!isHover) {
|
|
62
|
+
startTimingAnimationWithDefaults(
|
|
63
|
+
scale,
|
|
64
|
+
pressIn ? MINIFIED_SCALE : ORIGINAL_SCALE,
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}, []);
|
|
52
68
|
|
|
53
|
-
const
|
|
54
|
-
if (
|
|
55
|
-
|
|
69
|
+
const startOpacityAnimation = useCallback<StartPressAnimation>((pressIn) => {
|
|
70
|
+
if (pressIn) {
|
|
71
|
+
opacity.setValue(ACTIVE_OPACITY);
|
|
72
|
+
} else {
|
|
73
|
+
startTimingAnimationWithDefaults(opacity, ORIGINAL_OPACITY);
|
|
56
74
|
}
|
|
75
|
+
}, []);
|
|
57
76
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
} else if (!isHovered) {
|
|
65
|
-
if (pressIn) {
|
|
66
|
-
scale.value = withDelay(
|
|
67
|
-
100,
|
|
68
|
-
withTiming(MINIFIED_SCALE, ANIMATION_CONFIG),
|
|
69
|
-
);
|
|
70
|
-
} else {
|
|
71
|
-
scale.value = withTiming(ORIGINAL_SCALE, ANIMATION_CONFIG);
|
|
72
|
-
}
|
|
77
|
+
const startPressAnimation = useCallback<StartPressAnimation>((pressIn, isHover = false) => {
|
|
78
|
+
if (pressEffect === 'scale') {
|
|
79
|
+
startScaleAnimation(pressIn, isHover);
|
|
80
|
+
} else if (pressEffect === 'opacity') {
|
|
81
|
+
startOpacityAnimation(pressIn, isHover);
|
|
73
82
|
}
|
|
83
|
+
}, [pressEffect]);
|
|
84
|
+
|
|
85
|
+
const handlePressIn = useCallback(() => {
|
|
86
|
+
startPressAnimation(true, false);
|
|
87
|
+
}, [startPressAnimation]);
|
|
88
|
+
|
|
89
|
+
const handlePressOut = useCallback(() => {
|
|
90
|
+
startPressAnimation(false, false);
|
|
91
|
+
}, [startPressAnimation]);
|
|
92
|
+
|
|
93
|
+
const animatedStyle = {
|
|
94
|
+
opacity,
|
|
95
|
+
transform: [{ scale }],
|
|
74
96
|
};
|
|
75
97
|
|
|
76
98
|
return (
|
|
77
99
|
<AnimatedPressable
|
|
78
100
|
disabled={disabled}
|
|
79
101
|
onPress={handlePress}
|
|
80
|
-
onPressIn={
|
|
81
|
-
onPressOut={
|
|
102
|
+
onPressIn={handlePressIn}
|
|
103
|
+
onPressOut={handlePressOut}
|
|
82
104
|
style={[
|
|
83
105
|
animatedStyle,
|
|
84
|
-
|
|
85
|
-
style,
|
|
106
|
+
styleProp,
|
|
86
107
|
]}
|
|
108
|
+
unstable_pressDelay={PRESS_IN_DELAY}
|
|
87
109
|
{...otherProps}
|
|
88
110
|
>
|
|
89
111
|
{typeof children !== 'function' ? (
|
|
90
112
|
({ hovered }) => {
|
|
91
113
|
if (hovered !== undefined && !disabled) {
|
|
92
|
-
|
|
114
|
+
startPressAnimation(hovered, true);
|
|
93
115
|
}
|
|
94
116
|
|
|
95
117
|
return children;
|
|
@@ -4,15 +4,14 @@ import { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';
|
|
|
4
4
|
import type { WithTimingConfig } from 'react-native-reanimated';
|
|
5
5
|
import Animated, { Easing, useAnimatedStyle, useSharedValue, withRepeat, withTiming } from 'react-native-reanimated';
|
|
6
6
|
import { CircularProgress as CircularProgressIcon } from '../internal/icons';
|
|
7
|
-
import { css } from '../styles';
|
|
8
7
|
import { OverridableComponentProps } from '../types';
|
|
9
8
|
|
|
10
9
|
type CircularProgressStyles = NamedStylesStringUnion<'root'>;
|
|
11
10
|
|
|
12
11
|
const ANIMATION_CONFIG: Readonly<WithTimingConfig> = { duration: 900, easing: Easing.linear };
|
|
13
12
|
|
|
14
|
-
const
|
|
15
|
-
const
|
|
13
|
+
const MIN_ROTATE_DEGREE = 0;
|
|
14
|
+
const MAX_ROTATE_DEGREE = 360;
|
|
16
15
|
|
|
17
16
|
const useStyles: UseStyles<CircularProgressStyles> = function (): CircularProgressStyles {
|
|
18
17
|
return {
|
|
@@ -24,32 +23,32 @@ const useStyles: UseStyles<CircularProgressStyles> = function (): CircularProgre
|
|
|
24
23
|
};
|
|
25
24
|
|
|
26
25
|
export default function CircularProgress(props: OverridableComponentProps<ViewProps>) {
|
|
27
|
-
const { style } = props;
|
|
26
|
+
const { style: styleProp } = props;
|
|
28
27
|
|
|
29
28
|
const styles = useStyles();
|
|
30
29
|
|
|
31
|
-
const
|
|
32
|
-
styles.root,
|
|
33
|
-
style,
|
|
34
|
-
]);
|
|
30
|
+
const rotate = useSharedValue(MIN_ROTATE_DEGREE);
|
|
35
31
|
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
const spinStyle = useAnimatedStyle(() => ({
|
|
39
|
-
transform: [{ rotate: `${rotate}deg` }],
|
|
32
|
+
const animatedStyle = useAnimatedStyle(() => ({
|
|
33
|
+
transform: [{ rotate: `${rotate.value}deg` }],
|
|
40
34
|
}), []);
|
|
41
35
|
|
|
42
36
|
useEffect(() => {
|
|
43
37
|
rotate.value = withRepeat(
|
|
44
|
-
withTiming(
|
|
38
|
+
withTiming(MAX_ROTATE_DEGREE, ANIMATION_CONFIG),
|
|
45
39
|
-1,
|
|
46
40
|
false,
|
|
47
41
|
);
|
|
48
42
|
}, []);
|
|
49
43
|
|
|
50
44
|
return (
|
|
51
|
-
<Animated.View
|
|
52
|
-
<CircularProgressIcon/>
|
|
53
|
-
|
|
45
|
+
<Animated.View
|
|
46
|
+
children={<CircularProgressIcon/>}
|
|
47
|
+
style={[
|
|
48
|
+
animatedStyle,
|
|
49
|
+
styles.root,
|
|
50
|
+
styleProp,
|
|
51
|
+
]}
|
|
52
|
+
/>
|
|
54
53
|
);
|
|
55
54
|
};
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import
|
|
3
|
-
import Animated, { useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';
|
|
1
|
+
import React, { useCallback, useRef } from 'react';
|
|
2
|
+
import { Animated } from 'react-native';
|
|
4
3
|
import FastImage from 'react-native-fast-image';
|
|
5
4
|
import type ImageCoreProps from './ImageCoreProps';
|
|
6
5
|
|
|
7
6
|
// @ts-ignore
|
|
8
7
|
const AnimatedFastImage = Animated.createAnimatedComponent(FastImage);
|
|
9
8
|
|
|
10
|
-
const
|
|
9
|
+
const INITIAL_OPACITY = 0;
|
|
10
|
+
const LOADED_OPACITY = 1;
|
|
11
|
+
|
|
12
|
+
const ANIMATION_DURATION = 200;
|
|
11
13
|
|
|
12
14
|
export default function ImageCore(props: ImageCoreProps) {
|
|
13
15
|
const {
|
|
@@ -19,21 +21,17 @@ export default function ImageCore(props: ImageCoreProps) {
|
|
|
19
21
|
width,
|
|
20
22
|
} = props;
|
|
21
23
|
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
const opacity = useSharedValue(0);
|
|
25
|
-
|
|
26
|
-
const animatedStyle = useAnimatedStyle(() => ({
|
|
27
|
-
opacity: opacity.value,
|
|
28
|
-
}), []);
|
|
24
|
+
const opacity = useRef<Animated.Value>(new Animated.Value(INITIAL_OPACITY)).current;
|
|
29
25
|
|
|
30
|
-
const handleLoad = () => {
|
|
31
|
-
|
|
26
|
+
const handleLoad = useCallback(() => {
|
|
27
|
+
Animated.timing(opacity, {
|
|
28
|
+
toValue: LOADED_OPACITY,
|
|
29
|
+
duration: ANIMATION_DURATION,
|
|
30
|
+
useNativeDriver: true,
|
|
31
|
+
}).start();
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
};
|
|
33
|
+
onLoad?.();
|
|
34
|
+
}, [onLoad]);
|
|
37
35
|
|
|
38
36
|
return (
|
|
39
37
|
<AnimatedFastImage
|
|
@@ -42,8 +40,8 @@ export default function ImageCore(props: ImageCoreProps) {
|
|
|
42
40
|
resizeMode={resizeMode}
|
|
43
41
|
source={{ uri: source.uri }}
|
|
44
42
|
style={[
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
{ opacity },
|
|
44
|
+
{ width, height },
|
|
47
45
|
]}
|
|
48
46
|
/>
|
|
49
47
|
);
|
package/src/Tooltip/Tooltip.tsx
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
2
|
import { Text, View, ViewProps } from 'react-native';
|
|
3
|
-
import { TouchableWithoutFeedback } from 'react-native-gesture-handler';
|
|
4
3
|
import type { WithTimingConfig } from 'react-native-reanimated';
|
|
5
4
|
import Animated, { useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';
|
|
6
5
|
import { rgb } from '@fountain-ui/utils';
|
|
6
|
+
import ButtonBase from '../ButtonBase';
|
|
7
7
|
import { createFontStyle, css, useTheme } from '../styles';
|
|
8
8
|
import { Close as CloseIcon } from '../internal/icons';
|
|
9
9
|
import type TooltipProps from './TooltipProps';
|
|
10
10
|
import UpArrow from './UpArrow';
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const DEFAULT_OPACITY = 0.8;
|
|
13
13
|
const initialLayout = { width: 0, height: 0, x: 0, y: 0 };
|
|
14
14
|
|
|
15
15
|
const ANIMATION_CONFIG: Readonly<WithTimingConfig> = { duration: 150 };
|
|
@@ -30,11 +30,11 @@ export default function Tooltip(props: TooltipProps) {
|
|
|
30
30
|
|
|
31
31
|
const theme = useTheme();
|
|
32
32
|
|
|
33
|
-
const [layout, setLayout] =
|
|
33
|
+
const [layout, setLayout] = useState(initialLayout);
|
|
34
34
|
|
|
35
35
|
const scale = useSharedValue(0);
|
|
36
36
|
|
|
37
|
-
const
|
|
37
|
+
const animatedStyle = useAnimatedStyle(() => ({
|
|
38
38
|
transform: [{ scale: scale.value }],
|
|
39
39
|
}), []);
|
|
40
40
|
|
|
@@ -53,7 +53,7 @@ export default function Tooltip(props: TooltipProps) {
|
|
|
53
53
|
overflow: visible ? undefined : 'hidden',
|
|
54
54
|
};
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
useEffect(() => {
|
|
57
57
|
const nextScaleValue = visible ? 1 : 0;
|
|
58
58
|
|
|
59
59
|
scale.value = withTiming(nextScaleValue, ANIMATION_CONFIG);
|
|
@@ -61,7 +61,7 @@ export default function Tooltip(props: TooltipProps) {
|
|
|
61
61
|
|
|
62
62
|
const touchableStyle: ViewProps['style'] = {
|
|
63
63
|
alignItems: 'center',
|
|
64
|
-
backgroundColor: `rgba(${r}, ${g}, ${b}, ${
|
|
64
|
+
backgroundColor: `rgba(${r}, ${g}, ${b}, ${DEFAULT_OPACITY})`,
|
|
65
65
|
borderRadius: theme.shape.roundness,
|
|
66
66
|
flexDirection: 'row',
|
|
67
67
|
padding: theme.spacing(2),
|
|
@@ -78,8 +78,8 @@ export default function Tooltip(props: TooltipProps) {
|
|
|
78
78
|
]);
|
|
79
79
|
|
|
80
80
|
const buttonElem = (
|
|
81
|
-
<
|
|
82
|
-
|
|
81
|
+
<ButtonBase
|
|
82
|
+
pressEffect={'none'}
|
|
83
83
|
onPress={onClose}
|
|
84
84
|
>
|
|
85
85
|
<View style={css(touchableStyle)}>
|
|
@@ -95,14 +95,14 @@ export default function Tooltip(props: TooltipProps) {
|
|
|
95
95
|
height={20}
|
|
96
96
|
/>
|
|
97
97
|
</View>
|
|
98
|
-
</
|
|
98
|
+
</ButtonBase>
|
|
99
99
|
);
|
|
100
100
|
|
|
101
101
|
const arrowElem = (
|
|
102
102
|
<UpArrow
|
|
103
103
|
upsideDown={placement === 'top'}
|
|
104
104
|
fill={theme.palette.primary.main}
|
|
105
|
-
opacity={
|
|
105
|
+
opacity={DEFAULT_OPACITY}
|
|
106
106
|
/>
|
|
107
107
|
);
|
|
108
108
|
|
|
@@ -113,7 +113,7 @@ export default function Tooltip(props: TooltipProps) {
|
|
|
113
113
|
<Animated.View
|
|
114
114
|
onLayout={(event) => setLayout(event.nativeEvent.layout)}
|
|
115
115
|
style={[
|
|
116
|
-
|
|
116
|
+
animatedStyle,
|
|
117
117
|
tooltipLayoutStyle,
|
|
118
118
|
tooltipStyle,
|
|
119
119
|
]}
|
package/src/hooks/useThrottle.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useCallback, useRef } from 'react';
|
|
2
2
|
|
|
3
3
|
export interface ThrottleOptions {
|
|
4
4
|
periodMillis: number;
|
|
@@ -8,9 +8,9 @@ export interface ThrottleOptions {
|
|
|
8
8
|
export default function useThrottle(options: ThrottleOptions) {
|
|
9
9
|
const { periodMillis, callback } = options;
|
|
10
10
|
|
|
11
|
-
const lastExecMillisRef =
|
|
11
|
+
const lastExecMillisRef = useRef(0);
|
|
12
12
|
|
|
13
|
-
return
|
|
13
|
+
return useCallback((...args: any[]) => {
|
|
14
14
|
const now = Date.now();
|
|
15
15
|
const millisAfterExecuted = now - lastExecMillisRef.current;
|
|
16
16
|
lastExecMillisRef.current = now;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useState } from 'react';
|
|
2
2
|
import { ViewProps } from 'react-native';
|
|
3
3
|
import { useWorkletCallback } from 'react-native-reanimated';
|
|
4
4
|
|
|
5
5
|
type OnLayoutCallback = ViewProps['onLayout'];
|
|
6
6
|
|
|
7
7
|
export default function useHeight(initialHeight = 0): [number, OnLayoutCallback] {
|
|
8
|
-
const [height, setHeight] =
|
|
8
|
+
const [height, setHeight] = useState<number>(initialHeight);
|
|
9
9
|
|
|
10
10
|
const onLayout = useWorkletCallback((e) => {
|
|
11
11
|
setHeight(e.nativeEvent.layout.height);
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = ButtonBase;
|
|
7
|
-
|
|
8
|
-
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
|
|
10
|
-
var _reactNative = require("react-native");
|
|
11
|
-
|
|
12
|
-
var _hooks = require("../hooks");
|
|
13
|
-
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
|
-
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
17
|
-
|
|
18
|
-
const ORIGINAL_OPACITY = 1;
|
|
19
|
-
const ACTIVE_OPACITY = .65;
|
|
20
|
-
const DISABLED_OPACITY = .3;
|
|
21
|
-
const ORIGINAL_SCALE = 1;
|
|
22
|
-
const MINIFIED_SCALE = .96;
|
|
23
|
-
const animatedDuration = 150;
|
|
24
|
-
|
|
25
|
-
const AnimatedPressable = _reactNative.Animated.createAnimatedComponent(_reactNative.Pressable);
|
|
26
|
-
|
|
27
|
-
function ButtonBase(props) {
|
|
28
|
-
const {
|
|
29
|
-
children,
|
|
30
|
-
disabled = false,
|
|
31
|
-
disableThrottle = false,
|
|
32
|
-
onPress,
|
|
33
|
-
pressEffect = 'opacity',
|
|
34
|
-
style,
|
|
35
|
-
throttleMillis = 650,
|
|
36
|
-
...otherProps
|
|
37
|
-
} = props;
|
|
38
|
-
const handlePress = (0, _hooks.useThrottle)({
|
|
39
|
-
periodMillis: disableThrottle ? 0 : throttleMillis,
|
|
40
|
-
callback: onPress
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
const [opacity] = _react.default.useState(() => new _reactNative.Animated.Value(ORIGINAL_OPACITY));
|
|
44
|
-
|
|
45
|
-
const [scale] = _react.default.useState(() => new _reactNative.Animated.Value(ORIGINAL_SCALE));
|
|
46
|
-
|
|
47
|
-
const startAnimation = _react.default.useCallback(function (pressIn) {
|
|
48
|
-
let isHovered = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
49
|
-
|
|
50
|
-
if (pressEffect === 'none') {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (pressEffect === 'opacity') {
|
|
55
|
-
if (pressIn) {
|
|
56
|
-
_reactNative.Animated.timing(opacity, {
|
|
57
|
-
toValue: ACTIVE_OPACITY,
|
|
58
|
-
duration: animatedDuration,
|
|
59
|
-
useNativeDriver: true
|
|
60
|
-
}).start();
|
|
61
|
-
} else {
|
|
62
|
-
_reactNative.Animated.timing(opacity, {
|
|
63
|
-
toValue: ORIGINAL_OPACITY,
|
|
64
|
-
duration: 0,
|
|
65
|
-
useNativeDriver: true
|
|
66
|
-
}).start();
|
|
67
|
-
}
|
|
68
|
-
} else if (!isHovered) {
|
|
69
|
-
if (pressIn) {
|
|
70
|
-
_reactNative.Animated.timing(scale, {
|
|
71
|
-
toValue: MINIFIED_SCALE,
|
|
72
|
-
duration: animatedDuration,
|
|
73
|
-
delay: 100,
|
|
74
|
-
useNativeDriver: true
|
|
75
|
-
}).start();
|
|
76
|
-
} else {
|
|
77
|
-
_reactNative.Animated.timing(scale, {
|
|
78
|
-
toValue: ORIGINAL_SCALE,
|
|
79
|
-
duration: 150,
|
|
80
|
-
useNativeDriver: true
|
|
81
|
-
}).start();
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}, [pressEffect]);
|
|
85
|
-
|
|
86
|
-
return /*#__PURE__*/_react.default.createElement(AnimatedPressable, _extends({
|
|
87
|
-
disabled: disabled,
|
|
88
|
-
onPress: handlePress,
|
|
89
|
-
onPressIn: () => startAnimation(true),
|
|
90
|
-
onPressOut: () => startAnimation(false),
|
|
91
|
-
style: [style, {
|
|
92
|
-
opacity: disabled ? DISABLED_OPACITY : opacity,
|
|
93
|
-
transform: [{
|
|
94
|
-
scale: disabled ? ORIGINAL_SCALE : scale
|
|
95
|
-
}]
|
|
96
|
-
}]
|
|
97
|
-
}, otherProps), children);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
;
|
|
101
|
-
//# sourceMappingURL=ButtonBase.ios.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["ORIGINAL_OPACITY","ACTIVE_OPACITY","DISABLED_OPACITY","ORIGINAL_SCALE","MINIFIED_SCALE","animatedDuration","AnimatedPressable","Animated","createAnimatedComponent","Pressable","ButtonBase","props","children","disabled","disableThrottle","onPress","pressEffect","style","throttleMillis","otherProps","handlePress","useThrottle","periodMillis","callback","opacity","React","useState","Value","scale","startAnimation","useCallback","pressIn","isHovered","timing","toValue","duration","useNativeDriver","start","delay","transform"],"sources":["ButtonBase.ios.tsx"],"sourcesContent":["import React from 'react';\nimport { Animated, Pressable } from 'react-native';\nimport { useThrottle } from '../hooks';\nimport type ButtonBaseProps from './ButtonBaseProps';\n\nconst ORIGINAL_OPACITY = 1;\nconst ACTIVE_OPACITY = .65;\nconst DISABLED_OPACITY = .3;\n\nconst ORIGINAL_SCALE = 1;\nconst MINIFIED_SCALE = .96;\n\nconst animatedDuration = 150;\n\nconst AnimatedPressable = Animated.createAnimatedComponent(Pressable);\n\nexport default function ButtonBase(props: ButtonBaseProps) {\n const {\n children,\n disabled = false,\n disableThrottle = false,\n onPress,\n pressEffect = 'opacity',\n style,\n throttleMillis = 650,\n ...otherProps\n } = props;\n\n const handlePress = useThrottle({\n periodMillis: disableThrottle ? 0 : throttleMillis,\n callback: onPress,\n });\n\n const [opacity] = React.useState(() => new Animated.Value(ORIGINAL_OPACITY));\n const [scale] = React.useState(() => new Animated.Value(ORIGINAL_SCALE));\n\n const startAnimation = React.useCallback((pressIn: boolean, isHovered: boolean = false) => {\n if (pressEffect === 'none') {\n return;\n }\n\n if (pressEffect === 'opacity') {\n if (pressIn) {\n Animated.timing(opacity, {\n toValue: ACTIVE_OPACITY,\n duration: animatedDuration,\n useNativeDriver: true,\n }).start();\n } else {\n Animated.timing(opacity, {\n toValue: ORIGINAL_OPACITY,\n duration: 0,\n useNativeDriver: true,\n }).start();\n }\n } else if (!isHovered) {\n if (pressIn) {\n Animated.timing(scale, {\n toValue: MINIFIED_SCALE,\n duration: animatedDuration,\n delay: 100,\n useNativeDriver: true,\n }).start();\n } else {\n Animated.timing(scale, {\n toValue: ORIGINAL_SCALE,\n duration: 150,\n useNativeDriver: true,\n }).start();\n }\n }\n }, [pressEffect]);\n\n return (\n <AnimatedPressable\n disabled={disabled}\n onPress={handlePress}\n onPressIn={() => startAnimation(true)}\n onPressOut={() => startAnimation(false)}\n style={[style,\n {\n opacity: disabled ? DISABLED_OPACITY : opacity,\n transform: [\n {\n scale: disabled ? ORIGINAL_SCALE : scale,\n },\n ],\n },\n ]}\n {...otherProps}\n >\n {children}\n </AnimatedPressable>\n );\n};\n"],"mappings":"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"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = useDisabledReaction;
|
|
7
|
-
|
|
8
|
-
var _reactNativeReanimated = require("react-native-reanimated");
|
|
9
|
-
|
|
10
|
-
var _ButtonBase = require("../ButtonBase");
|
|
11
|
-
|
|
12
|
-
function useDisabledReaction(disabled, opacity) {
|
|
13
|
-
(0, _reactNativeReanimated.useAnimatedReaction)(() => disabled, result => {
|
|
14
|
-
if (result) {
|
|
15
|
-
opacity.value = _ButtonBase.DISABLED_OPACITY;
|
|
16
|
-
} else {
|
|
17
|
-
opacity.value = _ButtonBase.ORIGINAL_OPACITY;
|
|
18
|
-
}
|
|
19
|
-
}, [disabled]);
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["useDisabledReaction","disabled","opacity","useAnimatedReaction","result","value","DISABLED_OPACITY","ORIGINAL_OPACITY"],"sources":["index.ts"],"sourcesContent":["import type { SharedValue } from 'react-native-reanimated';\nimport { useAnimatedReaction } from 'react-native-reanimated';\nimport { DISABLED_OPACITY, ORIGINAL_OPACITY } from '../ButtonBase';\n\nexport default function useDisabledReaction(disabled: boolean, opacity: SharedValue<number>) {\n useAnimatedReaction(\n () => disabled,\n (result) => {\n if (result) {\n opacity.value = DISABLED_OPACITY;\n } else {\n opacity.value = ORIGINAL_OPACITY;\n }\n },\n [disabled],\n );\n}\n"],"mappings":";;;;;;;AACA;;AACA;;AAEe,SAASA,mBAAT,CAA6BC,QAA7B,EAAgDC,OAAhD,EAA8E;EACzF,IAAAC,0CAAA,EACI,MAAMF,QADV,EAEKG,MAAD,IAAY;IACR,IAAIA,MAAJ,EAAY;MACRF,OAAO,CAACG,KAAR,GAAgBC,4BAAhB;IACH,CAFD,MAEO;MACHJ,OAAO,CAACG,KAAR,GAAgBE,4BAAhB;IACH;EACJ,CARL,EASI,CAACN,QAAD,CATJ;AAWH"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["useDisabledReaction","disabled","opacity"],"sources":["index.native.ts"],"sourcesContent":["import Animated from 'react-native-reanimated';\n\nexport default function useDisabledReaction(disabled: boolean, opacity: Animated.SharedValue<number>) {\n}"],"mappings":";;;;;;;AAEe,SAASA,mBAAT,CAA6BC,QAA7B,EAAgDC,OAAhD,EAAuF,CACrG"}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = ImageCore;
|
|
7
|
-
|
|
8
|
-
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
|
|
10
|
-
var _reactNative = require("react-native");
|
|
11
|
-
|
|
12
|
-
var _reactNativeFastImage = _interopRequireDefault(require("react-native-fast-image"));
|
|
13
|
-
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
|
-
const AnimatedFastImage = _reactNative.Animated.createAnimatedComponent(_reactNativeFastImage.default);
|
|
17
|
-
|
|
18
|
-
function ImageCore(props) {
|
|
19
|
-
const {
|
|
20
|
-
height,
|
|
21
|
-
onError,
|
|
22
|
-
onLoad,
|
|
23
|
-
resizeMode,
|
|
24
|
-
source,
|
|
25
|
-
width
|
|
26
|
-
} = props;
|
|
27
|
-
const style = {
|
|
28
|
-
width,
|
|
29
|
-
height
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const [opacity] = _react.default.useState(() => new _reactNative.Animated.Value(0));
|
|
33
|
-
|
|
34
|
-
const handleLoad = () => {
|
|
35
|
-
_reactNative.Animated.timing(opacity, {
|
|
36
|
-
toValue: 1,
|
|
37
|
-
duration: 200,
|
|
38
|
-
useNativeDriver: true
|
|
39
|
-
}).start();
|
|
40
|
-
|
|
41
|
-
if (onLoad) {
|
|
42
|
-
onLoad();
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
return /*#__PURE__*/_react.default.createElement(AnimatedFastImage, {
|
|
47
|
-
onError: onError,
|
|
48
|
-
onLoad: handleLoad,
|
|
49
|
-
resizeMode: resizeMode,
|
|
50
|
-
source: {
|
|
51
|
-
uri: source.uri
|
|
52
|
-
},
|
|
53
|
-
style: [style, {
|
|
54
|
-
opacity
|
|
55
|
-
}]
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
;
|
|
60
|
-
//# sourceMappingURL=ImageCoreNative.ios.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["AnimatedFastImage","Animated","createAnimatedComponent","FastImage","ImageCore","props","height","onError","onLoad","resizeMode","source","width","style","opacity","React","useState","Value","handleLoad","timing","toValue","duration","useNativeDriver","start","uri"],"sources":["ImageCoreNative.ios.tsx"],"sourcesContent":["import React from 'react';\nimport { Animated } from 'react-native';\nimport FastImage from 'react-native-fast-image';\nimport type ImageCoreProps from './ImageCoreProps';\n\nconst AnimatedFastImage = Animated.createAnimatedComponent(FastImage);\n\nexport default function ImageCore(props: ImageCoreProps) {\n const {\n height,\n onError,\n onLoad,\n resizeMode,\n source,\n width,\n } = props;\n\n const style = { width, height };\n\n const [opacity] = React.useState(() => new Animated.Value(0));\n\n const handleLoad = () => {\n Animated.timing(opacity, {\n toValue: 1,\n duration: 200,\n useNativeDriver: true,\n }).start();\n\n if (onLoad) {\n onLoad();\n }\n };\n\n return (\n <AnimatedFastImage\n onError={onError}\n onLoad={handleLoad}\n resizeMode={resizeMode}\n source={{ uri: source.uri }}\n style={[\n style,\n { opacity },\n ]}\n />\n );\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;AAGA,MAAMA,iBAAiB,GAAGC,qBAAA,CAASC,uBAAT,CAAiCC,6BAAjC,CAA1B;;AAEe,SAASC,SAAT,CAAmBC,KAAnB,EAA0C;EACrD,MAAM;IACFC,MADE;IAEFC,OAFE;IAGFC,MAHE;IAIFC,UAJE;IAKFC,MALE;IAMFC;EANE,IAOFN,KAPJ;EASA,MAAMO,KAAK,GAAG;IAAED,KAAF;IAASL;EAAT,CAAd;;EAEA,MAAM,CAACO,OAAD,IAAYC,cAAA,CAAMC,QAAN,CAAe,MAAM,IAAId,qBAAA,CAASe,KAAb,CAAmB,CAAnB,CAArB,CAAlB;;EAEA,MAAMC,UAAU,GAAG,MAAM;IACrBhB,qBAAA,CAASiB,MAAT,CAAgBL,OAAhB,EAAyB;MACrBM,OAAO,EAAE,CADY;MAErBC,QAAQ,EAAE,GAFW;MAGrBC,eAAe,EAAE;IAHI,CAAzB,EAIGC,KAJH;;IAMA,IAAId,MAAJ,EAAY;MACRA,MAAM;IACT;EACJ,CAVD;;EAYA,oBACI,6BAAC,iBAAD;IACI,OAAO,EAAED,OADb;IAEI,MAAM,EAAEU,UAFZ;IAGI,UAAU,EAAER,UAHhB;IAII,MAAM,EAAE;MAAEc,GAAG,EAAEb,MAAM,CAACa;IAAd,CAJZ;IAKI,KAAK,EAAE,CACHX,KADG,EAEH;MAAEC;IAAF,CAFG;EALX,EADJ;AAYH;;AAAA"}
|