Skip to content

Conversation

@omairqazi29
Copy link

@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 561cd50

Command Status Duration Result
nx test apps-automated -c=ios ✅ Succeeded 4s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded 2s View ↗

☁️ Nx Cloud last updated this comment at 2025-12-24 03:11:21 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


helper.buildUIAndRunTest(slider, testAction);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for this @omairqazi29 💯 Possible to add a quick sample page which would have a Slider with this style gradient on it in the toolbox?
You can copy/paste this page for example: https://github.com/NativeScript/NativeScript/blob/main/apps/toolbox/src/pages/switch.xml into a sliders.{xml,ts} and add slider to it with this gradient style. It's super helpful to confirm behavior on your end but also for us to confirm as well.

Copy link
Author

Choose a reason for hiding this comment

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

add a quick sample page

Done, PFA, thanks!

image

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Slider linear-gradient support

2 participants