@react-native-gpui/linear-gradient 0.0.0-stage → 2.8.0-alpha.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/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@react-native-gpui/linear-gradient` are listed here. Each version's section becomes the notes of its GitHub release.
4
+
5
+ ## 2.8.0-alpha.1 - 2026-11-27
6
+
7
+ - First release, for `react-native-linear-gradient` 2.8.x: paints a linear gradient under the children of the view.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Streetwriters
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,37 @@
1
- # Temporary Holding Version
1
+ # @react-native-gpui/linear-gradient
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Adapter for [`react-native-linear-gradient`](https://github.com/react-native-linear-gradient/react-native-linear-gradient) (MIT): paints a linear gradient under the children of the view.
4
+
5
+ ## About
6
+
7
+ This package is the desktop adapter for [`react-native-linear-gradient`](https://github.com/react-native-linear-gradient/react-native-linear-gradient) 2.8. Install the original library next to it; its JavaScript runs unchanged on desktop, and this package provides the native side. The upstream library is licensed under the MIT license.
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ npm install react-native-linear-gradient @react-native-gpui/linear-gradient
13
+ ```
14
+
15
+ The module is autolinked on desktop.
16
+
17
+ ## Usage
18
+
19
+ ```js
20
+ import { LinearGradient } from 'react-native-linear-gradient';
21
+
22
+ <LinearGradient colors={['#2563eb', '#7c3aed']} style={{ flex: 1 }}>
23
+ {children}
24
+ </LinearGradient>;
25
+ ```
26
+
27
+ ## Platforms
28
+
29
+ macOS is tested. Windows and Linux are not tested yet.
30
+
31
+ ## Limitations
32
+
33
+ Two colors are drawn as one GPUI gradient, with their locations. More than two colors are drawn as one gradient per segment along the axis the direction is closest to, so a diagonal gradient with more than two colors is only approximate. `useAngle` and `angle` are honored, `angleCenter` is read but does not move the gradient.
34
+
35
+ ## License
36
+
37
+ MIT. See [LICENSE](LICENSE). The upstream library, [`react-native-linear-gradient`](https://github.com/react-native-linear-gradient/react-native-linear-gradient), is MIT licensed.
@@ -0,0 +1,14 @@
1
+ [package]
2
+ name = "rn-gpui-linear-gradient"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+
6
+ [dependencies]
7
+ react-native-gpui = "0.1"
8
+ # Only for DEP_RN_GPUI_CORE_RPATHS, which build.rs puts on the test binary rpath.
9
+ rn-gpui-sys = "0.1"
10
+ rn-gpui-module = "0.1"
11
+ gpui = "0.2"
12
+
13
+ [build-dependencies]
14
+ rn-gpui-module-build = "0.1"
@@ -0,0 +1,19 @@
1
+ fn main() {
2
+ rn_gpui_module_build::generate(&["../src/BVLinearGradientNativeComponent.ts"]);
3
+ test_rpaths();
4
+ }
5
+
6
+ /// Core's runtime is shared libraries (`libjsi.dylib`, ...). Core puts their
7
+ /// directories on the app's rpath only, so this crate's test binary gets them here.
8
+ fn test_rpaths() {
9
+ println!("cargo:rerun-if-env-changed=DEP_RN_GPUI_CORE_RPATHS");
10
+ if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows") {
11
+ return;
12
+ }
13
+ let Ok(dirs) = std::env::var("DEP_RN_GPUI_CORE_RPATHS") else {
14
+ return;
15
+ };
16
+ for dir in dirs.split('|').filter(|dir| !dir.is_empty()) {
17
+ println!("cargo:rustc-link-arg=-Wl,-rpath,{dir}");
18
+ }
19
+ }
@@ -0,0 +1,135 @@
1
+ rn_gpui_module::include_specs!();
2
+
3
+ use gpui::{
4
+ div, linear_color_stop, linear_gradient, prelude::*, rgba, AnyElement, LinearColorStop,
5
+ Window,
6
+ };
7
+
8
+ /// The processed color of React Native, `0xAARRGGBB`, as GPUI's `0xRRGGBBAA`.
9
+ fn color(processed: f64) -> u32 {
10
+ (processed as i64 as u32).rotate_left(8)
11
+ }
12
+
13
+ pub struct LinearGradient;
14
+
15
+ /// A CSS-style angle, in degrees from the top, of the line from start to end.
16
+ fn direction(props: &BVLinearGradientProps) -> f32 {
17
+ if props.use_angle() {
18
+ return props.angle() as f32;
19
+ }
20
+ let (start, end) = (props.start(), props.end());
21
+ let (dx, dy) = ((end.x - start.x) as f32, (end.y - start.y) as f32);
22
+ dx.atan2(-dy).to_degrees().rem_euclid(360.0)
23
+ }
24
+
25
+ fn stops(props: &BVLinearGradientProps) -> Vec<(u32, f32)> {
26
+ let colors = props.colors();
27
+ let locations = props.locations();
28
+ let count = colors.len();
29
+ colors
30
+ .iter()
31
+ .enumerate()
32
+ .map(|(index, processed)| {
33
+ let position = if locations.len() == count {
34
+ locations[index] as f32
35
+ } else if count > 1 {
36
+ index as f32 / (count - 1) as f32
37
+ } else {
38
+ 0.0
39
+ };
40
+ (color(*processed), position.clamp(0.0, 1.0))
41
+ })
42
+ .collect()
43
+ }
44
+
45
+ fn paint(props: &BVLinearGradientProps) -> AnyElement {
46
+ let stops = stops(props);
47
+ let angle = direction(props);
48
+ match stops.as_slice() {
49
+ [] => div().size_full().into_any_element(),
50
+ [(only, _)] => div().size_full().bg(rgba(*only)).into_any_element(),
51
+ [(first, first_at), (last, last_at)] => {
52
+ let gradient = linear_gradient(
53
+ angle,
54
+ linear_color_stop(rgba(*first), *first_at),
55
+ linear_color_stop(rgba(*last), *last_at),
56
+ );
57
+ div().size_full().bg(gradient).into_any_element()
58
+ }
59
+ _ => segments(&stops, angle),
60
+ }
61
+ }
62
+
63
+ /// Paints more than two stops as one two-stop gradient per segment, laid out
64
+ /// along the axis the direction is closest to. A diagonal direction is drawn
65
+ /// along its dominant axis.
66
+ fn segments(stops: &[(u32, f32)], angle: f32) -> AnyElement {
67
+ let radians = angle.to_radians();
68
+ let horizontal = radians.sin().abs() > radians.cos().abs();
69
+ let forward = if horizontal {
70
+ radians.sin() >= 0.0
71
+ } else {
72
+ -radians.cos() >= 0.0
73
+ };
74
+ let mut visual: Vec<(f32, u32)> = stops
75
+ .iter()
76
+ .map(|(color, at)| (if forward { *at } else { 1.0 - *at }, *color))
77
+ .collect();
78
+ visual.sort_by(|a, b| a.0.total_cmp(&b.0));
79
+
80
+ let segment_angle = if horizontal { 90.0 } else { 180.0 };
81
+ let mut root = div().relative().size_full();
82
+ for pair in visual.windows(2) {
83
+ let ((from, from_color), (to, to_color)) = (pair[0], pair[1]);
84
+ let width = to - from;
85
+ if width <= 0.0 {
86
+ continue;
87
+ }
88
+ let gradient = linear_gradient(
89
+ segment_angle,
90
+ LinearColorStop {
91
+ color: rgba(from_color).into(),
92
+ percentage: 0.0,
93
+ },
94
+ LinearColorStop {
95
+ color: rgba(to_color).into(),
96
+ percentage: 1.0,
97
+ },
98
+ );
99
+ let segment = div().absolute().bg(gradient);
100
+ let segment = if horizontal {
101
+ segment.top_0().bottom_0().left(gpui::relative(from)).w(gpui::relative(width))
102
+ } else {
103
+ segment.left_0().right_0().top(gpui::relative(from)).h(gpui::relative(width))
104
+ };
105
+ root = root.child(segment);
106
+ }
107
+ root.into_any_element()
108
+ }
109
+
110
+ impl BVLinearGradientSpec for LinearGradient {
111
+ fn create(_props: &BVLinearGradientProps, _cx: &mut BVLinearGradientContext) -> Self {
112
+ Self
113
+ }
114
+
115
+ fn update(
116
+ &mut self,
117
+ _props: &BVLinearGradientProps,
118
+ _changed: BVLinearGradientChanged,
119
+ _cx: &mut BVLinearGradientContext,
120
+ ) {
121
+ }
122
+
123
+ fn render(
124
+ &mut self,
125
+ props: &BVLinearGradientProps,
126
+ _window: &mut Window,
127
+ _cx: &mut BVLinearGradientContext,
128
+ ) -> AnyElement {
129
+ paint(props)
130
+ }
131
+ }
132
+
133
+ pub fn rn_gpui_register() {
134
+ react_native_gpui::host_component::register_component(bv_linear_gradient_component::<LinearGradient>());
135
+ }
package/package.json CHANGED
@@ -1,6 +1,37 @@
1
1
  {
2
2
  "name": "@react-native-gpui/linear-gradient",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.8.0-alpha.1",
4
+ "description": "Adapter for react-native-linear-gradient (MIT): paints gradients with the desktop renderer",
5
+ "license": "MIT",
6
+ "main": "src/index.ts",
7
+ "files": [
8
+ "src",
9
+ "desktop",
10
+ "react-native.config.js",
11
+ "README.md",
12
+ "CHANGELOG.md",
13
+ "LICENSE"
14
+ ],
15
+ "codegenConfig": {
16
+ "name": "RNGpuiLinearGradientSpec",
17
+ "type": "all",
18
+ "jsSrcsDir": "src"
19
+ },
20
+ "peerDependencies": {
21
+ "react-native": "0.87.x",
22
+ "react-native-linear-gradient": "2.8.x"
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/streetwriters/react-native-gpui-modules.git",
27
+ "directory": "modules/linear-gradient"
28
+ },
29
+ "homepage": "https://github.com/streetwriters/react-native-gpui-modules/tree/main/modules/linear-gradient#readme",
30
+ "bugs": {
31
+ "url": "https://github.com/streetwriters/react-native-gpui-modules/issues"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public",
35
+ "tag": "latest"
36
+ }
37
+ }
@@ -0,0 +1,14 @@
1
+ module.exports = {
2
+ dependency: {
3
+ platforms: {
4
+ desktop: {
5
+ crate: 'rn-gpui-linear-gradient',
6
+ hostComponents: [{ name: 'BVLinearGradient', container: true }],
7
+ sourceOverrides: {
8
+ 'react-native-linear-gradient/index.js':
9
+ './src/LinearGradient.desktop.js',
10
+ },
11
+ },
12
+ },
13
+ },
14
+ };
@@ -0,0 +1,22 @@
1
+ import type { HostComponent, ViewProps } from 'react-native';
2
+ import { codegenNativeComponent } from 'react-native';
3
+ import type { CodegenTypes } from 'react-native';
4
+
5
+ export type Point = Readonly<{
6
+ x: CodegenTypes.Double;
7
+ y: CodegenTypes.Double;
8
+ }>;
9
+
10
+ export interface NativeProps extends ViewProps {
11
+ start?: Point;
12
+ end?: Point;
13
+ colors: ReadonlyArray<CodegenTypes.Double>;
14
+ locations?: ReadonlyArray<CodegenTypes.Double>;
15
+ useAngle?: CodegenTypes.WithDefault<boolean, false>;
16
+ angleCenter?: Point;
17
+ angle?: CodegenTypes.WithDefault<CodegenTypes.Double, 0>;
18
+ }
19
+
20
+ export default codegenNativeComponent<NativeProps>('BVLinearGradient', {
21
+ interfaceOnly: true,
22
+ }) as HostComponent<NativeProps>;
@@ -0,0 +1,56 @@
1
+ import React, { Component } from 'react';
2
+ import { processColor } from 'react-native';
3
+ import NativeLinearGradient from './BVLinearGradientNativeComponent';
4
+
5
+ const toPoint = (name, point) => {
6
+ if (Array.isArray(point)) {
7
+ console.warn(
8
+ `LinearGradient '${name}' property should be an object with fields 'x' and 'y', Array type is deprecated.`,
9
+ );
10
+ return { x: point[0], y: point[1] };
11
+ }
12
+ return point;
13
+ };
14
+
15
+ export class LinearGradient extends Component {
16
+ static defaultProps = {
17
+ start: { x: 0.5, y: 0.0 },
18
+ end: { x: 0.5, y: 1.0 },
19
+ };
20
+
21
+ render() {
22
+ const {
23
+ children,
24
+ start,
25
+ end,
26
+ colors,
27
+ locations,
28
+ useAngle,
29
+ angleCenter,
30
+ angle,
31
+ ...otherProps
32
+ } = this.props;
33
+ if (colors && locations && colors.length !== locations.length) {
34
+ console.warn(
35
+ 'LinearGradient colors and locations props should be arrays of the same length',
36
+ );
37
+ }
38
+
39
+ return React.createElement(
40
+ NativeLinearGradient,
41
+ {
42
+ ...otherProps,
43
+ start: toPoint('start', start),
44
+ end: toPoint('end', end),
45
+ colors: colors.map(color => processColor(color)),
46
+ locations: locations ? locations.slice(0, colors.length) : undefined,
47
+ useAngle,
48
+ angleCenter: toPoint('angleCenter', angleCenter),
49
+ angle,
50
+ },
51
+ children,
52
+ );
53
+ }
54
+ }
55
+
56
+ export default LinearGradient;
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export {};