Skip to content

feat(slider): add linear-gradient support for track background#11015

Merged
NathanWalker merged 28 commits intoNativeScript:mainfrom
omairqazi29:feat/slider-linear-gradient-support
Jan 6, 2026
Merged

feat(slider): add linear-gradient support for track background#11015
NathanWalker merged 28 commits intoNativeScript:mainfrom
omairqazi29:feat/slider-linear-gradient-support

Conversation

@omairqazi29
Copy link
Contributor

@omairqazi29 omairqazi29 commented Dec 21, 2025

Summary

Android Implementation

  • Creates android.graphics.LinearGradient shader from CSS gradient color stops
  • Applies gradient to ShapeDrawable wrapped in ClipDrawable for progress clipping
  • Sets both progress layer and background layer (at 30% opacity) of the SeekBar

iOS Implementation

  • Creates CAGradientLayer with colors and positions from CSS gradient
  • Renders gradient layer to UIImage
  • Creates stretchable track images using resizableImageWithCapInsetsResizingMode
  • Sets minimum track image (full opacity) and maximum track image (30% opacity)

Usage

Via CSS

.gradient-slider {
    background: linear-gradient(to right, orangered, green, lightblue);
}
<Slider class="gradient-slider" minValue="0" maxValue="100" value="50" />

Programmatically

import { LinearGradient } from '@nativescript/core/ui/styling/linear-gradient';
import { Color } from '@nativescript/core';

const gradient = new LinearGradient();
gradient.angle = Math.PI / 2; // left to right
gradient.colorStops = [
    { color: new Color('orangered') },
    { color: new Color('green') },
    { color: new Color('lightblue') },
];

slider.style.backgroundImage = gradient;

Test plan

  • Added unit tests for linear gradient backgrounds
  • Added unit tests for linear gradients with explicit color stops
  • Manual testing on Android device/emulator
  • Manual testing on iOS device/simulator

Closes #5940

Enable using CSS linear-gradient for the Slider component's track.
This allows setting gradient backgrounds via the background-image
CSS property or programmatically.

On Android:
- Creates LinearGradient shader applied to ShapeDrawable
- Sets gradient on both progress and background layers of SeekBar

On iOS:
- Creates CAGradientLayer and renders to UIImage
- Sets resizable track images for min/max track states

Closes NativeScript#5940
@nx-cloud
Copy link

nx-cloud bot commented Dec 22, 2025

View your CI Pipeline Execution ↗ for commit 8805f91

Command Status Duration Result
nx test apps-automated -c=android ✅ Succeeded 4m 28s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded 3s View ↗

☁️ Nx Cloud last updated this comment at 2025-12-28 17:12:43 UTC

@nx-cloud
Copy link

nx-cloud bot commented Dec 22, 2025

View your CI Pipeline Execution ↗ for commit c3326e5

Command Status Duration Result
nx run-many --target=test --configuration=ci --... ✅ Succeeded 1s View ↗

☁️ Nx Cloud last updated this comment at 2025-12-22 03:03:49 UTC

Add sample page to toolbox demonstrating gradient slider backgrounds:
- Default slider for comparison
- Various gradient styles (rainbow, sunset, ocean, purple)
- Gradient with explicit color stops
- Disabled gradient slider example
@NathanWalker
Copy link
Contributor

Nice work @omairqazi29 I pushed up one adjustment to use newer/preferred iOS 10+ (non-deprecated) graphics APIs since NativeScript is right now a iOS 12/13 min target 👍
omairqazi29@430fd8d

//
if (value && value.image instanceof LinearGradient) {
this._applyGradientToTrack(value.image);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually unfortunately @omairqazi29 it does not work on Android if able to check this.
Screenshot 2025-12-26 at 3 41 28 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NathanWalker Fixed using ShapeDrawable with LinearGradient shader as shown in #5940 example.
Screenshot_1766797154

And on iOS:
image

@omairqazi29
Copy link
Contributor Author

Nice work @omairqazi29 I pushed up one adjustment to use newer/preferred iOS 10+ (non-deprecated) graphics APIs since NativeScript is right now a iOS 12/13 min target 👍 omairqazi29@430fd8d

Awesome noted.

dependabot bot and others added 13 commits January 5, 2026 19:29
…ativeScript#11020)

[skip ci]
Bumps [step-security/harden-runner](https://github.com/step-security/harden-runner) from 2.13.1 to 2.14.0.
- [Release notes](https://github.com/step-security/harden-runner/releases)
- [Commits](step-security/harden-runner@f4a75cf...20cf305)

---
updated-dependencies:
- dependency-name: step-security/harden-runner
  dependency-version: 2.14.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…ipt#11021)

[skip ci]
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 5.6.0 to 6.1.0.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](actions/setup-python@a26af69...83679a8)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-version: 6.1.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…Script#11022)

[skip ci]
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 5.0.0 to 6.0.0.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](actions/upload-artifact@330a01c...b7c566a)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: 6.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…cript#11023)

[skip ci]
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 4.31.5 to 4.31.9.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](github/codeql-action@fdbfb4d...5d4e8d1)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 4.31.9
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…t#11024)

[skip ci]
Bumps [actions/setup-java](https://github.com/actions/setup-java) from 5.0.0 to 5.1.0.
- [Release notes](https://github.com/actions/setup-java/releases)
- [Commits](actions/setup-java@dded088...f2beeb2)

---
updated-dependencies:
- dependency-name: actions/setup-java
  dependency-version: 5.1.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- project: devtools 0.0.2-next.1

- project: webpack5 5.0.31-next.1

- project: core 9.0.11-next.2

- project: vite 1.0.4-next.1
- project: devtools 0.0.2-next.2

- project: webpack5 5.0.31-next.2

- project: core 9.0.12-next.0

- project: vite 1.0.4-next.2
github-actions bot and others added 9 commits January 5, 2026 19:29
- project: devtools 0.0.2-next.4

- project: webpack5 5.0.30-next.1

- project: core 9.0.12-next.2

- project: vite 1.0.6-next.1
- project: webpack5 5.0.31-next.0
- project: webpack5 5.0.31-next.1

- project: vite 1.0.6-next.2
- project: webpack5 5.0.32-next.0
@NathanWalker
Copy link
Contributor

Pushed up one last improvement to android but wanted you to see where it all landed:
1603027

Screenshot 2026-01-05 at 8 42 13 PM

@NathanWalker
Copy link
Contributor

Thanks again for all your work here @omairqazi29!

@NathanWalker NathanWalker merged commit 08f6d18 into NativeScript:main Jan 6, 2026
1 check passed
@omairqazi29 omairqazi29 deleted the feat/slider-linear-gradient-support branch January 7, 2026 02:54