Skip to content

Commit 130a0fd

Browse files
authored
fix: correct animated fab elevation value (#3812)
1 parent 0ed4dc4 commit 130a0fd

3 files changed

Lines changed: 43 additions & 10 deletions

File tree

src/components/FAB/AnimatedFAB.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,12 @@ const AnimatedFAB = ({
314314
const md2Elevation = disabled || !isIOS ? 0 : 6;
315315
const md3Elevation = disabled || !isIOS ? 0 : 3;
316316

317+
const shadowStyle = isV3 ? styles.v3Shadow : styles.shadow;
318+
const baseStyle = [
319+
StyleSheet.absoluteFill,
320+
disabled ? styles.disabled : shadowStyle,
321+
];
322+
317323
const newAccessibilityState = { ...accessibilityState, disabled };
318324

319325
return (
@@ -359,8 +365,7 @@ const AnimatedFAB = ({
359365
<Animated.View
360366
pointerEvents="none"
361367
style={[
362-
StyleSheet.absoluteFill,
363-
disabled ? styles.disabled : styles.shadow,
368+
baseStyle,
364369
{
365370
width: extendedWidth,
366371
opacity: animFAB.interpolate({
@@ -370,12 +375,12 @@ const AnimatedFAB = ({
370375
borderRadius,
371376
},
372377
]}
378+
testID={`${testID}-extended-shadow`}
373379
/>
374380
<Animated.View
375381
pointerEvents="none"
376382
style={[
377-
StyleSheet.absoluteFill,
378-
disabled ? styles.disabled : styles.shadow,
383+
baseStyle,
379384
{
380385
opacity: animFAB.interpolate({
381386
inputRange: propForDirection([distance, 0.9 * distance, 0]),
@@ -392,6 +397,7 @@ const AnimatedFAB = ({
392397
},
393398
combinedStyles.absoluteFill,
394399
]}
400+
testID={`${testID}-shadow`}
395401
/>
396402
</View>
397403
<Animated.View
@@ -519,6 +525,9 @@ const styles = StyleSheet.create({
519525
shadow: {
520526
elevation: 6,
521527
},
528+
v3Shadow: {
529+
elevation: 3,
530+
},
522531
iconWrapper: {
523532
alignItems: 'center',
524533
justifyContent: 'center',

src/components/__tests__/AnimatedFAB.test.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,21 @@ it('renders FAB with uppercase styling if uppercase prop is truthy', () => {
126126
textTransform: 'uppercase',
127127
});
128128
});
129+
130+
it('renders correct elevation value for shadow views', () => {
131+
const { getByTestId } = render(
132+
<AnimatedFAB
133+
extended
134+
label="text"
135+
animateFrom="left"
136+
onPress={() => {}}
137+
icon="plus"
138+
testID="animated-fab"
139+
/>
140+
);
141+
142+
expect(getByTestId('animated-fab-shadow')).toHaveStyle({ elevation: 3 });
143+
expect(getByTestId('animated-fab-extended-shadow')).toHaveStyle({
144+
elevation: 3,
145+
});
146+
});

src/components/__tests__/__snapshots__/AnimatedFAB.test.tsx.snap

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ exports[`renders animated fab 1`] = `
8585
Object {
8686
"borderRadius": 16,
8787
"bottom": 0,
88-
"elevation": 6,
88+
"elevation": 3,
8989
"left": 0,
9090
"opacity": 0,
9191
"position": "absolute",
@@ -94,6 +94,7 @@ exports[`renders animated fab 1`] = `
9494
"width": 72,
9595
}
9696
}
97+
testID="animated-fab-extended-shadow"
9798
/>
9899
<View
99100
collapsable={false}
@@ -102,7 +103,7 @@ exports[`renders animated fab 1`] = `
102103
Object {
103104
"borderRadius": 16,
104105
"bottom": 0,
105-
"elevation": 6,
106+
"elevation": 3,
106107
"left": 0,
107108
"opacity": 1,
108109
"position": "absolute",
@@ -116,6 +117,7 @@ exports[`renders animated fab 1`] = `
116117
"width": 56,
117118
}
118119
}
120+
testID="animated-fab-shadow"
119121
/>
120122
</View>
121123
<View
@@ -376,7 +378,7 @@ exports[`renders animated fab with label on the left 1`] = `
376378
Object {
377379
"borderRadius": 16,
378380
"bottom": 0,
379-
"elevation": 6,
381+
"elevation": 3,
380382
"left": 0,
381383
"opacity": 0,
382384
"position": "absolute",
@@ -385,6 +387,7 @@ exports[`renders animated fab with label on the left 1`] = `
385387
"width": 72,
386388
}
387389
}
390+
testID="animated-fab-extended-shadow"
388391
/>
389392
<View
390393
collapsable={false}
@@ -393,7 +396,7 @@ exports[`renders animated fab with label on the left 1`] = `
393396
Object {
394397
"borderRadius": 16,
395398
"bottom": 0,
396-
"elevation": 6,
399+
"elevation": 3,
397400
"left": 0,
398401
"opacity": 1,
399402
"position": "absolute",
@@ -407,6 +410,7 @@ exports[`renders animated fab with label on the left 1`] = `
407410
"width": 56,
408411
}
409412
}
413+
testID="animated-fab-shadow"
410414
/>
411415
</View>
412416
<View
@@ -669,7 +673,7 @@ exports[`renders animated fab with label on the right by default 1`] = `
669673
Object {
670674
"borderRadius": 16,
671675
"bottom": 0,
672-
"elevation": 6,
676+
"elevation": 3,
673677
"left": 0,
674678
"opacity": 0,
675679
"position": "absolute",
@@ -678,6 +682,7 @@ exports[`renders animated fab with label on the right by default 1`] = `
678682
"width": 72,
679683
}
680684
}
685+
testID="animated-fab-extended-shadow"
681686
/>
682687
<View
683688
collapsable={false}
@@ -686,7 +691,7 @@ exports[`renders animated fab with label on the right by default 1`] = `
686691
Object {
687692
"borderRadius": 16,
688693
"bottom": 0,
689-
"elevation": 6,
694+
"elevation": 3,
690695
"left": 0,
691696
"opacity": 1,
692697
"position": "absolute",
@@ -700,6 +705,7 @@ exports[`renders animated fab with label on the right by default 1`] = `
700705
"width": 56,
701706
}
702707
}
708+
testID="animated-fab-shadow"
703709
/>
704710
</View>
705711
<View

0 commit comments

Comments
 (0)