chore: cleanup

This commit is contained in:
Nathan Walker
2021-02-19 14:51:31 -08:00
parent 621c8302f2
commit 945656fe3e
9 changed files with 117 additions and 60 deletions

View File

@@ -7,7 +7,7 @@ import { Color } from '../../color';
import { isDataURI, isFileOrResourcePath, layout } from '../../utils';
import { ImageSource } from '../../image-source';
import { CSSValue, parse as cssParse } from '../../css-value';
import { BoxShadow } from './box-shadow';
import { CSSShadow } from './css-shadow';
export * from './background-common';
@@ -717,7 +717,7 @@ function drawNoRadiusNonUniformBorders(nativeView: NativeView, background: Backg
}
// TODO: use sublayer if its applied to a layout
function drawBoxShadow(nativeView: NativeView, view: View, boxShadow: BoxShadow, background: BackgroundDefinition, useSubLayer: boolean = false) {
function drawBoxShadow(nativeView: NativeView, view: View, boxShadow: CSSShadow, background: BackgroundDefinition, useSubLayer: boolean = false) {
const layer: CALayer = nativeView.layer;
layer.masksToBounds = false;

View File

@@ -1,6 +1,6 @@
import { Color } from '../../color';
export class BoxShadow {
export class CSSShadow {
public offsetX: number;
public offsetY: number;
public blurRadius: number;

View File

@@ -17,7 +17,7 @@ import { Trace } from '../../trace';
import * as parser from '../../css/parser';
import { LinearGradient } from './linear-gradient';
import { BoxShadow } from './box-shadow';
import { CSSShadow } from './css-shadow';
export type LengthDipUnit = { readonly unit: 'dip'; readonly value: dip };
export type LengthPxUnit = { readonly unit: 'px'; readonly value: px };
@@ -452,10 +452,10 @@ export const verticalAlignmentProperty = new CssProperty<Style, VerticalAlignmen
});
verticalAlignmentProperty.register(Style);
function parseBoxShadowProperites(value: string): BoxShadow {
export function parseShadowProperites(value: string): CSSShadow {
if (typeof value === 'string') {
let arr;
let colorRaw;
let colorRaw = 'black';
if (value.indexOf('rgb') > -1) {
arr = value.split(' ');
colorRaw = arr.pop();
@@ -464,27 +464,29 @@ function parseBoxShadowProperites(value: string): BoxShadow {
colorRaw = arr.pop();
}
let offsetX: number;
let offsetY: number;
let blurRadius: number; // not currently in use
let spreadRadius: number; // maybe rename this to just radius
let offsetX = 0;
let offsetY = 0;
let blurRadius = 0; // not currently in use
let spreadRadius = 0; // maybe rename this to just radius
let color: Color = new Color(colorRaw);
if (arr.length === 2) {
offsetX = parseFloat(arr[0]);
offsetY = parseFloat(arr[1]);
} else if (arr.length === 3) {
offsetX = parseFloat(arr[0]);
offsetY = parseFloat(arr[1]);
blurRadius = parseFloat(arr[2]);
} else if (arr.length === 4) {
offsetX = parseFloat(arr[0]);
offsetY = parseFloat(arr[1]);
blurRadius = parseFloat(arr[2]);
spreadRadius = parseFloat(arr[3]);
} else {
throw new Error('Expected 3, 4 or 5 parameters. Actual: ' + value);
if (arr.length === 1) {
Trace.write('Expected 3, 4 or 5 parameters. Actual: ' + value, Trace.categories.Error, Trace.messageType.error);
}
if (arr.length > 1) {
offsetX = parseFloat(arr[0]);
offsetY = parseFloat(arr[1]);
}
if (arr.length > 2) {
blurRadius = parseFloat(arr[2]);
}
if (arr.length > 3) {
spreadRadius = parseFloat(arr[3]);
}
return {
offsetX: offsetX,
offsetY: offsetY,
@@ -1321,14 +1323,14 @@ export const borderBottomLeftRadiusProperty = new CssProperty<Style, Length>({
});
borderBottomLeftRadiusProperty.register(Style);
const boxShadowProperty = new CssProperty<Style, BoxShadow>({
const boxShadowProperty = new CssProperty<Style, CSSShadow>({
name: 'boxShadow',
cssName: 'box-shadow',
valueChanged: (target, oldValue, newValue) => {
target.boxShadow = newValue;
},
valueConverter: (value) => {
return parseBoxShadowProperites(value);
return parseShadowProperites(value);
},
});
boxShadowProperty.register(Style);

View File

@@ -12,7 +12,7 @@ import { FlexDirection, FlexWrap, JustifyContent, AlignItems, AlignContent, Orde
import { Trace } from '../../../trace';
import { TextAlignment, TextDecoration, TextTransform, WhiteSpace, TextShadow } from '../../text-base';
import { AccessibilityLiveRegion, AccessibilityRole, AccessibilityState } from '../../../accessibility/accessibility-types';
import { BoxShadow } from '../box-shadow';
import { CSSShadow } from '../css-shadow';
export interface CommonLayoutParams {
width: number;
@@ -140,7 +140,7 @@ export class Style extends Observable implements StyleDefinition {
public borderBottomRightRadius: Length;
public borderBottomLeftRadius: Length;
public boxShadow: BoxShadow;
public boxShadow: CSSShadow;
public fontSize: number;
public fontFamily: string;