chore: cleanup

This commit is contained in:
Nathan Walker
2021-02-19 22:48:51 -08:00
parent 207edb94f4
commit 3e001ff9e7
2 changed files with 12 additions and 10 deletions

View File

@@ -4,7 +4,7 @@ import { BackgroundRepeat } from '../styling/style-properties';
import { LinearGradient } from './linear-gradient';
// Types.
import { Color } from '../../color';
import { BoxShadow } from './box-shadow';
import { CSSShadow } from './css-shadow';
export class Background implements BackgroundDefinition {
public static default = new Background();
@@ -27,7 +27,7 @@ export class Background implements BackgroundDefinition {
public borderBottomLeftRadius = 0;
public borderBottomRightRadius = 0;
public clipPath: string;
public boxShadow: BoxShadow;
public boxShadow: CSSShadow;
private clone(): Background {
const clone = new Background();
@@ -181,7 +181,7 @@ export class Background implements BackgroundDefinition {
return clone;
}
public withBoxShadow(value: BoxShadow): Background {
public withBoxShadow(value: CSSShadow): Background {
const clone = this.clone();
clone.boxShadow = value;
@@ -288,7 +288,7 @@ export class Background implements BackgroundDefinition {
return !!this.boxShadow;
}
public getBoxShadow(): BoxShadow {
public getBoxShadow(): CSSShadow {
return this.boxShadow;
}

View File

@@ -8,6 +8,7 @@ import { isDataURI, isFileOrResourcePath, layout } from '../../utils';
import { ImageSource } from '../../image-source';
import { CSSValue, parse as cssParse } from '../../css-value';
import { CSSShadow } from './css-shadow';
import { Length } from './style-properties';
export * from './background-common';
@@ -717,12 +718,13 @@ function drawNoRadiusNonUniformBorders(nativeView: NativeView, background: Backg
// TODO: use sublayer if its applied to a layout
function drawBoxShadow(nativeView: NativeView, view: View, boxShadow: CSSShadow, background: BackgroundDefinition, useSubLayer: boolean = false) {
// TODO: fine named 'shadow-layer' first and otherwise need to search through sublayers (need logic used in text-shadow for layer - see getShadowLayer)
const layer: CALayer = nativeView.layer;
layer.masksToBounds = false;
nativeView.clipsToBounds = false;
// this is required (if not, shadow will get cutoff at parent's dimensions)
// this is required (if not, shadow will get cutoff at parent's dimensions)
// nativeView.clipsToBounds doesn't work
view.setProperty('clipToBounds', false);
@@ -731,13 +733,13 @@ 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 = 1;
layer.shadowRadius = layout.toDeviceIndependentPixels(boxShadow.spreadRadius);
layer.shadowOpacity = background.color?.a ? background.color?.a / 255 : 1;
layer.shadowRadius = Length.toDevicePixels(boxShadow.spreadRadius);
layer.shadowColor = boxShadow.color.ios.CGColor;
const adjustedShadowOffset = {
x: layout.toDeviceIndependentPixels(boxShadow.offsetX),
y: layout.toDeviceIndependentPixels(boxShadow.offsetY),
x: Length.toDevicePixels(boxShadow.offsetX),
y: Length.toDevicePixels(boxShadow.offsetY),
};
layer.shadowOffset = CGSizeMake(adjustedShadowOffset.x, adjustedShadowOffset.y);