Skip to content

Commit 7b3cf89

Browse files
committed
chore: improve box-shadow performance
1 parent 046ab08 commit 7b3cf89

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

example/src/screens/ShadowsExampleScreen.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ const styles = StyleSheet.create(() => ({
5656
margin: [100, 0],
5757
backgroundColor: 'white',
5858
boxShadow: '1px 1px 15px gray',
59+
transition: [['boxShadow', 'borderRadius'], 800],
60+
61+
'&:active': {
62+
borderRadius: 100,
63+
},
5964
},
6065
text1: {
6166
margin: [50, 0, 5, 0],

src/Animated.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ export function createComponent<T extends NativeComponents>(WrappedComponent: T)
392392
{!!BeforeComponent && <BeforeComponent style={before}>{beforeContent}</BeforeComponent>}
393393

394394
{!mockShadow && renderComponent(e)}
395-
{mockShadow && <BoxShadow style={this.getStyleProps(e).style}>{renderComponent(e)}</BoxShadow>}
395+
{mockShadow && <BoxShadow {...this.getStyleProps(e)}>{renderComponent(e)}</BoxShadow>}
396396

397397
{!!AfterComponent && <AfterComponent style={after}>{afterContent}</AfterComponent>}
398398
</>

src/components/BoxShadow.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ class BoxShadow extends Component<BoxShadowProps> {
113113
const height = style.height || 0;
114114

115115
const shadowRadius = style.shadowRadius as any;
116-
let radius = shadowRadius / 20;
116+
let radius = Math.max(shadowRadius / 6, 1);
117117
if (typeof shadowRadius?._value !== 'undefined') {
118-
(shadowRadius as Animated.Value).addListener(({ value }) => this.setState({ radius: value / 20 }));
118+
(shadowRadius as Animated.Value).addListener(({ value }) => this.setState({ radius: Math.max(value / 6, 1) }));
119119
} else {
120120
this.setState({ radius });
121121
}
@@ -209,20 +209,20 @@ const styles = StyleSheet.create((o) => ({
209209
border: {
210210
width: o.state.width,
211211
height: o.state.height,
212+
transform: [{ scale: 0.7 }],
212213
backgroundColor: '#fff',
213-
transform: [{ scale: 0.2 }],
214214
...o.state.shadowStyle,
215215
},
216216
shadow: {
217217
position: 'absolute',
218218
width: o.state.width,
219219
height: o.state.height,
220220
opacity: o.state.opacity,
221-
marginTop: o.state.offset.top,
222-
marginLeft: o.state.offset.left,
221+
top: o.state.offset.top,
222+
left: o.state.offset.left,
223223
tintColor: o.state.color,
224224
zIndex: -1,
225-
transform: [{ scale: 5 }],
225+
transform: [{ scale: 1 / 0.7 }],
226226
pointerEvents: 'none',
227227
},
228228
}));

0 commit comments

Comments
 (0)