import { elevationProperty , rippleColorProperty , themer } from '@nativescript-community/ui-material-core' ; import { Color , backgroundColorProperty , colorProperty } from '@nativescript/core' ; import { maxValueProperty } from '@nativescript/core/ui/progress' ; import { minValueProperty } from '@nativescript/core/ui/slider/slider-common' ; import { stepSizeProperty , thumbColorProperty , thumbHollowAtStartProperty , trackBackgroundColorProperty , trackFillColorProperty } from './cssproperties' ; import { SliderBase } from './slider-common' ; export class Slider extends SliderBase { nativeViewProtected : MDCSlider ; constructor ( ) { super ( ) ; } public createNativeView ( ) { const result = MDCSlider . new ( ) ; result . statefulAPIEnabled = true ; ( result as any ) . enableRippleBehavior = true ; const colorScheme = themer . getAppColorScheme ( ) as MDCSemanticColorScheme ; if ( colorScheme ) { MDCSliderColorThemer . applySemanticColorSchemeToSlider ( colorScheme , result ) ; } return result ; } [ colorProperty . setNative ] ( color ) { if ( ! this . trackBackgroundColor ) { this . trackBackgroundColor = new Color ( 66.3 , color . r , color . g , color . b ) ; } if ( ! this . trackFillColor ) { this . trackFillColor = color ; } if ( ! this . thumbColor ) { this . thumbColor = color ; } } [ rippleColorProperty . setNative ] ( color ) { this . nativeViewProtected . rippleColor = color ? ( color . ios as UIColor ) . colorWithAlphaComponent ( 0.26 ) : null ; } [ thumbColorProperty . setNative ] ( color ) { this . nativeViewProtected . setThumbColorForState ( color ? color . ios : null , UIControlState . Normal ) ; if ( ! this . rippleColor ) { this . rippleColor = color ; } } [ backgroundColorProperty . setNative ] ( value ) { this [ trackBackgroundColorProperty . setNative ] ( value ) ; } [ trackBackgroundColorProperty . setNative ] ( color ) { this . nativeViewProtected . setTrackBackgroundColorForState ( color ? color . ios : null , UIControlState . Normal ) ; } [ trackFillColorProperty . setNative ] ( color ) { this . nativeViewProtected . setTrackFillColorForState ( color ? color . ios : null , UIControlState . Normal ) ; } [ thumbHollowAtStartProperty . setNative ] ( value ) { this . nativeViewProtected . thumbHollowAtStart = value ; } [ elevationProperty . setNative ] ( value ) { this . nativeViewProtected . thumbElevation = value ; } [ minValueProperty . setNative ] ( value ) { this . nativeViewProtected . minimumValue = value ; if ( this . stepSize !== 0 ) { this . nativeViewProtected . numberOfDiscreteValues = ( this . maxValue - this . minValue ) / value ; } } [ maxValueProperty . setNative ] ( value ) { this . nativeViewProtected . maximumValue = value ; if ( this . stepSize !== 0 ) { this . nativeViewProtected . numberOfDiscreteValues = ( this . maxValue - this . minValue ) / value ; } } [ stepSizeProperty . getDefault ] ( ) { return 0 ; } [ stepSizeProperty . setNative ] ( value ) { if ( value === 0 ) { this . nativeViewProtected . discrete = false ; } else { this . nativeViewProtected . discrete = true ; this . nativeViewProtected . numberOfDiscreteValues = ( this . maxValue - this . minValue ) / value ; this . nativeViewProtected . shouldDisplayDiscreteValueLabel = false ; } } }