feat: implement spreadRadius

This commit is contained in:
Igor Randjelovic
2021-02-26 18:39:36 +01:00
committed by Nathan Walker
parent 733050995c
commit fca3466408

View File

@ -9,6 +9,8 @@ import { ImageSource } from '../../image-source';
import { CSSValue, parse as cssParse } from '../../css-value'; import { CSSValue, parse as cssParse } from '../../css-value';
import { CSSShadow } from './css-shadow'; import { CSSShadow } from './css-shadow';
import { Length, LengthType } from './style-properties'; import { Length, LengthType } from './style-properties';
import { Properties } from '../animation/animation-common';
import height = Properties.height;
export * from './background-common'; export * from './background-common';
@ -732,16 +734,19 @@ function drawBoxShadow(nativeView: NativeView, view: View, boxShadow: CSSShadow,
layer.backgroundColor = UIColor.whiteColor.CGColor; layer.backgroundColor = UIColor.whiteColor.CGColor;
} }
// shadow opacity is handled on the shadow's color instance // shadow opacity is handled on the shadow's color instance
layer.shadowOpacity = background.color?.a ? background.color?.a / 255 : 1; layer.shadowOpacity = boxShadow.color?.a ? boxShadow.color?.a / 255 : 1;
layer.shadowRadius = Length.toDevicePixels(boxShadow.spreadRadius); layer.shadowRadius = Length.toDevicePixels(boxShadow.blurRadius);
layer.shadowColor = boxShadow.color.ios.CGColor; layer.shadowColor = boxShadow.color.ios.CGColor;
layer.shadowOffset = CGSizeMake(Length.toDevicePixels(boxShadow.offsetX), Length.toDevicePixels(boxShadow.offsetY)); layer.shadowOffset = CGSizeMake(Length.toDevicePixels(boxShadow.offsetX), Length.toDevicePixels(boxShadow.offsetY));
// 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
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(nativeView.bounds, cornerRadius).CGPath; layer.shadowPath = UIBezierPath.bezierPathWithRoundedRectCornerRadius(bounds, cornerRadius).CGPath;
} }
function clearBoxShadow(nativeView: NativeView) { function clearBoxShadow(nativeView: NativeView) {