Skip to content

Commit 6f3ba78

Browse files
refactor: remove middle layer in Surface
1 parent 93e2bff commit 6f3ba78

File tree

2 files changed

+23
-32
lines changed

2 files changed

+23
-32
lines changed

src/components/FAB/FAB.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ const FAB = forwardRef<View, Props>(
266266
},
267267
],
268268
},
269-
styles.container,
270269
!isV3 && styles.elevated,
271270
!isV3 && disabled && styles.disabled,
272271
style,
@@ -286,6 +285,7 @@ const FAB = forwardRef<View, Props>(
286285
accessibilityRole="button"
287286
accessibilityState={newAccessibilityState}
288287
testID={testID}
288+
style={{ borderRadius }}
289289
>
290290
<View
291291
style={[styles.content, label ? extendedStyle : fabStyle]}
@@ -330,9 +330,6 @@ const styles = StyleSheet.create({
330330
elevated: {
331331
elevation: 6,
332332
},
333-
container: {
334-
overflow: 'hidden',
335-
},
336333
content: {
337334
flexDirection: 'row',
338335
alignItems: 'center',

src/components/Surface.tsx

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -238,21 +238,26 @@ const Surface = forwardRef<View, Props>(
238238
...restStyle
239239
} = (StyleSheet.flatten(style) || {}) as ViewStyle;
240240

241-
const [filteredStyle, borderRadiusStyle, marginStyle] = splitStyles(
242-
restStyle,
243-
(style) => style.startsWith('border') && style.endsWith('Radius'),
244-
(style) => style.startsWith('margin')
241+
const [filteredStyle, marginStyle] = splitStyles(restStyle, (style) =>
242+
style.startsWith('margin')
245243
);
246244

247-
const sharedStyles = {
248-
flex: height ? 1 : undefined,
249-
};
245+
if (
246+
process.env.NODE_ENV !== 'production' &&
247+
filteredStyle.overflow === 'hidden' &&
248+
elevation !== 0
249+
) {
250+
console.warn(
251+
'When setting overflow to hidden on Surface the shadow will not be displayed correctly. Wrap the content of your component in a separate View with the overflow style.'
252+
);
253+
}
250254

251255
const innerLayerViewStyles = [
252256
filteredStyle,
253-
sharedStyles,
254-
borderRadiusStyle,
255-
{ backgroundColor: backgroundColorStyle || backgroundColor },
257+
{
258+
flex: height ? 1 : undefined,
259+
backgroundColor: backgroundColorStyle || backgroundColor,
260+
},
256261
];
257262

258263
const outerLayerViewStyles = {
@@ -303,16 +308,10 @@ const Surface = forwardRef<View, Props>(
303308
testID={`${testID}-outer-layer`}
304309
>
305310
<Animated.View
306-
style={[getStyleForAnimatedShadowLayer(1), sharedStyles]}
307-
testID={`${testID}-middle-layer`}
311+
style={[getStyleForAnimatedShadowLayer(1), innerLayerViewStyles]}
312+
testID={testID}
308313
>
309-
<Animated.View
310-
{...props}
311-
testID={testID}
312-
style={innerLayerViewStyles}
313-
>
314-
{children}
315-
</Animated.View>
314+
{children}
316315
</Animated.View>
317316
</Animated.View>
318317
);
@@ -339,16 +338,11 @@ const Surface = forwardRef<View, Props>(
339338
testID={`${testID}-outer-layer`}
340339
>
341340
<Animated.View
342-
style={[getStyleForShadowLayer(1), sharedStyles]}
343-
testID={`${testID}-middle-layer`}
341+
{...props}
342+
style={[getStyleForShadowLayer(1), innerLayerViewStyles]}
343+
testID={testID}
344344
>
345-
<Animated.View
346-
{...props}
347-
testID={testID}
348-
style={innerLayerViewStyles}
349-
>
350-
{children}
351-
</Animated.View>
345+
{children}
352346
</Animated.View>
353347
</Animated.View>
354348
);

0 commit comments

Comments
 (0)