@@ -5,7 +5,7 @@ import { colorProperty, backgroundColorProperty, backgroundInternalProperty } fr
55import { Color } from '../../color' ;
66import { AccessibilityDecrementEventData , AccessibilityIncrementEventData } from '.' ;
77import { LinearGradient } from '../styling/linear-gradient' ;
8- import { Screen } from '../../platform' ;
8+ import { Screen } from '../../platform/screen ' ;
99
1010export * from './slider-common' ;
1111
@@ -186,52 +186,48 @@ export class Slider extends SliderBase {
186186 gradientLayer . frame = CGRectMake ( 0 , 0 , trackWidth , trackHeight ) ;
187187 gradientLayer . cornerRadius = trackHeight / 2 ;
188188
189+ // Create renderer format with proper scale
190+ const format = UIGraphicsImageRendererFormat . defaultFormat ( ) ;
191+ format . scale = Screen . mainScreen . scale ;
192+ format . opaque = false ;
193+
194+ const size = CGSizeMake ( trackWidth , trackHeight ) ;
195+ const renderer = UIGraphicsImageRenderer . alloc ( ) . initWithSizeFormat ( size , format ) ;
196+
189197 // Render gradient to image
190- UIGraphicsBeginImageContextWithOptions ( CGSizeMake ( trackWidth , trackHeight ) , false , Screen . mainScreen . scale ) ;
191- const context = UIGraphicsGetCurrentContext ( ) ;
192- if ( context ) {
193- gradientLayer . renderInContext ( context ) ;
194- const gradientImage = UIGraphicsGetImageFromCurrentImageContext ( ) ;
195- UIGraphicsEndImageContext ( ) ;
196-
197- if ( gradientImage ) {
198- // Create stretchable image for the track
199- const capInsets = new UIEdgeInsets ( {
198+ const gradientImage = renderer . imageWithActions ( ( rendererContext ) => {
199+ gradientLayer . renderInContext ( rendererContext . CGContext ) ;
200+ } ) ;
201+
202+ if ( gradientImage ) {
203+ // Create stretchable image for the track
204+ const capInsets = new UIEdgeInsets ( {
205+ top : 0 ,
206+ left : trackHeight / 2 ,
207+ bottom : 0 ,
208+ right : trackHeight / 2 ,
209+ } ) ;
210+ const stretchableImage = gradientImage . resizableImageWithCapInsetsResizingMode ( capInsets , UIImageResizingMode . Stretch ) ;
211+
212+ // Set the gradient image for minimum track (filled portion)
213+ nativeView . setMinimumTrackImageForState ( stretchableImage , UIControlState . Normal ) ;
214+
215+ // For maximum track, create a semi-transparent version
216+ const maxTrackImage = renderer . imageWithActions ( ( rendererContext ) => {
217+ CGContextSetAlpha ( rendererContext . CGContext , 0.3 ) ;
218+ gradientLayer . renderInContext ( rendererContext . CGContext ) ;
219+ } ) ;
220+
221+ if ( maxTrackImage ) {
222+ const maxCapInsets = new UIEdgeInsets ( {
200223 top : 0 ,
201224 left : trackHeight / 2 ,
202225 bottom : 0 ,
203226 right : trackHeight / 2 ,
204227 } ) ;
205- const stretchableImage = gradientImage . resizableImageWithCapInsetsResizingMode ( capInsets , UIImageResizingMode . Stretch ) ;
206-
207- // Set the gradient image for minimum track (filled portion)
208- nativeView . setMinimumTrackImageForState ( stretchableImage , UIControlState . Normal ) ;
209-
210- // For maximum track, create a semi-transparent version
211- UIGraphicsBeginImageContextWithOptions ( CGSizeMake ( trackWidth , trackHeight ) , false , Screen . mainScreen . scale ) ;
212- const maxContext = UIGraphicsGetCurrentContext ( ) ;
213- if ( maxContext ) {
214- CGContextSetAlpha ( maxContext , 0.3 ) ;
215- gradientLayer . renderInContext ( maxContext ) ;
216- const maxTrackImage = UIGraphicsGetImageFromCurrentImageContext ( ) ;
217- UIGraphicsEndImageContext ( ) ;
218-
219- if ( maxTrackImage ) {
220- const maxCapInsets = new UIEdgeInsets ( {
221- top : 0 ,
222- left : trackHeight / 2 ,
223- bottom : 0 ,
224- right : trackHeight / 2 ,
225- } ) ;
226- const maxStretchableImage = maxTrackImage . resizableImageWithCapInsetsResizingMode ( maxCapInsets , UIImageResizingMode . Stretch ) ;
227- nativeView . setMaximumTrackImageForState ( maxStretchableImage , UIControlState . Normal ) ;
228- }
229- } else {
230- UIGraphicsEndImageContext ( ) ;
231- }
228+ const maxStretchableImage = maxTrackImage . resizableImageWithCapInsetsResizingMode ( maxCapInsets , UIImageResizingMode . Stretch ) ;
229+ nativeView . setMaximumTrackImageForState ( maxStretchableImage , UIControlState . Normal ) ;
232230 }
233- } else {
234- UIGraphicsEndImageContext ( ) ;
235231 }
236232 }
237233
0 commit comments