chore: cleanup

This commit is contained in:
Nathan Walker
2021-02-25 20:03:49 -08:00
parent dee6bde170
commit 784e9c93cd
6 changed files with 198 additions and 209 deletions

View File

@@ -4,7 +4,7 @@ import { Background as BackgroundDefinition } from './background';
import { View, Point } from '../core/view';
import { LinearGradient } from './linear-gradient';
import { Color } from '../../color';
import { isDataURI, isFileOrResourcePath, layout } from '../../utils';
import { iOSNativeHelper, isDataURI, isFileOrResourcePath, layout } from '../../utils';
import { ImageSource } from '../../image-source';
import { CSSValue, parse as cssParse } from '../../css-value';
import { CSSShadow } from './css-shadow';
@@ -718,8 +718,7 @@ 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;
const layer: CALayer = iOSNativeHelper.getShadowLayer(nativeView, 'ns-box-shadow');
layer.masksToBounds = false;
nativeView.clipsToBounds = false;
@@ -752,7 +751,7 @@ function drawBoxShadow(nativeView: NativeView, view: View, boxShadow: CSSShadow,
function clearBoxShadow(nativeView: NativeView) {
nativeView.clipsToBounds = true;
const layer: CALayer = nativeView.layer;
const layer: CALayer = iOSNativeHelper.getShadowLayer(nativeView, 'ns-box-shadow');
layer.masksToBounds = true;
layer.shadowOffset = CGSizeMake(0, 0);
layer.shadowColor = UIColor.clearColor.CGColor;

View File

@@ -802,8 +802,7 @@ export const backgroundImageProperty = new CssProperty<Style, string | LinearGra
name: 'backgroundImage',
cssName: 'background-image',
valueChanged: (target, oldValue, newValue) => {
const background = target.backgroundInternal.withImage(newValue);
target.backgroundInternal = background;
target.backgroundInternal = target.backgroundInternal.withImage(newValue);
},
equalityComparer: (value1, value2) => {
if (value1 instanceof LinearGradient && value2 instanceof LinearGradient) {
@@ -816,8 +815,7 @@ export const backgroundImageProperty = new CssProperty<Style, string | LinearGra
if (typeof value === 'string') {
const parsed = parser.parseBackground(value);
if (parsed) {
const background = parsed.value;
value = typeof background.image === 'object' ? LinearGradient.parse(background.image) : value;
value = typeof parsed.value.image === 'object' ? LinearGradient.parse(parsed.value.image) : value;
}
}
@@ -830,8 +828,7 @@ export const backgroundColorProperty = new CssAnimationProperty<Style, Color>({
name: 'backgroundColor',
cssName: 'background-color',
valueChanged: (target, oldValue, newValue) => {
const background = target.backgroundInternal.withColor(newValue);
target.backgroundInternal = background;
target.backgroundInternal = target.backgroundInternal.withColor(newValue);
},
equalityComparer: Color.equals,
valueConverter: (value) => new Color(value),
@@ -853,8 +850,7 @@ export const backgroundRepeatProperty = new CssProperty<Style, BackgroundRepeat>
cssName: 'background-repeat',
valueConverter: BackgroundRepeat.parse,
valueChanged: (target, oldValue, newValue) => {
const background = target.backgroundInternal.withRepeat(newValue);
target.backgroundInternal = background;
target.backgroundInternal = target.backgroundInternal.withRepeat(newValue);
},
});
backgroundRepeatProperty.register(Style);
@@ -863,8 +859,7 @@ export const backgroundSizeProperty = new CssProperty<Style, string>({
name: 'backgroundSize',
cssName: 'background-size',
valueChanged: (target, oldValue, newValue) => {
const background = target.backgroundInternal.withSize(newValue);
target.backgroundInternal = background;
target.backgroundInternal = target.backgroundInternal.withSize(newValue);
},
});
backgroundSizeProperty.register(Style);
@@ -873,8 +868,7 @@ export const backgroundPositionProperty = new CssProperty<Style, string>({
name: 'backgroundPosition',
cssName: 'background-position',
valueChanged: (target, oldValue, newValue) => {
const background = target.backgroundInternal.withPosition(newValue);
target.backgroundInternal = background;
target.backgroundInternal = target.backgroundInternal.withPosition(newValue);
},
});
backgroundPositionProperty.register(Style);
@@ -998,8 +992,7 @@ export const borderTopColorProperty = new CssProperty<Style, Color>({
name: 'borderTopColor',
cssName: 'border-top-color',
valueChanged: (target, oldValue, newValue) => {
const background = target.backgroundInternal.withBorderTopColor(newValue);
target.backgroundInternal = background;
target.backgroundInternal = target.backgroundInternal.withBorderTopColor(newValue);
},
equalityComparer: Color.equals,
valueConverter: (value) => new Color(value),
@@ -1010,8 +1003,7 @@ export const borderRightColorProperty = new CssProperty<Style, Color>({
name: 'borderRightColor',
cssName: 'border-right-color',
valueChanged: (target, oldValue, newValue) => {
const background = target.backgroundInternal.withBorderRightColor(newValue);
target.backgroundInternal = background;
target.backgroundInternal = target.backgroundInternal.withBorderRightColor(newValue);
},
equalityComparer: Color.equals,
valueConverter: (value) => new Color(value),
@@ -1022,8 +1014,7 @@ export const borderBottomColorProperty = new CssProperty<Style, Color>({
name: 'borderBottomColor',
cssName: 'border-bottom-color',
valueChanged: (target, oldValue, newValue) => {
const background = target.backgroundInternal.withBorderBottomColor(newValue);
target.backgroundInternal = background;
target.backgroundInternal = target.backgroundInternal.withBorderBottomColor(newValue);
},
equalityComparer: Color.equals,
valueConverter: (value) => new Color(value),
@@ -1034,8 +1025,7 @@ export const borderLeftColorProperty = new CssProperty<Style, Color>({
name: 'borderLeftColor',
cssName: 'border-left-color',
valueChanged: (target, oldValue, newValue) => {
const background = target.backgroundInternal.withBorderLeftColor(newValue);
target.backgroundInternal = background;
target.backgroundInternal = target.backgroundInternal.withBorderLeftColor(newValue);
},
equalityComparer: Color.equals,
valueConverter: (value) => new Color(value),
@@ -1093,8 +1083,7 @@ export const borderTopWidthProperty = new CssProperty<Style, Length>({
} else {
Trace.write(`${newValue} not set to view's property because ".viewRef" is cleared`, Trace.categories.Style, Trace.messageType.warn);
}
const background = target.backgroundInternal.withBorderTopWidth(value);
target.backgroundInternal = background;
target.backgroundInternal = target.backgroundInternal.withBorderTopWidth(value);
},
valueConverter: Length.parse,
});
@@ -1118,8 +1107,7 @@ export const borderRightWidthProperty = new CssProperty<Style, Length>({
} else {
Trace.write(`${newValue} not set to view's property because ".viewRef" is cleared`, Trace.categories.Style, Trace.messageType.warn);
}
const background = target.backgroundInternal.withBorderRightWidth(value);
target.backgroundInternal = background;
target.backgroundInternal = target.backgroundInternal.withBorderRightWidth(value);
},
valueConverter: Length.parse,
});
@@ -1143,8 +1131,7 @@ export const borderBottomWidthProperty = new CssProperty<Style, Length>({
} else {
Trace.write(`${newValue} not set to view's property because ".viewRef" is cleared`, Trace.categories.Style, Trace.messageType.warn);
}
const background = target.backgroundInternal.withBorderBottomWidth(value);
target.backgroundInternal = background;
target.backgroundInternal = target.backgroundInternal.withBorderBottomWidth(value);
},
valueConverter: Length.parse,
});
@@ -1168,8 +1155,7 @@ export const borderLeftWidthProperty = new CssProperty<Style, Length>({
} else {
Trace.write(`${newValue} not set to view's property because ".viewRef" is cleared`, Trace.categories.Style, Trace.messageType.warn);
}
const background = target.backgroundInternal.withBorderLeftWidth(value);
target.backgroundInternal = background;
target.backgroundInternal = target.backgroundInternal.withBorderLeftWidth(value);
},
valueConverter: Length.parse,
});
@@ -1218,8 +1204,7 @@ export const borderTopLeftRadiusProperty = new CssProperty<Style, Length>({
if (!isNonNegativeFiniteNumber(value)) {
throw new Error(`border-top-left-radius should be Non-Negative Finite number. Value: ${value}`);
}
const background = target.backgroundInternal.withBorderTopLeftRadius(value);
target.backgroundInternal = background;
target.backgroundInternal = target.backgroundInternal.withBorderTopLeftRadius(value);
},
valueConverter: Length.parse,
});
@@ -1235,8 +1220,7 @@ export const borderTopRightRadiusProperty = new CssProperty<Style, Length>({
if (!isNonNegativeFiniteNumber(value)) {
throw new Error(`border-top-right-radius should be Non-Negative Finite number. Value: ${value}`);
}
const background = target.backgroundInternal.withBorderTopRightRadius(value);
target.backgroundInternal = background;
target.backgroundInternal = target.backgroundInternal.withBorderTopRightRadius(value);
},
valueConverter: Length.parse,
});
@@ -1252,8 +1236,7 @@ export const borderBottomRightRadiusProperty = new CssProperty<Style, Length>({
if (!isNonNegativeFiniteNumber(value)) {
throw new Error(`border-bottom-right-radius should be Non-Negative Finite number. Value: ${value}`);
}
const background = target.backgroundInternal.withBorderBottomRightRadius(value);
target.backgroundInternal = background;
target.backgroundInternal = target.backgroundInternal.withBorderBottomRightRadius(value);
},
valueConverter: Length.parse,
});
@@ -1269,8 +1252,7 @@ export const borderBottomLeftRadiusProperty = new CssProperty<Style, Length>({
if (!isNonNegativeFiniteNumber(value)) {
throw new Error(`border-bottom-left-radius should be Non-Negative Finite number. Value: ${value}`);
}
const background = target.backgroundInternal.withBorderBottomLeftRadius(value);
target.backgroundInternal = background;
target.backgroundInternal = target.backgroundInternal.withBorderBottomLeftRadius(value);
},
valueConverter: Length.parse,
});
@@ -1280,8 +1262,7 @@ const boxShadowProperty = new CssProperty<Style, CSSShadow>({
name: 'boxShadow',
cssName: 'box-shadow',
valueChanged: (target, oldValue, newValue) => {
const background = target.backgroundInternal.withBoxShadow(newValue);
target.backgroundInternal = background;
target.backgroundInternal = target.backgroundInternal.withBoxShadow(newValue);
},
valueConverter: (value) => {
return parseCSSShadow(value);
@@ -1311,8 +1292,7 @@ export const clipPathProperty = new CssProperty<Style, string>({
throw new Error('clip-path is not valid.');
}
const background = target.backgroundInternal.withClipPath(newValue);
target.backgroundInternal = background;
target.backgroundInternal = target.backgroundInternal.withClipPath(newValue);
},
});
clipPathProperty.register(Style);