From e0165abbcd1329a3dfd353548f5d75eef0c792de Mon Sep 17 00:00:00 2001 From: adrianknight89 Date: Mon, 19 Dec 2016 06:42:16 -0600 Subject: Slider should show user-set value on initial load (#378) --- .../Renderers/SliderRenderer.cs | 30 +++++++++++++--------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/Xamarin.Forms.Platform.Android/Renderers/SliderRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/SliderRenderer.cs index 5df5bf31..2f94b411 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/SliderRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/SliderRenderer.cs @@ -7,8 +7,8 @@ namespace Xamarin.Forms.Platform.Android { public class SliderRenderer : ViewRenderer, SeekBar.IOnSeekBarChangeListener { - double _max; - double _min; + double _max, _min; + bool _progressChangedOnce; public SliderRenderer() { @@ -23,6 +23,12 @@ namespace Xamarin.Forms.Platform.Android void SeekBar.IOnSeekBarChangeListener.OnProgressChanged(SeekBar seekBar, int progress, bool fromUser) { + if (!_progressChangedOnce) + { + _progressChangedOnce = true; + return; + } + ((IElementController)Element).SetValueFromRenderer(Slider.ValueProperty, Value); } @@ -84,20 +90,20 @@ namespace Xamarin.Forms.Platform.Android base.OnLayout(changed, l, t, r, b); BuildVersionCodes androidVersion = Build.VERSION.SdkInt; - if (androidVersion >= BuildVersionCodes.JellyBean) - { - // Thumb only supported JellyBean and higher + if (androidVersion < BuildVersionCodes.JellyBean) + return; - if (Control == null) - return; + // Thumb only supported JellyBean and higher - SeekBar seekbar = Control; + if (Control == null) + return; - Drawable thumb = seekbar.Thumb; - int thumbTop = seekbar.Height / 2 - thumb.IntrinsicHeight / 2; + SeekBar seekbar = Control; - thumb.SetBounds(thumb.Bounds.Left, thumbTop, thumb.Bounds.Left + thumb.IntrinsicWidth, thumbTop + thumb.IntrinsicHeight); - } + Drawable thumb = seekbar.Thumb; + int thumbTop = seekbar.Height / 2 - thumb.IntrinsicHeight / 2; + + thumb.SetBounds(thumb.Bounds.Left, thumbTop, thumb.Bounds.Left + thumb.IntrinsicWidth, thumbTop + thumb.IntrinsicHeight); } } } \ No newline at end of file -- cgit v1.2.3