@tamagui/linear-gradient 1.114.4 → 1.115.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/LinearGradient.cjs +69 -0
- package/dist/cjs/index.cjs +18 -0
- package/dist/cjs/linear-gradient.cjs +105 -0
- package/dist/cjs/linear-gradient.native.cjs +26 -0
- package/dist/cjs/linear-gradient.native.cjs.map +6 -0
- package/package.json +6 -5
- package/dist/cjs/LinearGradient.js +0 -57
- package/dist/cjs/index.js +0 -15
- package/dist/cjs/linear-gradient.js +0 -99
- /package/dist/cjs/{LinearGradient.js.map → LinearGradient.cjs.map} +0 -0
- /package/dist/cjs/{index.js.map → index.cjs.map} +0 -0
- /package/dist/cjs/{linear-gradient.js.map → linear-gradient.cjs.map} +0 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
21
|
+
var LinearGradient_exports = {};
|
|
22
|
+
__export(LinearGradient_exports, {
|
|
23
|
+
LinearGradient: () => LinearGradient
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(LinearGradient_exports);
|
|
26
|
+
var import_core = require("@tamagui/core"),
|
|
27
|
+
import_stacks = require("@tamagui/stacks"),
|
|
28
|
+
import_linear_gradient = require("./linear-gradient.cjs"),
|
|
29
|
+
import_jsx_runtime = require("react/jsx-runtime");
|
|
30
|
+
const LinearGradientFrame = (0, import_core.styled)(import_stacks.YStack, {
|
|
31
|
+
name: "LinearGradient",
|
|
32
|
+
overflow: "hidden",
|
|
33
|
+
position: "relative"
|
|
34
|
+
}),
|
|
35
|
+
LinearGradient = LinearGradientFrame.styleable((propsIn, ref) => {
|
|
36
|
+
const props = (0, import_core.useProps)(propsIn),
|
|
37
|
+
{
|
|
38
|
+
start,
|
|
39
|
+
end,
|
|
40
|
+
colors: colorsProp,
|
|
41
|
+
locations,
|
|
42
|
+
children,
|
|
43
|
+
...stackProps
|
|
44
|
+
} = props,
|
|
45
|
+
theme = (0, import_core.useTheme)();
|
|
46
|
+
let colors = props.colors?.map(c => theme[c]?.get("web") ?? c) || [];
|
|
47
|
+
return process.env.NODE_ENV !== "production" && colors.some(c => {
|
|
48
|
+
const normalized = (0, import_core.normalizeColor)(c);
|
|
49
|
+
if (!normalized || normalized.startsWith("$")) return !0;
|
|
50
|
+
}) && (console.error(`LinearGradient: "colors" prop contains invalid color tokens: ${colors} fallback to default colors: ["#000", "#fff"]`), colors = ["#000", "#fff"]), /* @__PURE__ */(0, import_jsx_runtime.jsxs)(LinearGradientFrame, {
|
|
51
|
+
ref,
|
|
52
|
+
...stackProps,
|
|
53
|
+
children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_linear_gradient.LinearGradient, {
|
|
54
|
+
start,
|
|
55
|
+
end,
|
|
56
|
+
colors,
|
|
57
|
+
locations,
|
|
58
|
+
style: gradientStyle
|
|
59
|
+
}), children]
|
|
60
|
+
});
|
|
61
|
+
}),
|
|
62
|
+
gradientStyle = {
|
|
63
|
+
position: "absolute",
|
|
64
|
+
top: 0,
|
|
65
|
+
left: 0,
|
|
66
|
+
right: 0,
|
|
67
|
+
bottom: 0,
|
|
68
|
+
zIndex: 0
|
|
69
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
7
|
+
get: () => from[key],
|
|
8
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
9
|
+
});
|
|
10
|
+
return to;
|
|
11
|
+
},
|
|
12
|
+
__reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
13
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
14
|
+
value: !0
|
|
15
|
+
}), mod);
|
|
16
|
+
var src_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(src_exports);
|
|
18
|
+
__reExport(src_exports, require("./LinearGradient.cjs"), module.exports);
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: !0
|
|
28
|
+
}) : target, mod)),
|
|
29
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
+
value: !0
|
|
31
|
+
}), mod);
|
|
32
|
+
var linear_gradient_exports = {};
|
|
33
|
+
__export(linear_gradient_exports, {
|
|
34
|
+
LinearGradient: () => LinearGradient
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(linear_gradient_exports);
|
|
37
|
+
var import_core = require("@tamagui/core"),
|
|
38
|
+
React = __toESM(require("react")),
|
|
39
|
+
import_react_native = require("react-native-web"),
|
|
40
|
+
import_jsx_runtime = require("react/jsx-runtime");
|
|
41
|
+
function LinearGradient({
|
|
42
|
+
colors,
|
|
43
|
+
locations,
|
|
44
|
+
start,
|
|
45
|
+
end,
|
|
46
|
+
...props
|
|
47
|
+
}) {
|
|
48
|
+
const [{
|
|
49
|
+
height,
|
|
50
|
+
width
|
|
51
|
+
}, setLayout] = React.useState({
|
|
52
|
+
height: 1,
|
|
53
|
+
width: 1
|
|
54
|
+
}),
|
|
55
|
+
linearGradientBackgroundImage = React.useMemo(() => getLinearGradientBackgroundImage(
|
|
56
|
+
// @ts-expect-error ok
|
|
57
|
+
colors, locations, start, end, width, height), [colors, locations, start, end, width, height]);
|
|
58
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react_native.View, {
|
|
59
|
+
...props,
|
|
60
|
+
style: [props.style,
|
|
61
|
+
// @ts-ignore: [ts] Property 'backgroundImage' does not exist on type 'ViewStyle'.
|
|
62
|
+
{
|
|
63
|
+
backgroundImage: linearGradientBackgroundImage
|
|
64
|
+
}],
|
|
65
|
+
onLayout: event => {
|
|
66
|
+
const {
|
|
67
|
+
width: width2,
|
|
68
|
+
height: height2
|
|
69
|
+
} = event.nativeEvent.layout;
|
|
70
|
+
setLayout(oldLayout => width2 !== oldLayout.width || height2 !== oldLayout.height ? {
|
|
71
|
+
height: height2,
|
|
72
|
+
width: width2
|
|
73
|
+
} : oldLayout), props.onLayout && props.onLayout(event);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function getLinearGradientBackgroundImage(colors, locations, startPoint, endPoint, width = 1, height = 1) {
|
|
78
|
+
const gradientColors = calculateGradientColors(
|
|
79
|
+
// @ts-expect-error TODO fix numbers
|
|
80
|
+
colors, locations);
|
|
81
|
+
return `linear-gradient(${calculatePseudoAngle(width, height, startPoint, endPoint)}deg, ${gradientColors.join(", ")})`;
|
|
82
|
+
}
|
|
83
|
+
function calculatePseudoAngle(width, height, startPoint, endPoint) {
|
|
84
|
+
const getControlPoints = () => {
|
|
85
|
+
let correctedStartPoint = [0, 0];
|
|
86
|
+
Array.isArray(startPoint) && (correctedStartPoint = [startPoint[0] != null ? startPoint[0] : 0, startPoint[1] != null ? startPoint[1] : 0]);
|
|
87
|
+
let correctedEndPoint = [0, 1];
|
|
88
|
+
return Array.isArray(endPoint) && (correctedEndPoint = [endPoint[0] != null ? endPoint[0] : 0, endPoint[1] != null ? endPoint[1] : 1]), [correctedStartPoint, correctedEndPoint];
|
|
89
|
+
},
|
|
90
|
+
[start, end] = getControlPoints();
|
|
91
|
+
start[0] *= width, end[0] *= width, start[1] *= height, end[1] *= height;
|
|
92
|
+
const py = end[1] - start[1],
|
|
93
|
+
px = end[0] - start[0];
|
|
94
|
+
return 90 + Math.atan2(py, px) * 180 / Math.PI;
|
|
95
|
+
}
|
|
96
|
+
function calculateGradientColors(colors, locations) {
|
|
97
|
+
return colors.map((color, index) => {
|
|
98
|
+
const output = (0, import_core.normalizeColor)(color);
|
|
99
|
+
if (locations && locations[index]) {
|
|
100
|
+
const percentage = Math.max(0, Math.min(1, locations[index])) * 100;
|
|
101
|
+
return `${output} ${percentage}%`;
|
|
102
|
+
}
|
|
103
|
+
return output;
|
|
104
|
+
});
|
|
105
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
21
|
+
var linear_gradient_native_exports = {};
|
|
22
|
+
__export(linear_gradient_native_exports, {
|
|
23
|
+
LinearGradient: () => import_expo_linear_gradient.LinearGradient
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(linear_gradient_native_exports);
|
|
26
|
+
var import_expo_linear_gradient = require("expo-linear-gradient");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/linear-gradient",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.115.1",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"*.css"
|
|
6
6
|
],
|
|
@@ -29,15 +29,16 @@
|
|
|
29
29
|
"react-native": "./dist/cjs/index.native.js",
|
|
30
30
|
"types": "./types/index.d.ts",
|
|
31
31
|
"import": "./dist/esm/index.mjs",
|
|
32
|
-
"require": "./dist/cjs/index.
|
|
32
|
+
"require": "./dist/cjs/index.cjs",
|
|
33
|
+
"default": "./dist/cjs/index.native.js"
|
|
33
34
|
}
|
|
34
35
|
},
|
|
35
36
|
"dependencies": {
|
|
36
|
-
"@tamagui/core": "1.
|
|
37
|
-
"@tamagui/stacks": "1.
|
|
37
|
+
"@tamagui/core": "1.115.1",
|
|
38
|
+
"@tamagui/stacks": "1.115.1"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
|
-
"@tamagui/build": "1.
|
|
41
|
+
"@tamagui/build": "1.115.1",
|
|
41
42
|
"expo-linear-gradient": "~13.0.2",
|
|
42
43
|
"react": "^18.2.0 || ^19.0.0"
|
|
43
44
|
},
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
8
|
-
}, __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
10
|
-
for (let key of __getOwnPropNames(from))
|
|
11
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
15
|
-
var LinearGradient_exports = {};
|
|
16
|
-
__export(LinearGradient_exports, {
|
|
17
|
-
LinearGradient: () => LinearGradient
|
|
18
|
-
});
|
|
19
|
-
module.exports = __toCommonJS(LinearGradient_exports);
|
|
20
|
-
var import_core = require("@tamagui/core"), import_stacks = require("@tamagui/stacks"), import_linear_gradient = require("./linear-gradient"), import_jsx_runtime = require("react/jsx-runtime");
|
|
21
|
-
const LinearGradientFrame = (0, import_core.styled)(import_stacks.YStack, {
|
|
22
|
-
name: "LinearGradient",
|
|
23
|
-
overflow: "hidden",
|
|
24
|
-
position: "relative"
|
|
25
|
-
}), LinearGradient = LinearGradientFrame.styleable(
|
|
26
|
-
(propsIn, ref) => {
|
|
27
|
-
const props = (0, import_core.useProps)(propsIn), { start, end, colors: colorsProp, locations, children, ...stackProps } = props, theme = (0, import_core.useTheme)();
|
|
28
|
-
let colors = props.colors?.map((c) => theme[c]?.get("web") ?? c) || [];
|
|
29
|
-
return process.env.NODE_ENV !== "production" && colors.some((c) => {
|
|
30
|
-
const normalized = (0, import_core.normalizeColor)(c);
|
|
31
|
-
if (!normalized || normalized.startsWith("$"))
|
|
32
|
-
return !0;
|
|
33
|
-
}) && (console.error(
|
|
34
|
-
`LinearGradient: "colors" prop contains invalid color tokens: ${colors} fallback to default colors: ["#000", "#fff"]`
|
|
35
|
-
), colors = ["#000", "#fff"]), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(LinearGradientFrame, { ref, ...stackProps, children: [
|
|
36
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
37
|
-
import_linear_gradient.LinearGradient,
|
|
38
|
-
{
|
|
39
|
-
start,
|
|
40
|
-
end,
|
|
41
|
-
colors,
|
|
42
|
-
locations,
|
|
43
|
-
style: gradientStyle
|
|
44
|
-
}
|
|
45
|
-
),
|
|
46
|
-
children
|
|
47
|
-
] });
|
|
48
|
-
}
|
|
49
|
-
), gradientStyle = {
|
|
50
|
-
position: "absolute",
|
|
51
|
-
top: 0,
|
|
52
|
-
left: 0,
|
|
53
|
-
right: 0,
|
|
54
|
-
bottom: 0,
|
|
55
|
-
zIndex: 0
|
|
56
|
-
};
|
|
57
|
-
//# sourceMappingURL=LinearGradient.js.map
|
package/dist/cjs/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
7
|
-
for (let key of __getOwnPropNames(from))
|
|
8
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
|
-
return to;
|
|
10
|
-
}, __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
11
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
12
|
-
var src_exports = {};
|
|
13
|
-
module.exports = __toCommonJS(src_exports);
|
|
14
|
-
__reExport(src_exports, require("./LinearGradient"), module.exports);
|
|
15
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
9
|
-
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
-
return to;
|
|
14
|
-
};
|
|
15
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
21
|
-
mod
|
|
22
|
-
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
23
|
-
var linear_gradient_exports = {};
|
|
24
|
-
__export(linear_gradient_exports, {
|
|
25
|
-
LinearGradient: () => LinearGradient
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(linear_gradient_exports);
|
|
28
|
-
var import_core = require("@tamagui/core"), React = __toESM(require("react")), import_react_native = require("react-native-web"), import_jsx_runtime = require("react/jsx-runtime");
|
|
29
|
-
function LinearGradient({
|
|
30
|
-
colors,
|
|
31
|
-
locations,
|
|
32
|
-
start,
|
|
33
|
-
end,
|
|
34
|
-
...props
|
|
35
|
-
}) {
|
|
36
|
-
const [{ height, width }, setLayout] = React.useState({
|
|
37
|
-
height: 1,
|
|
38
|
-
width: 1
|
|
39
|
-
}), linearGradientBackgroundImage = React.useMemo(() => getLinearGradientBackgroundImage(
|
|
40
|
-
// @ts-expect-error ok
|
|
41
|
-
colors,
|
|
42
|
-
locations,
|
|
43
|
-
start,
|
|
44
|
-
end,
|
|
45
|
-
width,
|
|
46
|
-
height
|
|
47
|
-
), [colors, locations, start, end, width, height]);
|
|
48
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
49
|
-
import_react_native.View,
|
|
50
|
-
{
|
|
51
|
-
...props,
|
|
52
|
-
style: [
|
|
53
|
-
props.style,
|
|
54
|
-
// @ts-ignore: [ts] Property 'backgroundImage' does not exist on type 'ViewStyle'.
|
|
55
|
-
{ backgroundImage: linearGradientBackgroundImage }
|
|
56
|
-
],
|
|
57
|
-
onLayout: (event) => {
|
|
58
|
-
const { width: width2, height: height2 } = event.nativeEvent.layout;
|
|
59
|
-
setLayout((oldLayout) => width2 !== oldLayout.width || height2 !== oldLayout.height ? { height: height2, width: width2 } : oldLayout), props.onLayout && props.onLayout(event);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
function getLinearGradientBackgroundImage(colors, locations, startPoint, endPoint, width = 1, height = 1) {
|
|
65
|
-
const gradientColors = calculateGradientColors(
|
|
66
|
-
// @ts-expect-error TODO fix numbers
|
|
67
|
-
colors,
|
|
68
|
-
locations
|
|
69
|
-
);
|
|
70
|
-
return `linear-gradient(${calculatePseudoAngle(width, height, startPoint, endPoint)}deg, ${gradientColors.join(", ")})`;
|
|
71
|
-
}
|
|
72
|
-
function calculatePseudoAngle(width, height, startPoint, endPoint) {
|
|
73
|
-
const getControlPoints = () => {
|
|
74
|
-
let correctedStartPoint = [0, 0];
|
|
75
|
-
Array.isArray(startPoint) && (correctedStartPoint = [
|
|
76
|
-
startPoint[0] != null ? startPoint[0] : 0,
|
|
77
|
-
startPoint[1] != null ? startPoint[1] : 0
|
|
78
|
-
]);
|
|
79
|
-
let correctedEndPoint = [0, 1];
|
|
80
|
-
return Array.isArray(endPoint) && (correctedEndPoint = [
|
|
81
|
-
endPoint[0] != null ? endPoint[0] : 0,
|
|
82
|
-
endPoint[1] != null ? endPoint[1] : 1
|
|
83
|
-
]), [correctedStartPoint, correctedEndPoint];
|
|
84
|
-
}, [start, end] = getControlPoints();
|
|
85
|
-
start[0] *= width, end[0] *= width, start[1] *= height, end[1] *= height;
|
|
86
|
-
const py = end[1] - start[1], px = end[0] - start[0];
|
|
87
|
-
return 90 + Math.atan2(py, px) * 180 / Math.PI;
|
|
88
|
-
}
|
|
89
|
-
function calculateGradientColors(colors, locations) {
|
|
90
|
-
return colors.map((color, index) => {
|
|
91
|
-
const output = (0, import_core.normalizeColor)(color);
|
|
92
|
-
if (locations && locations[index]) {
|
|
93
|
-
const percentage = Math.max(0, Math.min(1, locations[index])) * 100;
|
|
94
|
-
return `${output} ${percentage}%`;
|
|
95
|
-
}
|
|
96
|
-
return output;
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
//# sourceMappingURL=linear-gradient.js.map
|
|
File without changes
|
|
File without changes
|
|
File without changes
|