@@ -6,6 +6,8 @@ import { BindingOptions, View, Page, Observable, EventData, PropertyChangeData,
66import { Slider } from '@nativescript/core/ui/slider' ;
77// << article-require-slider
88
9+ import { LinearGradient } from '@nativescript/core/ui/styling/linear-gradient' ;
10+
911// ### Binding the Progress and Slider value properties to a observable view-model property.
1012
1113// >> article-binding-slider-properties
@@ -121,6 +123,67 @@ export function test_set_backgroundColor() {
121123 }
122124}
123125
126+ export function test_set_linear_gradient_background ( ) {
127+ const slider = new Slider ( ) ;
128+
129+ // Create a linear gradient programmatically
130+ const gradient = new LinearGradient ( ) ;
131+ gradient . angle = Math . PI / 2 ; // 90 degrees (left to right)
132+ gradient . colorStops = [ { color : new Color ( 'red' ) } , { color : new Color ( 'green' ) } , { color : new Color ( 'blue' ) } ] ;
133+
134+ function testAction ( views : Array < View > ) {
135+ // Set the gradient via the style's backgroundImage
136+ slider . style . backgroundImage = gradient ;
137+
138+ // Verify the slider was created and the gradient was applied
139+ TKUnit . assertNotNull ( slider , 'slider should not be null' ) ;
140+
141+ if ( __APPLE__ ) {
142+ // On iOS, verify that track images were set
143+ const minTrackImage = slider . ios . minimumTrackImageForState ( UIControlState . Normal ) ;
144+ const maxTrackImage = slider . ios . maximumTrackImageForState ( UIControlState . Normal ) ;
145+ TKUnit . assertNotNull ( minTrackImage , 'minimumTrackImage should be set after applying gradient' ) ;
146+ TKUnit . assertNotNull ( maxTrackImage , 'maximumTrackImage should be set after applying gradient' ) ;
147+ } else if ( __ANDROID__ ) {
148+ // On Android, verify the progress drawable was modified
149+ const progressDrawable = slider . android . getProgressDrawable ( ) ;
150+ TKUnit . assertNotNull ( progressDrawable , 'progressDrawable should not be null' ) ;
151+ }
152+ }
153+
154+ helper . buildUIAndRunTest ( slider , testAction ) ;
155+ }
156+
157+ export function test_set_linear_gradient_with_stops ( ) {
158+ const slider = new Slider ( ) ;
159+
160+ // Create a linear gradient with explicit color stops
161+ const gradient = new LinearGradient ( ) ;
162+ gradient . angle = 0 ; // 0 degrees (bottom to top)
163+ gradient . colorStops = [
164+ { color : new Color ( 'orangered' ) , offset : { unit : '%' , value : 0 } } ,
165+ { color : new Color ( 'green' ) , offset : { unit : '%' , value : 0.5 } } ,
166+ { color : new Color ( 'lightblue' ) , offset : { unit : '%' , value : 1 } } ,
167+ ] ;
168+
169+ function testAction ( views : Array < View > ) {
170+ slider . style . backgroundImage = gradient ;
171+
172+ // Verify the slider was created
173+ TKUnit . assertNotNull ( slider , 'slider should not be null' ) ;
174+
175+ if ( __APPLE__ ) {
176+ const minTrackImage = slider . ios . minimumTrackImageForState ( UIControlState . Normal ) ;
177+ TKUnit . assertNotNull ( minTrackImage , 'minimumTrackImage should be set after applying gradient with stops' ) ;
178+ } else if ( __ANDROID__ ) {
179+ const progressDrawable = slider . android . getProgressDrawable ( ) ;
180+ TKUnit . assertNotNull ( progressDrawable , 'progressDrawable should not be null' ) ;
181+ }
182+ }
183+
184+ helper . buildUIAndRunTest ( slider , testAction ) ;
185+ }
186+
124187export function test_default_TNS_values ( ) {
125188 const slider = new Slider ( ) ;
126189 TKUnit . assertEqual ( slider . value , 0 , 'Default slider.value' ) ;
0 commit comments