-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathShadowedView.android.tsx
More file actions
78 lines (74 loc) · 2.16 KB
/
ShadowedView.android.tsx
File metadata and controls
78 lines (74 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import React from 'react';
import {
I18nManager,
StyleSheet,
StyleProp, // eslint-disable-line @typescript-eslint/no-unused-vars
ViewProps,
ViewStyle, // eslint-disable-line @typescript-eslint/no-unused-vars
} from 'react-native';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { FastShadowView, FastShadowViewProps } from './FastShadowView';
export class ShadowedView extends React.Component<ViewProps> {
render(): React.ReactNode {
const { style, children } = this.props;
const child = React.isValidElement(children)
? (children as React.ReactElement<ViewProps>)
: undefined;
const cornerRadii = getCornerRadiiFromStyle(style) ??
getCornerRadiiFromStyle(child?.props.style) ?? {
topLeft: 0,
topRight: 0,
bottomLeft: 0,
bottomRight: 0,
};
return <FastShadowView {...this.props} cornerRadii={cornerRadii} />;
}
}
function getCornerRadiiFromStyle(
style: StyleProp<ViewStyle> | undefined
): FastShadowViewProps['cornerRadii'] | undefined {
const borderRadiusProps = [
'borderRadius',
'borderTopLeftRadius',
'borderTopStartRadius',
'borderTopRightRadius',
'borderTopEndRadius',
'borderBottomLeftRadius',
'borderBottomStartRadius',
'borderBottomRightRadius',
'borderBottomEndRadius',
] as const;
const s = StyleSheet.flatten(style) ?? {};
if (
!s.backgroundColor &&
!borderRadiusProps.some((prop) => s[prop] !== undefined)
) {
return undefined;
}
return {
topLeft:
(I18nManager.isRTL ? s.borderTopEndRadius : s.borderTopStartRadius) ??
s.borderTopLeftRadius ??
s.borderRadius ??
0,
topRight:
(I18nManager.isRTL ? s.borderTopStartRadius : s.borderTopEndRadius) ??
s.borderTopRightRadius ??
s.borderRadius ??
0,
bottomLeft:
(I18nManager.isRTL
? s.borderBottomEndRadius
: s.borderBottomStartRadius) ??
s.borderBottomLeftRadius ??
s.borderRadius ??
0,
bottomRight:
(I18nManager.isRTL
? s.borderBottomStartRadius
: s.borderBottomEndRadius) ??
s.borderBottomRightRadius ??
s.borderRadius ??
0,
};
}