Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct animated fab elevation value #3812

Merged
merged 1 commit into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/components/FAB/AnimatedFAB.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,12 @@ const AnimatedFAB = ({
const md2Elevation = disabled || !isIOS ? 0 : 6;
const md3Elevation = disabled || !isIOS ? 0 : 3;

const shadowStyle = isV3 ? styles.v3Shadow : styles.shadow;
const baseStyle = [
StyleSheet.absoluteFill,
disabled ? styles.disabled : shadowStyle,
];

const newAccessibilityState = { ...accessibilityState, disabled };

return (
Expand Down Expand Up @@ -359,8 +365,7 @@ const AnimatedFAB = ({
<Animated.View
pointerEvents="none"
style={[
StyleSheet.absoluteFill,
disabled ? styles.disabled : styles.shadow,
baseStyle,
{
width: extendedWidth,
opacity: animFAB.interpolate({
Expand All @@ -370,12 +375,12 @@ const AnimatedFAB = ({
borderRadius,
},
]}
testID={`${testID}-extended-shadow`}
/>
<Animated.View
pointerEvents="none"
style={[
StyleSheet.absoluteFill,
disabled ? styles.disabled : styles.shadow,
baseStyle,
{
opacity: animFAB.interpolate({
inputRange: propForDirection([distance, 0.9 * distance, 0]),
Expand All @@ -392,6 +397,7 @@ const AnimatedFAB = ({
},
combinedStyles.absoluteFill,
]}
testID={`${testID}-shadow`}
/>
</View>
<Animated.View
Expand Down Expand Up @@ -519,6 +525,9 @@ const styles = StyleSheet.create({
shadow: {
elevation: 6,
},
v3Shadow: {
elevation: 3,
},
iconWrapper: {
alignItems: 'center',
justifyContent: 'center',
Expand Down
18 changes: 18 additions & 0 deletions src/components/__tests__/AnimatedFAB.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,21 @@ it('renders FAB with uppercase styling if uppercase prop is truthy', () => {
textTransform: 'uppercase',
});
});

it('renders correct elevation value for shadow views', () => {
const { getByTestId } = render(
<AnimatedFAB
extended
label="text"
animateFrom="left"
onPress={() => {}}
icon="plus"
testID="animated-fab"
/>
);

expect(getByTestId('animated-fab-shadow')).toHaveStyle({ elevation: 3 });
expect(getByTestId('animated-fab-extended-shadow')).toHaveStyle({
elevation: 3,
});
});
18 changes: 12 additions & 6 deletions src/components/__tests__/__snapshots__/AnimatedFAB.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ exports[`renders animated fab 1`] = `
Object {
"borderRadius": 16,
"bottom": 0,
"elevation": 6,
"elevation": 3,
"left": 0,
"opacity": 0,
"position": "absolute",
Expand All @@ -94,6 +94,7 @@ exports[`renders animated fab 1`] = `
"width": 72,
}
}
testID="animated-fab-extended-shadow"
/>
<View
collapsable={false}
Expand All @@ -102,7 +103,7 @@ exports[`renders animated fab 1`] = `
Object {
"borderRadius": 16,
"bottom": 0,
"elevation": 6,
"elevation": 3,
"left": 0,
"opacity": 1,
"position": "absolute",
Expand All @@ -116,6 +117,7 @@ exports[`renders animated fab 1`] = `
"width": 56,
}
}
testID="animated-fab-shadow"
/>
</View>
<View
Expand Down Expand Up @@ -376,7 +378,7 @@ exports[`renders animated fab with label on the left 1`] = `
Object {
"borderRadius": 16,
"bottom": 0,
"elevation": 6,
"elevation": 3,
"left": 0,
"opacity": 0,
"position": "absolute",
Expand All @@ -385,6 +387,7 @@ exports[`renders animated fab with label on the left 1`] = `
"width": 72,
}
}
testID="animated-fab-extended-shadow"
/>
<View
collapsable={false}
Expand All @@ -393,7 +396,7 @@ exports[`renders animated fab with label on the left 1`] = `
Object {
"borderRadius": 16,
"bottom": 0,
"elevation": 6,
"elevation": 3,
"left": 0,
"opacity": 1,
"position": "absolute",
Expand All @@ -407,6 +410,7 @@ exports[`renders animated fab with label on the left 1`] = `
"width": 56,
}
}
testID="animated-fab-shadow"
/>
</View>
<View
Expand Down Expand Up @@ -669,7 +673,7 @@ exports[`renders animated fab with label on the right by default 1`] = `
Object {
"borderRadius": 16,
"bottom": 0,
"elevation": 6,
"elevation": 3,
"left": 0,
"opacity": 0,
"position": "absolute",
Expand All @@ -678,6 +682,7 @@ exports[`renders animated fab with label on the right by default 1`] = `
"width": 72,
}
}
testID="animated-fab-extended-shadow"
/>
<View
collapsable={false}
Expand All @@ -686,7 +691,7 @@ exports[`renders animated fab with label on the right by default 1`] = `
Object {
"borderRadius": 16,
"bottom": 0,
"elevation": 6,
"elevation": 3,
"left": 0,
"opacity": 1,
"position": "absolute",
Expand All @@ -700,6 +705,7 @@ exports[`renders animated fab with label on the right by default 1`] = `
"width": 56,
}
}
testID="animated-fab-shadow"
/>
</View>
<View
Expand Down