Skip to content

Commit

Permalink
feat: implement spreadRadius
Browse files Browse the repository at this point in the history
  • Loading branch information
rigor789 authored and NathanWalker committed Apr 6, 2021
1 parent 7330509 commit fca3466
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/core/ui/styling/background.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { ImageSource } from '../../image-source';
import { CSSValue, parse as cssParse } from '../../css-value';
import { CSSShadow } from './css-shadow';
import { Length, LengthType } from './style-properties';
import { Properties } from '../animation/animation-common';
import height = Properties.height;

export * from './background-common';

Expand Down Expand Up @@ -732,16 +734,19 @@ function drawBoxShadow(nativeView: NativeView, view: View, boxShadow: CSSShadow,
layer.backgroundColor = UIColor.whiteColor.CGColor;
}
// shadow opacity is handled on the shadow's color instance
layer.shadowOpacity = background.color?.a ? background.color?.a / 255 : 1;
layer.shadowRadius = Length.toDevicePixels(boxShadow.spreadRadius);
layer.shadowOpacity = boxShadow.color?.a ? boxShadow.color?.a / 255 : 1;
layer.shadowRadius = Length.toDevicePixels(boxShadow.blurRadius);
layer.shadowColor = boxShadow.color.ios.CGColor;
layer.shadowOffset = CGSizeMake(Length.toDevicePixels(boxShadow.offsetX), Length.toDevicePixels(boxShadow.offsetY));

// this should match the view's border radius
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
layer.shadowPath = UIBezierPath.bezierPathWithRoundedRectCornerRadius(nativeView.bounds, cornerRadius).CGPath;
layer.shadowPath = UIBezierPath.bezierPathWithRoundedRectCornerRadius(bounds, cornerRadius).CGPath;
}

function clearBoxShadow(nativeView: NativeView) {
Expand Down

0 comments on commit fca3466

Please sign in to comment.