Skip to content

Commit

Permalink
Merge branch 'release/6.0.1xx-preview4'
Browse files Browse the repository at this point in the history
# Conflicts:
#	eng/Version.Details.xml
#	eng/Versions.props
#	src/Controls/samples/Controls.Sample/Pages/MainPage.cs
#	src/Controls/src/Core/AppHostBuilderExtensions.cs
#	src/Core/src/TaskExtensions.cs
  • Loading branch information
PureWeen committed Apr 27, 2021
2 parents 87ace6a + ea4a7ae commit 45065af
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 4 deletions.
2 changes: 1 addition & 1 deletion GitInfo.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.0.100-ci.main
6.0.100-preview.4
3 changes: 3 additions & 0 deletions src/Compatibility/Core/src/WinUI/SliderRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,19 @@ void UpdateFlowDirection()

protected override bool PreventGestureBubbling { get; set; } = true;

[PortHandler]
void OnNativeValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
((IElementController)Element).SetValueFromRenderer(Slider.ValueProperty, e.NewValue);
}

[PortHandler]
void OnPointerPressed(object sender, PointerRoutedEventArgs e)
{
((ISliderController)Element)?.SendDragStarted();
}

[PortHandler]
void OnPointerReleased(object sender, PointerRoutedEventArgs e)
{
((ISliderController)Element)?.SendDragCompleted();
Expand Down
2 changes: 1 addition & 1 deletion src/Controls/samples/Controls.Sample/Pages/MainPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,4 @@ void AddTextResizeDemo(Microsoft.Maui.ILayout layout)
layout.Add(explicitWidthTestLabel);
}
}
}
}
4 changes: 2 additions & 2 deletions src/Controls/src/Core/AppHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ private static void ConfigureNativeServices(HostBuilderContext arg1, IServiceCol
if (!UI.Xaml.Application.Current.Resources.ContainsKey("MauiControlsPageControlStyle"))
{
var myResourceDictionary = new Microsoft.UI.Xaml.ResourceDictionary();
myResourceDictionary.Source = new Uri("ms-appx:///Microsoft.Maui.Controls/Maui/Platform/Windows/Styles/Resources.xbf");
myResourceDictionary.Source = new Uri("ms-appx:///Microsoft.Maui.Controls/Platform/Windows/Styles/Resources.xbf");
Microsoft.UI.Xaml.Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
}
#endif
}
}
}
}
46 changes: 46 additions & 0 deletions src/Core/src/Handlers/Slider/SliderHandler.Windows.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#nullable enable
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;

namespace Microsoft.Maui.Handlers
Expand All @@ -8,6 +11,9 @@ public partial class SliderHandler : ViewHandler<ISlider, Slider>
{
static Brush? DefaultForegroundColor;
static Brush? DefaultBackgroundColor;

PointerEventHandler? _pointerPressedHandler;
PointerEventHandler? _pointerReleasedHandler;

protected override Slider CreateNativeView()
{
Expand All @@ -19,6 +25,30 @@ protected override Slider CreateNativeView()
return slider;
}

protected override void ConnectHandler(Slider nativeView)
{
nativeView.ValueChanged += OnNativeValueChanged;

_pointerPressedHandler = new PointerEventHandler(OnPointerPressed);
_pointerReleasedHandler = new PointerEventHandler(OnPointerReleased);

nativeView.AddHandler(UIElement.PointerPressedEvent, _pointerPressedHandler, true);
nativeView.AddHandler(UIElement.PointerReleasedEvent, _pointerReleasedHandler, true);
nativeView.AddHandler(UIElement.PointerCanceledEvent, _pointerReleasedHandler, true);
}

protected override void DisconnectHandler(Slider nativeView)
{
nativeView.ValueChanged -= OnNativeValueChanged;

nativeView.RemoveHandler(UIElement.PointerPressedEvent, _pointerPressedHandler);
nativeView.RemoveHandler(UIElement.PointerReleasedEvent, _pointerReleasedHandler);
nativeView.RemoveHandler(UIElement.PointerCanceledEvent, _pointerReleasedHandler);

_pointerPressedHandler = null;
_pointerReleasedHandler = null;
}

protected override void SetupDefaults(Slider nativeView)
{
DefaultForegroundColor = nativeView.Foreground;
Expand Down Expand Up @@ -52,5 +82,21 @@ public static void MapMaximumTrackColor(SliderHandler handler, ISlider slider)

[MissingMapper]
public static void MapThumbColor(SliderHandler handler, ISlider slider) { }

void OnNativeValueChanged(object? sender, RangeBaseValueChangedEventArgs e)
{
if (VirtualView != null)
VirtualView.Value = e.NewValue;
}

void OnPointerPressed(object? sender, PointerRoutedEventArgs e)
{
VirtualView?.DragStarted();
}

void OnPointerReleased(object? sender, PointerRoutedEventArgs e)
{
VirtualView?.DragCompleted();
}
}
}
10 changes: 10 additions & 0 deletions src/Core/src/Platform/Windows/SliderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
#nullable enable
using System;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;

namespace Microsoft.Maui
{
public static class SliderExtensions
{
static void UpdateIncrement(this Slider nativeSlider, ISlider slider)
{
double stepping = Math.Min((slider.Maximum - slider.Minimum) / 1000, 1);
nativeSlider.StepFrequency = stepping;
nativeSlider.SmallChange = stepping;
}

public static void UpdateMinimum(this Slider nativeSlider, ISlider slider)
{
nativeSlider.Minimum = slider.Minimum;
nativeSlider.UpdateIncrement(slider);
}

public static void UpdateMaximum(this Slider nativeSlider, ISlider slider)
{
nativeSlider.Maximum = slider.Maximum;
nativeSlider.UpdateIncrement(slider);
}

public static void UpdateValue(this Slider nativeSlider, ISlider slider)
Expand Down

0 comments on commit 45065af

Please sign in to comment.