Repository navigation
Expand file tree
/
Copy pathutils.ios.ts
More file actions
90 lines (71 loc) · 2.64 KB
/
Copy pathutils.ios.ts
File metadata and controls
90 lines (71 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { Screen } from '../platform';
import * as utils from '../utils';
import { LinearGradient } from './styling/linear-gradient';
interface NativeScriptUIView extends UIView {
hasNonUniformBorder: boolean;
hasNonUniformBorderColor: boolean;
borderLayer: CAShapeLayer;
maskType: ios.LayerMaskType;
originalMask: CALayer;
gradientLayer: CAGradientLayer;
outerShadowContainerLayer: CALayer;
}
export namespace ios {
export type LayerMaskType = 'BORDER' | 'CLIP_PATH';
export namespace LayerMask {
export const BORDER = 'BORDER';
export const CLIP_PATH = 'CLIP_PATH';
}
export function getActualHeight(view: UIView): number {
if (view.window && !view.hidden) {
return utils.layout.toDevicePixels(view.frame.size.height);
}
return 0;
}
export function getStatusBarHeight(viewController?: UIViewController): number {
const app = UIApplication.sharedApplication;
if (!app || app.statusBarHidden) {
return 0;
}
if (viewController && viewController.prefersStatusBarHidden) {
return 0;
}
const statusFrame = app.statusBarFrame;
const min = Math.min(statusFrame.size.width, statusFrame.size.height);
return utils.layout.toDevicePixels(min);
}
export function drawGradient(nativeView: NativeScriptUIView, gradientLayer: CAGradientLayer, gradient: LinearGradient, gradientLayerOpacity?: number): void {
if (!nativeView || !gradient) {
return;
}
if (typeof gradientLayerOpacity === 'number') {
gradientLayer.opacity = gradientLayerOpacity;
}
// Update these properties instead of layer frame as the latter messes with animations
gradientLayer.bounds = nativeView.bounds;
gradientLayer.anchorPoint = CGPointMake(0, 0);
gradientLayer.allowsEdgeAntialiasing = true;
gradientLayer.contentsScale = Screen.mainScreen.scale;
const iosColors = NSMutableArray.alloc().initWithCapacity(gradient.colorStops.length);
const iosStops = NSMutableArray.alloc<number>().initWithCapacity(gradient.colorStops.length);
let hasStops = false;
gradient.colorStops.forEach((stop) => {
iosColors.addObject(stop.color.ios.CGColor);
if (stop.offset) {
iosStops.addObject(stop.offset.value);
hasStops = true;
}
});
gradientLayer.colors = iosColors;
if (hasStops) {
gradientLayer.locations = iosStops;
}
const alpha = gradient.angle / (Math.PI * 2);
const startX = Math.pow(Math.sin(Math.PI * (alpha + 0.75)), 2);
const startY = Math.pow(Math.sin(Math.PI * (alpha + 0.5)), 2);
const endX = Math.pow(Math.sin(Math.PI * (alpha + 0.25)), 2);
const endY = Math.pow(Math.sin(Math.PI * alpha), 2);
gradientLayer.startPoint = { x: startX, y: startY };
gradientLayer.endPoint = { x: endX, y: endY };
}
}