UNPKG

2.77 kBJavaScriptView Raw
1import { Screen } from '../platform';
2import * as utils from '../utils';
3export var ios;
4(function (ios) {
5 let LayerMask;
6 (function (LayerMask) {
7 LayerMask.BORDER = 'BORDER';
8 LayerMask.CLIP_PATH = 'CLIP_PATH';
9 })(LayerMask = ios.LayerMask || (ios.LayerMask = {}));
10 function getActualHeight(view) {
11 if (view.window && !view.hidden) {
12 return utils.layout.toDevicePixels(view.frame.size.height);
13 }
14 return 0;
15 }
16 ios.getActualHeight = getActualHeight;
17 function getStatusBarHeight(viewController) {
18 const app = UIApplication.sharedApplication;
19 if (!app || app.statusBarHidden) {
20 return 0;
21 }
22 if (viewController && viewController.prefersStatusBarHidden) {
23 return 0;
24 }
25 const statusFrame = app.statusBarFrame;
26 const min = Math.min(statusFrame.size.width, statusFrame.size.height);
27 return utils.layout.toDevicePixels(min);
28 }
29 ios.getStatusBarHeight = getStatusBarHeight;
30 function drawGradient(nativeView, gradientLayer, gradient, gradientLayerOpacity) {
31 if (!nativeView || !gradient) {
32 return;
33 }
34 if (typeof gradientLayerOpacity === 'number') {
35 gradientLayer.opacity = gradientLayerOpacity;
36 }
37 // Update these properties instead of layer frame as the latter messes with animations
38 gradientLayer.bounds = nativeView.bounds;
39 gradientLayer.anchorPoint = CGPointMake(0, 0);
40 gradientLayer.allowsEdgeAntialiasing = true;
41 gradientLayer.contentsScale = Screen.mainScreen.scale;
42 const iosColors = NSMutableArray.alloc().initWithCapacity(gradient.colorStops.length);
43 const iosStops = NSMutableArray.alloc().initWithCapacity(gradient.colorStops.length);
44 let hasStops = false;
45 gradient.colorStops.forEach((stop) => {
46 iosColors.addObject(stop.color.ios.CGColor);
47 if (stop.offset) {
48 iosStops.addObject(stop.offset.value);
49 hasStops = true;
50 }
51 });
52 gradientLayer.colors = iosColors;
53 if (hasStops) {
54 gradientLayer.locations = iosStops;
55 }
56 const alpha = gradient.angle / (Math.PI * 2);
57 const startX = Math.pow(Math.sin(Math.PI * (alpha + 0.75)), 2);
58 const startY = Math.pow(Math.sin(Math.PI * (alpha + 0.5)), 2);
59 const endX = Math.pow(Math.sin(Math.PI * (alpha + 0.25)), 2);
60 const endY = Math.pow(Math.sin(Math.PI * alpha), 2);
61 gradientLayer.startPoint = { x: startX, y: startY };
62 gradientLayer.endPoint = { x: endX, y: endY };
63 }
64 ios.drawGradient = drawGradient;
65})(ios || (ios = {}));
66//# sourceMappingURL=utils.ios.js.map
\No newline at end of file