summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoradrianknight89 <adrianknight89@outlook.com>2016-12-19 12:42:16 (GMT)
committerRui Marinho <me@ruimarinho.net>2016-12-19 12:42:16 (GMT)
commite0165abbcd1329a3dfd353548f5d75eef0c792de (patch)
tree58c352a50974cb38883e2d221b2766c548af0574
parent6c8abfdc14138bb803272497b0f97793106acb08 (diff)
downloadxamarin-forms-e0165abbcd1329a3dfd353548f5d75eef0c792de.zip
xamarin-forms-e0165abbcd1329a3dfd353548f5d75eef0c792de.tar.gz
xamarin-forms-e0165abbcd1329a3dfd353548f5d75eef0c792de.tar.bz2
Slider should show user-set value on initial load (#378)
-rw-r--r--Xamarin.Forms.Platform.Android/Renderers/SliderRenderer.cs30
1 files changed, 18 insertions, 12 deletions
diff --git a/Xamarin.Forms.Platform.Android/Renderers/SliderRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/SliderRenderer.cs
index 5df5bf3..2f94b41 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<Slider, SeekBar>, 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