mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix: safeguards against invalid values
This commit is contained in:
committed by
Nathan Walker
parent
9f710411bf
commit
6f875b2eb7
@@ -733,15 +733,25 @@ function drawBoxShadow(nativeView: NativeView, view: View, boxShadow: CSSShadow,
|
|||||||
}
|
}
|
||||||
// shadow opacity is handled on the shadow's color instance
|
// shadow opacity is handled on the shadow's color instance
|
||||||
layer.shadowOpacity = boxShadow.color?.a ? boxShadow.color?.a / 255 : 1;
|
layer.shadowOpacity = boxShadow.color?.a ? boxShadow.color?.a / 255 : 1;
|
||||||
layer.shadowRadius = Length.toDevicePixels(boxShadow.blurRadius);
|
layer.shadowRadius = Length.toDevicePixels(boxShadow.blurRadius, 0.0);
|
||||||
layer.shadowColor = boxShadow.color.ios.CGColor;
|
layer.shadowColor = boxShadow.color.ios.CGColor;
|
||||||
layer.shadowOffset = CGSizeMake(Length.toDevicePixels(boxShadow.offsetX), Length.toDevicePixels(boxShadow.offsetY));
|
|
||||||
|
// prettier-ignore
|
||||||
|
layer.shadowOffset = CGSizeMake(
|
||||||
|
Length.toDevicePixels(boxShadow.offsetX, 0.0),
|
||||||
|
Length.toDevicePixels(boxShadow.offsetY, 0.0)
|
||||||
|
);
|
||||||
|
|
||||||
// this should match the view's border radius
|
// this should match the view's border radius
|
||||||
const cornerRadius = Length.toDevicePixels(<LengthType>view.style.borderRadius);
|
const cornerRadius = Length.toDevicePixels(<LengthType>view.style.borderRadius);
|
||||||
|
|
||||||
// apply spreadRadius by expanding shadow layer bounds
|
// apply spreadRadius by expanding shadow layer bounds
|
||||||
const bounds = boxShadow.spreadRadius ? CGRectInset(nativeView.bounds, -Length.toDevicePixels(boxShadow.spreadRadius), -Length.toDevicePixels(boxShadow.spreadRadius)) : nativeView.bounds;
|
// prettier-ignore
|
||||||
|
const bounds = boxShadow.spreadRadius ?
|
||||||
|
CGRectInset(nativeView.bounds,
|
||||||
|
-Length.toDevicePixels(boxShadow.spreadRadius),
|
||||||
|
-Length.toDevicePixels(boxShadow.spreadRadius)
|
||||||
|
) : nativeView.bounds;
|
||||||
|
|
||||||
// This has the nice glow with box shadow of 0,0
|
// This has the nice glow with box shadow of 0,0
|
||||||
layer.shadowPath = UIBezierPath.bezierPathWithRoundedRectCornerRadius(bounds, cornerRadius).CGPath;
|
layer.shadowPath = UIBezierPath.bezierPathWithRoundedRectCornerRadius(bounds, cornerRadius).CGPath;
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ const isLength = (v) => v === '0' || LENGTH_RE.test(v);
|
|||||||
* @param value
|
* @param value
|
||||||
*/
|
*/
|
||||||
export function parseCSSShadow(value: string): CSSShadow {
|
export function parseCSSShadow(value: string): CSSShadow {
|
||||||
const parts = value.split(PARTS_RE);
|
const parts = value.trim().split(PARTS_RE);
|
||||||
const inset = parts.includes('inset');
|
const inset = parts.includes('inset');
|
||||||
const first = parts[0];
|
const first = parts[0];
|
||||||
const last = parts[parts.length - 1];
|
const last = parts[parts.length - 1];
|
||||||
|
|||||||
Reference in New Issue
Block a user