-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* StepperHandlers * Fixed Stepper handler broken tests * Remove duplicate searchbar * Add IStepper interface Co-authored-by: E.Z. Hart <[email protected]>
- Loading branch information
1 parent
18ed4c4
commit 403bc73
Showing
22 changed files
with
551 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace Microsoft.Maui | ||
{ | ||
/// <summary> | ||
/// Provides functionality to select a value from a range of values. | ||
/// </summary> | ||
public interface IRange : IView | ||
{ | ||
/// <summary> | ||
/// Gets or sets the minimum selectable value. | ||
/// </summary> | ||
double Minimum { get; } | ||
|
||
/// <summary> | ||
/// Gets or sets the maximum selectable value. | ||
/// </summary> | ||
double Maximum { get; } | ||
|
||
/// <summary> | ||
/// Gets or sets the current value. | ||
/// </summary> | ||
double Value { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace Microsoft.Maui | ||
{ | ||
/// <summary> | ||
/// Represents a View that consists of two buttons labeled with minus and plus signs. | ||
/// Use a Stepper for selecting a numeric value from a range of values. | ||
/// </summary> | ||
public interface IStepper : IView, IRange | ||
{ | ||
/// <summary> | ||
/// Gets the increment by which Value is increased or decreased. | ||
/// </summary> | ||
double Increment { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
using Android.Widget; | ||
using Android.Views; | ||
using AButton = Android.Widget.Button; | ||
using AOrientation = Android.Widget.Orientation; | ||
|
||
namespace Microsoft.Maui.Handlers | ||
{ | ||
public partial class StepperHandler : AbstractViewHandler<IStepper, LinearLayout>, IStepperHandler | ||
{ | ||
AButton? _downButton; | ||
AButton? _upButton; | ||
|
||
IStepper? IStepperHandler.VirtualView => VirtualView; | ||
|
||
AButton? IStepperHandler.UpButton => _upButton; | ||
|
||
AButton? IStepperHandler.DownButton => _downButton; | ||
|
||
protected override LinearLayout CreateNativeView() | ||
{ | ||
var stepperLayout = new LinearLayout(Context) | ||
{ | ||
Orientation = AOrientation.Horizontal, | ||
Focusable = true, | ||
DescendantFocusability = DescendantFocusability.AfterDescendants | ||
}; | ||
|
||
StepperHandlerManager.CreateStepperButtons(this, out _downButton, out _upButton); | ||
|
||
if (_downButton != null) | ||
stepperLayout.AddView(_downButton, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.MatchParent)); | ||
|
||
if (_upButton != null) | ||
stepperLayout.AddView(_upButton, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.MatchParent)); | ||
|
||
return stepperLayout; | ||
} | ||
|
||
public static void MapMinimum(StepperHandler handler, IStepper stepper) | ||
{ | ||
handler.TypedNativeView?.UpdateMinimum(stepper); | ||
} | ||
|
||
public static void MapMaximum(StepperHandler handler, IStepper stepper) | ||
{ | ||
handler.TypedNativeView?.UpdateMaximum(stepper); | ||
} | ||
|
||
public static void MapIncrement(StepperHandler handler, IStepper stepper) | ||
{ | ||
handler.TypedNativeView?.UpdateIncrement(stepper); | ||
} | ||
|
||
public static void MapValue(StepperHandler handler, IStepper stepper) | ||
{ | ||
handler.TypedNativeView?.UpdateValue(stepper); | ||
} | ||
|
||
AButton IStepperHandler.CreateButton() | ||
{ | ||
if (Context == null) | ||
throw new ArgumentException("Context is null or empty", nameof(Context)); | ||
|
||
var button = new AButton(Context); | ||
button.SetHeight((int)Context.ToPixels(10.0)); | ||
return button; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
|
||
namespace Microsoft.Maui.Handlers | ||
{ | ||
public partial class StepperHandler : AbstractViewHandler<IStepper, object> | ||
{ | ||
protected override object CreateNativeView() => throw new NotImplementedException(); | ||
|
||
public static void MapMinimum(IViewHandler handler, IStepper stepper) { } | ||
public static void MapMaximum(IViewHandler handler, IStepper stepper) { } | ||
public static void MapIncrement(IViewHandler handler, IStepper stepper) { } | ||
public static void MapValue(IViewHandler handler, IStepper stepper) { } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace Microsoft.Maui.Handlers | ||
{ | ||
public partial class StepperHandler | ||
{ | ||
public static PropertyMapper<IStepper, StepperHandler> StepperMapper = new PropertyMapper<IStepper, StepperHandler>(ViewHandler.ViewMapper) | ||
{ | ||
[nameof(IStepper.Minimum)] = MapMinimum, | ||
[nameof(IStepper.Maximum)] = MapMaximum, | ||
[nameof(IStepper.Increment)] = MapIncrement, | ||
[nameof(IStepper.Value)] = MapValue | ||
}; | ||
|
||
public StepperHandler() : base(StepperMapper) | ||
{ | ||
|
||
} | ||
|
||
public StepperHandler(PropertyMapper mapper) : base(mapper ?? StepperMapper) | ||
{ | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Drawing; | ||
using UIKit; | ||
|
||
namespace Microsoft.Maui.Handlers | ||
{ | ||
public partial class StepperHandler : AbstractViewHandler<IStepper, UIStepper> | ||
{ | ||
protected override UIStepper CreateNativeView() | ||
{ | ||
return new UIStepper(RectangleF.Empty); | ||
} | ||
|
||
protected override void ConnectHandler(UIStepper nativeView) | ||
{ | ||
nativeView.ValueChanged += OnValueChanged; | ||
} | ||
|
||
protected override void DisconnectHandler(UIStepper nativeView) | ||
{ | ||
nativeView.ValueChanged -= OnValueChanged; | ||
} | ||
|
||
public static void MapMinimum(StepperHandler handler, IStepper stepper) | ||
{ | ||
handler.TypedNativeView?.UpdateMinimum(stepper); | ||
} | ||
|
||
public static void MapMaximum(StepperHandler handler, IStepper stepper) | ||
{ | ||
handler.TypedNativeView?.UpdateMaximum(stepper); | ||
} | ||
|
||
public static void MapIncrement(StepperHandler handler, IStepper stepper) | ||
{ | ||
handler.TypedNativeView?.UpdateIncrement(stepper); | ||
} | ||
|
||
public static void MapValue(StepperHandler handler, IStepper stepper) | ||
{ | ||
handler.TypedNativeView?.UpdateValue(stepper); | ||
} | ||
|
||
void OnValueChanged(object? sender, EventArgs e) | ||
{ | ||
if (TypedNativeView == null || VirtualView == null) | ||
return; | ||
|
||
VirtualView.Value = TypedNativeView.Value; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using Android.Widget; | ||
using AButton = Android.Widget.Button; | ||
|
||
namespace Microsoft.Maui | ||
{ | ||
public static class StepperExtensions | ||
{ | ||
public static void UpdateMinimum(this LinearLayout linearLayout, IStepper stepper) | ||
{ | ||
UpdateButtons(linearLayout, stepper); | ||
} | ||
|
||
public static void UpdateMaximum(this LinearLayout linearLayout, IStepper stepper) | ||
{ | ||
UpdateButtons(linearLayout, stepper); | ||
} | ||
|
||
public static void UpdateIncrement(this LinearLayout linearLayout, IStepper stepper) | ||
{ | ||
UpdateButtons(linearLayout, stepper); | ||
} | ||
|
||
public static void UpdateValue(this LinearLayout linearLayout, IStepper stepper) | ||
{ | ||
UpdateButtons(linearLayout, stepper); | ||
} | ||
|
||
public static void UpdateIsEnabled(this LinearLayout linearLayout, IStepper stepper) | ||
{ | ||
UpdateButtons(linearLayout, stepper); | ||
} | ||
|
||
internal static void UpdateButtons(this LinearLayout linearLayout, IStepper stepper) | ||
{ | ||
AButton? downButton = null; | ||
AButton? upButton = null; | ||
|
||
for (int i = 0; i < linearLayout?.ChildCount; i++) | ||
{ | ||
var childButton = linearLayout.GetChildAt(i) as AButton; | ||
|
||
if (childButton?.Text == "-") | ||
downButton = childButton; | ||
|
||
if (childButton?.Text == "+") | ||
upButton = childButton; | ||
} | ||
|
||
StepperHandlerManager.UpdateButtons(stepper, downButton, upButton); | ||
} | ||
} | ||
} |
Oops, something went wrong.