MCPcopy Create free account
hub / github.com/NativeScript/NativeScript / fromGradient

Function fromGradient

packages/core/ui/styling/background.android.ts:15–34  ·  view source on GitHub ↗
(gradient: LinearGradient)

Source from the content-addressed store, hash-verified

13}
14
15function fromGradient(gradient: LinearGradient): org.nativescript.widgets.LinearGradientDefinition {
16 const colors = Array.create('int', gradient.colorStops.length);
17 const stops = Array.create('float', gradient.colorStops.length);
18 let hasStops = false;
19 gradient.colorStops.forEach((stop, index) => {
20 colors[index] = stop.color.android;
21 if (stop.offset) {
22 stops[index] = stop.offset.value;
23 hasStops = true;
24 }
25 });
26
27 const alpha = gradient.angle / (Math.PI * 2);
28 const startX = Math.pow(Math.sin(Math.PI * (alpha + 0.75)), 2);
29 const startY = Math.pow(Math.sin(Math.PI * (alpha + 0.5)), 2);
30 const endX = Math.pow(Math.sin(Math.PI * (alpha + 0.25)), 2);
31 const endY = Math.pow(Math.sin(Math.PI * alpha), 2);
32
33 return new org.nativescript.widgets.LinearGradientDefinition(startX, startY, endX, endY, colors, hasStops ? stops : null);
34}
35
36const pattern = /url\(('|")(.*?)\1\)/;
37export function refreshBorderDrawable(view: View, borderDrawable: org.nativescript.widgets.BorderDrawable) {

Callers 1

refreshBorderDrawableFunction · 0.85

Calls 2

forEachMethod · 0.80
createMethod · 0.65

Tested by

no test coverage detected