@hero-design/rn 8.30.2 → 8.30.3
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/.turbo/turbo-build.log +1 -1
- package/es/index.js +147 -49
- package/lib/index.js +147 -49
- package/package.json +5 -5
- package/src/components/FAB/ActionGroup/__tests__/__snapshots__/index.spec.tsx.snap +982 -819
- package/src/components/FAB/ActionGroup/__tests__/index.spec.tsx +4 -11
- package/src/components/FAB/ActionGroup/index.tsx +142 -98
- package/src/components/FAB/AnimatedFABIcon.tsx +3 -5
- package/src/components/FAB/FAB.tsx +112 -28
- package/src/components/FAB/__tests__/__snapshots__/index.spec.tsx.snap +27 -9
- package/src/components/FAB/__tests__/index.spec.tsx +22 -2
- package/src/types.ts +4 -0
- package/testUtils/setup.tsx +2 -0
- package/types/components/FAB/ActionGroup/StyledActionGroup.d.ts +1 -1
- package/types/components/FAB/ActionGroup/index.d.ts +7 -1
- package/types/components/FAB/FAB.d.ts +8 -2
- package/types/components/FAB/index.d.ts +3 -2
- package/types/types.d.ts +3 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import '@testing-library/jest-native/extend-expect';
|
|
2
|
-
import React from 'react';
|
|
3
2
|
import { fireEvent } from '@testing-library/react-native';
|
|
4
|
-
import
|
|
3
|
+
import React from 'react';
|
|
5
4
|
import ActionGroup from '..';
|
|
5
|
+
import renderWithTheme from '../../../../testHelpers/renderWithTheme';
|
|
6
6
|
|
|
7
7
|
describe('ActionGroup', () => {
|
|
8
8
|
it.each`
|
|
@@ -40,23 +40,16 @@ describe('ActionGroup', () => {
|
|
|
40
40
|
expect(toJSON()).toMatchSnapshot();
|
|
41
41
|
|
|
42
42
|
expect(getByText('What would you like to create?')).toBeDefined();
|
|
43
|
-
expect(getByText('Shout out')).toBeDefined();
|
|
44
43
|
expect(getByTestId('speaker-action-item')).toBeDefined();
|
|
45
44
|
expect(getByTestId('target-action-item')).toBeDefined();
|
|
46
45
|
expect(getByTestId('plane-action-item')).toBeDefined();
|
|
47
46
|
expect(getByTestId('health-bag-action-item')).toBeDefined();
|
|
48
47
|
|
|
49
48
|
if (active) {
|
|
50
|
-
// verify
|
|
51
|
-
expect(getByTestId('action-group')).toHaveStyle({
|
|
52
|
-
transform: [{ translateX: 0 }],
|
|
53
|
-
});
|
|
49
|
+
// verify backdrop appears
|
|
54
50
|
expect(getByTestId('back-drop')).toHaveProp('pointerEvents', 'auto');
|
|
55
51
|
} else {
|
|
56
|
-
// verify
|
|
57
|
-
expect(getByTestId('action-group')).toHaveStyle({
|
|
58
|
-
transform: [{ translateX: 400 }],
|
|
59
|
-
});
|
|
52
|
+
// verify backdrop disappears
|
|
60
53
|
expect(getByTestId('back-drop')).toHaveProp('pointerEvents', 'box-none');
|
|
61
54
|
}
|
|
62
55
|
});
|
|
@@ -1,35 +1,29 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
|
|
1
|
+
import React, {
|
|
2
|
+
forwardRef,
|
|
3
|
+
useEffect,
|
|
4
|
+
useImperativeHandle,
|
|
5
|
+
useRef,
|
|
6
|
+
} from 'react';
|
|
3
7
|
import type { StyleProp, ViewStyle } from 'react-native';
|
|
8
|
+
import { Animated, Platform } from 'react-native';
|
|
9
|
+
import type { IconName } from '../../Icon';
|
|
10
|
+
import type { ActionItemProps } from './ActionItem';
|
|
4
11
|
import ActionItem from './ActionItem';
|
|
5
12
|
import {
|
|
13
|
+
StyledActionGroupContainer,
|
|
6
14
|
StyledBackdrop,
|
|
7
15
|
StyledContainer,
|
|
8
16
|
StyledFAB,
|
|
9
17
|
StyledHeaderText,
|
|
10
|
-
StyledActionGroupContainer,
|
|
11
18
|
} from './StyledActionGroup';
|
|
12
|
-
import type { IconName } from '../../Icon';
|
|
13
|
-
import type { ActionItemProps } from './ActionItem';
|
|
14
19
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}: ActionItemsContainerProps) => {
|
|
23
|
-
return (
|
|
24
|
-
<View style={style}>
|
|
25
|
-
{items?.map((itemProp) => (
|
|
26
|
-
<ActionItem
|
|
27
|
-
key={itemProp.key || `${itemProp.icon}_${itemProp.title}`}
|
|
28
|
-
{...itemProp}
|
|
29
|
-
/>
|
|
30
|
-
))}
|
|
31
|
-
</View>
|
|
32
|
-
);
|
|
20
|
+
import Box from '../../Box';
|
|
21
|
+
import { FABHandles } from '../FAB';
|
|
22
|
+
|
|
23
|
+
export type ActionGroupHandles = {
|
|
24
|
+
showFAB: () => void;
|
|
25
|
+
collapseFAB: () => void;
|
|
26
|
+
hideFAB: () => void;
|
|
33
27
|
};
|
|
34
28
|
|
|
35
29
|
export interface ActionGroupProps {
|
|
@@ -66,87 +60,137 @@ export interface ActionGroupProps {
|
|
|
66
60
|
/**
|
|
67
61
|
* Action items of the action group.
|
|
68
62
|
* */
|
|
69
|
-
|
|
70
63
|
items?: Array<ActionItemProps>;
|
|
64
|
+
|
|
71
65
|
/**
|
|
72
66
|
* Testing id of the component.
|
|
73
67
|
*/
|
|
74
|
-
|
|
75
68
|
testID?: string;
|
|
76
69
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
active,
|
|
81
|
-
style,
|
|
82
|
-
items,
|
|
83
|
-
testID,
|
|
84
|
-
fabTitle,
|
|
85
|
-
fabIcon = 'add',
|
|
86
|
-
}: ActionGroupProps) => {
|
|
87
|
-
const tranlateXAnimation = useRef<Animated.Value>(
|
|
88
|
-
new Animated.Value(active ? 1 : 0)
|
|
89
|
-
);
|
|
90
|
-
useEffect(() => {
|
|
91
|
-
const animation = Animated.timing(tranlateXAnimation.current, {
|
|
92
|
-
toValue: active ? 1 : 0,
|
|
93
|
-
useNativeDriver: Platform.OS === 'ios' || Platform.OS === 'android',
|
|
94
|
-
easing: Easing.inOut(Easing.cubic),
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
animation.start();
|
|
98
|
-
}, [active]);
|
|
99
|
-
|
|
100
|
-
const interpolatedTranlateXAnimation = tranlateXAnimation.current.interpolate(
|
|
70
|
+
|
|
71
|
+
const ActionGroup = forwardRef<ActionGroupHandles, ActionGroupProps>(
|
|
72
|
+
(
|
|
101
73
|
{
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
74
|
+
headerTitle,
|
|
75
|
+
onPress,
|
|
76
|
+
active,
|
|
77
|
+
style,
|
|
78
|
+
items,
|
|
79
|
+
testID,
|
|
80
|
+
fabTitle,
|
|
81
|
+
fabIcon = 'add',
|
|
82
|
+
},
|
|
83
|
+
ref
|
|
84
|
+
) => {
|
|
85
|
+
const fabRef = useRef<FABHandles>(null);
|
|
86
|
+
const tranlateXAnimation = useRef<Animated.Value>(
|
|
87
|
+
new Animated.Value(active ? 1 : 0)
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const animatedValues = useRef(
|
|
91
|
+
items?.map(() => new Animated.Value(0)) || []
|
|
92
|
+
).current;
|
|
93
|
+
|
|
94
|
+
const translateYAnimations = animatedValues?.map((value) =>
|
|
95
|
+
value.interpolate({
|
|
96
|
+
inputRange: [0, 1],
|
|
97
|
+
outputRange: active ? [100, 0] : [40, 0],
|
|
98
|
+
})
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
useImperativeHandle(
|
|
102
|
+
ref,
|
|
103
|
+
() => ({
|
|
104
|
+
showFAB: () => fabRef.current?.show(),
|
|
105
|
+
collapseFAB: () => fabRef.current?.collapse(),
|
|
106
|
+
hideFAB: () => fabRef.current?.hide(),
|
|
107
|
+
}),
|
|
108
|
+
[fabRef]
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
Animated.spring(tranlateXAnimation.current, {
|
|
113
|
+
toValue: active ? 1 : 0,
|
|
114
|
+
useNativeDriver: Platform.OS !== 'web',
|
|
115
|
+
}).start();
|
|
116
|
+
|
|
117
|
+
Animated.stagger(
|
|
118
|
+
20,
|
|
119
|
+
animatedValues
|
|
120
|
+
.map((value) =>
|
|
121
|
+
Animated.spring(value, {
|
|
122
|
+
toValue: active ? 1 : 0,
|
|
123
|
+
useNativeDriver: Platform.OS !== 'web',
|
|
124
|
+
})
|
|
125
|
+
)
|
|
126
|
+
.reverse()
|
|
127
|
+
).start();
|
|
128
|
+
}, [active, animatedValues]);
|
|
129
|
+
|
|
130
|
+
const interpolatedBackdropOpacityAnimation =
|
|
131
|
+
tranlateXAnimation.current.interpolate({
|
|
132
|
+
inputRange: [0, 1],
|
|
133
|
+
outputRange: [0, 0.4],
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const interpolatedActionGroupOpacityAnimation =
|
|
137
|
+
tranlateXAnimation.current.interpolate({
|
|
138
|
+
inputRange: [0, 1],
|
|
139
|
+
outputRange: [0, 1],
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
return (
|
|
143
|
+
<StyledContainer testID={testID} pointerEvents="box-none" style={style}>
|
|
144
|
+
<StyledBackdrop
|
|
145
|
+
pointerEvents={active ? 'auto' : 'box-none'}
|
|
146
|
+
testID="back-drop"
|
|
147
|
+
style={{ opacity: interpolatedBackdropOpacityAnimation }}
|
|
148
|
+
/>
|
|
149
|
+
<StyledActionGroupContainer
|
|
150
|
+
pointerEvents={active ? 'auto' : 'none'}
|
|
151
|
+
testID="action-group"
|
|
152
|
+
style={{
|
|
153
|
+
opacity: interpolatedActionGroupOpacityAnimation,
|
|
154
|
+
}}
|
|
155
|
+
>
|
|
156
|
+
{!!headerTitle && (
|
|
157
|
+
<Animated.View
|
|
158
|
+
style={{
|
|
159
|
+
transform: [{ translateY: translateYAnimations[0] }],
|
|
160
|
+
}}
|
|
161
|
+
>
|
|
162
|
+
<StyledHeaderText testID="header-text">
|
|
163
|
+
{headerTitle}
|
|
164
|
+
</StyledHeaderText>
|
|
165
|
+
</Animated.View>
|
|
166
|
+
)}
|
|
167
|
+
|
|
168
|
+
<Box style={[style, { paddingBottom: 0 }]}>
|
|
169
|
+
{items?.map((itemProp, index) => (
|
|
170
|
+
<Animated.View
|
|
171
|
+
key={itemProp.key || `${itemProp.icon}_${itemProp.title}`}
|
|
172
|
+
style={{
|
|
173
|
+
transform: [{ translateY: translateYAnimations[index] }],
|
|
174
|
+
}}
|
|
175
|
+
>
|
|
176
|
+
<ActionItem {...itemProp} />
|
|
177
|
+
</Animated.View>
|
|
178
|
+
))}
|
|
179
|
+
</Box>
|
|
180
|
+
</StyledActionGroupContainer>
|
|
181
|
+
|
|
182
|
+
<StyledFAB
|
|
183
|
+
testID="fab"
|
|
184
|
+
icon={fabIcon}
|
|
185
|
+
onPress={onPress}
|
|
186
|
+
animated
|
|
187
|
+
active={active}
|
|
188
|
+
title={fabTitle}
|
|
189
|
+
ref={fabRef}
|
|
190
|
+
/>
|
|
191
|
+
</StyledContainer>
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
);
|
|
151
195
|
|
|
152
196
|
export default ActionGroup;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useEffect, useRef } from 'react';
|
|
2
|
-
import { Animated,
|
|
3
|
-
import { StyledFABIcon } from './StyledFAB';
|
|
2
|
+
import { Animated, Platform, StyleSheet } from 'react-native';
|
|
4
3
|
import type { IconProps } from '../Icon';
|
|
4
|
+
import { StyledFABIcon } from './StyledFAB';
|
|
5
5
|
|
|
6
6
|
const AnimatedIcons = Animated.createAnimatedComponent(StyledFABIcon);
|
|
7
7
|
|
|
@@ -14,11 +14,9 @@ const AnimatedFABIcon = ({ active, ...iconProps }: Props) => {
|
|
|
14
14
|
new Animated.Value(active ? 1 : 0)
|
|
15
15
|
);
|
|
16
16
|
useEffect(() => {
|
|
17
|
-
const animation = Animated.
|
|
17
|
+
const animation = Animated.spring(rotateAnimation.current, {
|
|
18
18
|
toValue: active ? 1 : 0,
|
|
19
19
|
useNativeDriver: Platform.OS === 'ios' || Platform.OS === 'android',
|
|
20
|
-
easing: Easing.inOut(Easing.ease),
|
|
21
|
-
duration: 300,
|
|
22
20
|
});
|
|
23
21
|
|
|
24
22
|
animation.start();
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import
|
|
1
|
+
import React, { forwardRef, useEffect, useImperativeHandle } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
LayoutAnimation,
|
|
4
|
+
LayoutAnimationConfig,
|
|
5
|
+
Platform,
|
|
6
|
+
StyleProp,
|
|
7
|
+
StyleSheet,
|
|
8
|
+
UIManager,
|
|
9
|
+
ViewStyle,
|
|
10
|
+
} from 'react-native';
|
|
3
11
|
import { useTheme } from '../../theme';
|
|
4
12
|
import type { IconName } from '../Icon';
|
|
5
13
|
import { AnimatedFABIcon } from './AnimatedFABIcon';
|
|
@@ -10,6 +18,18 @@ import {
|
|
|
10
18
|
StyledIconContainer,
|
|
11
19
|
} from './StyledFAB';
|
|
12
20
|
|
|
21
|
+
if (Platform.OS === 'android') {
|
|
22
|
+
if (UIManager.setLayoutAnimationEnabledExperimental) {
|
|
23
|
+
UIManager.setLayoutAnimationEnabledExperimental(true);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type FABHandles = {
|
|
28
|
+
show: () => void;
|
|
29
|
+
collapse: () => void;
|
|
30
|
+
hide: () => void;
|
|
31
|
+
};
|
|
32
|
+
|
|
13
33
|
export interface FABProps {
|
|
14
34
|
/**
|
|
15
35
|
* Name of the Icon.
|
|
@@ -54,7 +74,6 @@ const IconOnlyContent = ({
|
|
|
54
74
|
}: {
|
|
55
75
|
icon: IconName;
|
|
56
76
|
animated?: boolean;
|
|
57
|
-
|
|
58
77
|
active?: boolean;
|
|
59
78
|
}) => {
|
|
60
79
|
if (animated) {
|
|
@@ -85,31 +104,96 @@ const IconWithTextContent = ({
|
|
|
85
104
|
<StyledFABText>{title}</StyledFABText>
|
|
86
105
|
</>
|
|
87
106
|
);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}: FABProps): JSX.Element => {
|
|
97
|
-
const isIconOnly = !title;
|
|
98
|
-
const theme = useTheme();
|
|
99
|
-
return (
|
|
100
|
-
<StyledFAB
|
|
101
|
-
underlayColor={theme.__hd__.fab.colors.buttonPressedBackground}
|
|
102
|
-
onPress={onPress}
|
|
103
|
-
style={style}
|
|
104
|
-
testID={testID}
|
|
105
|
-
>
|
|
106
|
-
{isIconOnly ? (
|
|
107
|
-
<IconOnlyContent animated={animated} active={active} icon={icon} />
|
|
108
|
-
) : (
|
|
109
|
-
<IconWithTextContent icon={icon} title={title} />
|
|
110
|
-
)}
|
|
111
|
-
</StyledFAB>
|
|
112
|
-
);
|
|
107
|
+
|
|
108
|
+
const defaultAnimation: LayoutAnimationConfig = {
|
|
109
|
+
create: {
|
|
110
|
+
type: 'easeInEaseOut',
|
|
111
|
+
property: 'opacity',
|
|
112
|
+
},
|
|
113
|
+
update: { type: 'spring', springDamping: 1 },
|
|
114
|
+
duration: 400,
|
|
113
115
|
};
|
|
114
116
|
|
|
117
|
+
const FAB = forwardRef<FABHandles, FABProps>(
|
|
118
|
+
({ onPress, title, icon, animated, testID, active, style }, ref) => {
|
|
119
|
+
const theme = useTheme();
|
|
120
|
+
|
|
121
|
+
const [displayState, setDisplayState] = React.useState({
|
|
122
|
+
hideTitle: false,
|
|
123
|
+
hideButton: false,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const [canAnimate, setCanAnimate] = React.useState(false);
|
|
127
|
+
|
|
128
|
+
const isIconOnly = displayState.hideTitle || active || !title;
|
|
129
|
+
|
|
130
|
+
useImperativeHandle(
|
|
131
|
+
ref,
|
|
132
|
+
() => ({
|
|
133
|
+
show: () => {
|
|
134
|
+
setDisplayState({
|
|
135
|
+
hideButton: false,
|
|
136
|
+
hideTitle: false,
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
collapse: () => {
|
|
140
|
+
setDisplayState({
|
|
141
|
+
hideButton: false,
|
|
142
|
+
hideTitle: true,
|
|
143
|
+
});
|
|
144
|
+
},
|
|
145
|
+
hide: () => {
|
|
146
|
+
setDisplayState((previousState) => ({
|
|
147
|
+
...previousState,
|
|
148
|
+
hideButton: true,
|
|
149
|
+
}));
|
|
150
|
+
},
|
|
151
|
+
}),
|
|
152
|
+
[displayState]
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
useEffect(() => {
|
|
156
|
+
if (canAnimate) {
|
|
157
|
+
LayoutAnimation.configureNext(defaultAnimation);
|
|
158
|
+
}
|
|
159
|
+
}, [isIconOnly]);
|
|
160
|
+
|
|
161
|
+
useEffect(() => {
|
|
162
|
+
if (canAnimate) {
|
|
163
|
+
LayoutAnimation.configureNext(defaultAnimation);
|
|
164
|
+
}
|
|
165
|
+
}, [displayState.hideButton]);
|
|
166
|
+
|
|
167
|
+
const marginBottom = Number(StyleSheet.flatten(style)?.marginBottom) || 0;
|
|
168
|
+
|
|
169
|
+
return (
|
|
170
|
+
<StyledFAB
|
|
171
|
+
/** Add a small timeout before executing animation to prevent flakiness on android */
|
|
172
|
+
onLayout={() => setTimeout(() => setCanAnimate(true), 200)}
|
|
173
|
+
underlayColor={theme.__hd__.fab.colors.buttonPressedBackground}
|
|
174
|
+
onPress={onPress}
|
|
175
|
+
style={[
|
|
176
|
+
style,
|
|
177
|
+
{
|
|
178
|
+
bottom: displayState.hideButton
|
|
179
|
+
? -(marginBottom + theme.__hd__.fab.sizes.height * 2)
|
|
180
|
+
: StyleSheet.flatten(style)?.bottom,
|
|
181
|
+
},
|
|
182
|
+
]}
|
|
183
|
+
testID={testID}
|
|
184
|
+
>
|
|
185
|
+
{isIconOnly ? (
|
|
186
|
+
<IconOnlyContent
|
|
187
|
+
animated={animated}
|
|
188
|
+
active={active}
|
|
189
|
+
icon={active ? 'add' : icon}
|
|
190
|
+
/>
|
|
191
|
+
) : (
|
|
192
|
+
<IconWithTextContent icon={icon} title={title} />
|
|
193
|
+
)}
|
|
194
|
+
</StyledFAB>
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
);
|
|
198
|
+
|
|
115
199
|
export default FAB;
|
|
@@ -5,6 +5,7 @@ exports[`FAB when animated is false renders StyledFABIcon 1`] = `
|
|
|
5
5
|
accessible={true}
|
|
6
6
|
focusable={false}
|
|
7
7
|
onClick={[Function]}
|
|
8
|
+
onLayout={[Function]}
|
|
8
9
|
onResponderGrant={[Function]}
|
|
9
10
|
onResponderMove={[Function]}
|
|
10
11
|
onResponderRelease={[Function]}
|
|
@@ -30,9 +31,14 @@ exports[`FAB when animated is false renders StyledFABIcon 1`] = `
|
|
|
30
31
|
"shadowOpacity": 0.12,
|
|
31
32
|
"shadowRadius": 8,
|
|
32
33
|
},
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
Array [
|
|
35
|
+
Object {
|
|
36
|
+
"backgroundColor": "#001f23",
|
|
37
|
+
},
|
|
38
|
+
Object {
|
|
39
|
+
"bottom": undefined,
|
|
40
|
+
},
|
|
41
|
+
],
|
|
36
42
|
]
|
|
37
43
|
}
|
|
38
44
|
>
|
|
@@ -67,6 +73,7 @@ exports[`FAB when animated is true renders animatedFABIcon 1`] = `
|
|
|
67
73
|
accessible={true}
|
|
68
74
|
focusable={false}
|
|
69
75
|
onClick={[Function]}
|
|
76
|
+
onLayout={[Function]}
|
|
70
77
|
onResponderGrant={[Function]}
|
|
71
78
|
onResponderMove={[Function]}
|
|
72
79
|
onResponderRelease={[Function]}
|
|
@@ -92,9 +99,14 @@ exports[`FAB when animated is true renders animatedFABIcon 1`] = `
|
|
|
92
99
|
"shadowOpacity": 0.12,
|
|
93
100
|
"shadowRadius": 8,
|
|
94
101
|
},
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
102
|
+
Array [
|
|
103
|
+
Object {
|
|
104
|
+
"backgroundColor": "#001f23",
|
|
105
|
+
},
|
|
106
|
+
Object {
|
|
107
|
+
"bottom": undefined,
|
|
108
|
+
},
|
|
109
|
+
],
|
|
98
110
|
]
|
|
99
111
|
}
|
|
100
112
|
>
|
|
@@ -159,6 +171,7 @@ exports[`FAB when title has value renders correctly 1`] = `
|
|
|
159
171
|
accessible={true}
|
|
160
172
|
focusable={false}
|
|
161
173
|
onClick={[Function]}
|
|
174
|
+
onLayout={[Function]}
|
|
162
175
|
onResponderGrant={[Function]}
|
|
163
176
|
onResponderMove={[Function]}
|
|
164
177
|
onResponderRelease={[Function]}
|
|
@@ -184,9 +197,14 @@ exports[`FAB when title has value renders correctly 1`] = `
|
|
|
184
197
|
"shadowOpacity": 0.12,
|
|
185
198
|
"shadowRadius": 8,
|
|
186
199
|
},
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
200
|
+
Array [
|
|
201
|
+
Object {
|
|
202
|
+
"backgroundColor": "#001f23",
|
|
203
|
+
},
|
|
204
|
+
Object {
|
|
205
|
+
"bottom": undefined,
|
|
206
|
+
},
|
|
207
|
+
],
|
|
190
208
|
]
|
|
191
209
|
}
|
|
192
210
|
>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { createRef } from 'react';
|
|
2
2
|
import { fireEvent } from '@testing-library/react-native';
|
|
3
3
|
import renderWithTheme from '../../../testHelpers/renderWithTheme';
|
|
4
|
-
import { theme } from '../../../index';
|
|
4
|
+
import { FABHandles, theme } from '../../../index';
|
|
5
5
|
import FAB from '..';
|
|
6
6
|
|
|
7
7
|
describe('FAB', () => {
|
|
@@ -66,4 +66,24 @@ describe('FAB', () => {
|
|
|
66
66
|
expect(onPressSpy).toBeCalledTimes(1);
|
|
67
67
|
});
|
|
68
68
|
});
|
|
69
|
+
|
|
70
|
+
describe('usage with ref', () => {
|
|
71
|
+
it('allow controlling inner fab states by ref', () => {
|
|
72
|
+
const fabRef = createRef<FABHandles>();
|
|
73
|
+
|
|
74
|
+
const { queryByText } = renderWithTheme(
|
|
75
|
+
<FAB ref={fabRef} title="Shout out" icon="speaker" />
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
expect(queryByText('Shout out')).toBeDefined();
|
|
79
|
+
fabRef.current!.collapse();
|
|
80
|
+
expect(queryByText('Shout out')).toBeFalsy();
|
|
81
|
+
|
|
82
|
+
fabRef.current!.show();
|
|
83
|
+
expect(queryByText('Shout out')).toBeDefined();
|
|
84
|
+
|
|
85
|
+
fabRef.current!.hide();
|
|
86
|
+
expect(queryByText('Shout out')).toBeDefined();
|
|
87
|
+
});
|
|
88
|
+
});
|
|
69
89
|
});
|
package/src/types.ts
CHANGED
|
@@ -15,6 +15,8 @@ import type {
|
|
|
15
15
|
import { SwipeableProps } from './components/Swipeable';
|
|
16
16
|
import { TextProps } from './components/Typography/Text';
|
|
17
17
|
import { CardCarouselHandles } from './components/Carousel/CardCarousel';
|
|
18
|
+
import { FABHandles } from './components/FAB/FAB';
|
|
19
|
+
import { ActionGroupHandles } from './components/FAB/ActionGroup';
|
|
18
20
|
|
|
19
21
|
export type {
|
|
20
22
|
BottomNavigationTabType,
|
|
@@ -32,4 +34,6 @@ export type {
|
|
|
32
34
|
TextInputHandles,
|
|
33
35
|
Theme,
|
|
34
36
|
CardCarouselHandles,
|
|
37
|
+
FABHandles,
|
|
38
|
+
ActionGroupHandles,
|
|
35
39
|
};
|
package/testUtils/setup.tsx
CHANGED
|
@@ -11,6 +11,7 @@ jest.mock('react-native', () => {
|
|
|
11
11
|
const RN = jest.requireActual('react-native');
|
|
12
12
|
|
|
13
13
|
const mockedAnimatedFunctions = {
|
|
14
|
+
setImmediate: () => jest.fn(),
|
|
14
15
|
start: () => jest.fn(),
|
|
15
16
|
stop: () => jest.fn(),
|
|
16
17
|
_isUsingNativeDriver: () => jest.fn(),
|
|
@@ -19,6 +20,7 @@ jest.mock('react-native', () => {
|
|
|
19
20
|
|
|
20
21
|
RN.Animated.timing = () => mockedAnimatedFunctions;
|
|
21
22
|
RN.Animated.spring = () => mockedAnimatedFunctions;
|
|
23
|
+
RN.Animated.stagger = () => mockedAnimatedFunctions;
|
|
22
24
|
|
|
23
25
|
return RN;
|
|
24
26
|
});
|
|
@@ -14,7 +14,7 @@ declare const StyledActionGroupContainer: import("@emotion/native").StyledCompon
|
|
|
14
14
|
theme?: import("@emotion/react").Theme | undefined;
|
|
15
15
|
as?: import("react").ElementType<any> | undefined;
|
|
16
16
|
}, {}, {}>;
|
|
17
|
-
declare const StyledFAB: import("@emotion/native").StyledComponent<import("../FAB").FABProps & {
|
|
17
|
+
declare const StyledFAB: import("@emotion/native").StyledComponent<import("../FAB").FABProps & import("react").RefAttributes<import("../FAB").FABHandles> & {
|
|
18
18
|
theme?: import("@emotion/react").Theme | undefined;
|
|
19
19
|
as?: import("react").ElementType<any> | undefined;
|
|
20
20
|
}, {}, {}>;
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
import type { StyleProp, ViewStyle } from 'react-native';
|
|
2
3
|
import type { IconName } from '../../Icon';
|
|
3
4
|
import type { ActionItemProps } from './ActionItem';
|
|
5
|
+
export declare type ActionGroupHandles = {
|
|
6
|
+
showFAB: () => void;
|
|
7
|
+
collapseFAB: () => void;
|
|
8
|
+
hideFAB: () => void;
|
|
9
|
+
};
|
|
4
10
|
export interface ActionGroupProps {
|
|
5
11
|
/**
|
|
6
12
|
* Title of the action group header.
|
|
@@ -35,5 +41,5 @@ export interface ActionGroupProps {
|
|
|
35
41
|
*/
|
|
36
42
|
testID?: string;
|
|
37
43
|
}
|
|
38
|
-
declare const ActionGroup:
|
|
44
|
+
declare const ActionGroup: React.ForwardRefExoticComponent<ActionGroupProps & React.RefAttributes<ActionGroupHandles>>;
|
|
39
45
|
export default ActionGroup;
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { StyleProp, ViewStyle } from 'react-native';
|
|
2
3
|
import type { IconName } from '../Icon';
|
|
4
|
+
export declare type FABHandles = {
|
|
5
|
+
show: () => void;
|
|
6
|
+
collapse: () => void;
|
|
7
|
+
hide: () => void;
|
|
8
|
+
};
|
|
3
9
|
export interface FABProps {
|
|
4
10
|
/**
|
|
5
11
|
* Name of the Icon.
|
|
@@ -30,5 +36,5 @@ export interface FABProps {
|
|
|
30
36
|
*/
|
|
31
37
|
testID?: string;
|
|
32
38
|
}
|
|
33
|
-
declare const FAB:
|
|
39
|
+
declare const FAB: React.ForwardRefExoticComponent<FABProps & React.RefAttributes<FABHandles>>;
|
|
34
40
|
export default FAB;
|