Skip to content

Commit

Permalink
Handler staging (#547)
Browse files Browse the repository at this point in the history
* TimePicker Handlers (#454)

* TimePickerHandlers

* Undo changes in sample

* Add some nullability fixes

* Fix build error

* Changes from PR feedback

* Fixed build error

* Updated tests

* Roll time picker and popup into one control

* Move 24 hour view check to handler

* Pull NSLocale -> CultureInfo code out to common property

Co-authored-by: E.Z. Hart <hartez@users.noreply.github.com>
Co-authored-by: E.Z. Hart <hartez@gmail.com>

* CheckBoxHandlers (#432)

* Rename ICheck -> ICheckBox, remove Color stuff (to be replaced with Brush
later), fix DeviceTests

* Implement CharacterSpacing property in EditorHandlers (#516)

* Fix broken test and incorrect CharacterSpacing on iOS

* Implement HorizontalTextAlignment property in EntryHandlers (#524)

* Better text on example

* Remove IView from ITextAlignment

* Remove IView from IPlaceholder

* Implement IsTextPredictionEnabled property on Editor (#515)

* Initial implementation

* Added Tests

* Added PortHandler Attributes

* Added Tests

* Handle turning text prediction back on

Co-authored-by: E.Z. Hart <hartez@gmail.com>

* Implement ReturnType property in EntryHandlers (#518)

* Implement CharacterSpacing property in SearchBarHandlers (#494)

* Implement CharacterSpacing in SearchBarHandlers

* Tests failing because of static

* Rounding for Android

* Fix iOS test

* There! No magic numbers!

* Fix rebase issuse and make SearchBar stuff work on iOS

Co-authored-by: Matthew Leibowitz <mattleibow@live.com>
Co-authored-by: E.Z. Hart <hartez@gmail.com>

* Stepper Handlers (#517)

* StepperHandlers

* Fixed Stepper handler broken tests

* Remove duplicate searchbar

* Add IStepper interface

Co-authored-by: E.Z. Hart <hartez@gmail.com>

* IStepper.Increment -> IStepper.Step

* Picker Handlers (#433)

* PickerHandlers

* Nullability fixes

* Updated Picker device tests

* New things in the tests!

* Removed unnecessary Android Api level validation

* Added Picker Items null validation in iOS PickerHandler

* Moved Picker Handler tests between different classes

* Renamed NativePicker to MauiPicker

* Removed unused code from iOS PickerExtensions

* Fix build error

* Fix build error

* Remove duplicate class

Co-authored-by: Matthew Leibowitz <mattleibow@live.com>
Co-authored-by: E.Z. Hart <hartez@gmail.com>

* ActivityIndicator Handlers (#417)

* ActivityIndicatorHandler

* Register IActivityIndicator

* Add comments to IActivityIndicator

* Fix build error

* Implement Font properties in SearchBarHandlers (#533)

* Speed up PR builds (#510)

Reduce the jobs and use the new pools

* implement Font properties in SearchBarHandlers

* Fix rebase issues

Co-authored-by: Matthew Leibowitz <mattleibow@live.com>
Co-authored-by: E.Z. Hart <hartez@gmail.com>

* Implemented LineHeight on Label (#538)

* Implemented LineHeight on Label (#368)

* Fix-up after rebase

Co-authored-by: E.Z. Hart <hartez@gmail.com>

* Fix broken label tests; add some missing label tests; attributed string cleanup

* Consolidate and rename extension method classes

* Fix class names and de-duplicate methods

* Centralize time extensions

* Fix mapping

Co-authored-by: Javier Suárez <javiersuarezruiz@hotmail.com>
Co-authored-by: Glenn Hevey <glenn.hevey@gmail.com>
Co-authored-by: Matthew Leibowitz <mattleibow@live.com>
Co-authored-by: Amr <hassaninamr@yahoo.com>
  • Loading branch information
5 people committed Mar 18, 2021
1 parent 2922521 commit 25e6476
Show file tree
Hide file tree
Showing 165 changed files with 4,017 additions and 255 deletions.
Expand Up @@ -29,6 +29,7 @@ public class CheckBoxRendererBase :
IPlatformElementConfiguration<PlatformConfiguration.Android, CheckBox> _platformElementConfiguration;
CheckBox _checkBox;

[PortHandler]
static int[][] _checkedStates = new int[][]
{
new int[] { AAttribute.StateEnabled, AAttribute.StateChecked },
Expand Down Expand Up @@ -185,6 +186,7 @@ void IOnCheckedChangeListener.OnCheckedChanged(CompoundButton buttonView, bool i
((IElementController)Element).SetValueFromRenderer(CheckBox.IsCheckedProperty, isChecked);
}

[PortHandler]
void UpdateIsChecked()
{
if (Element == null || Control == null)
Expand All @@ -210,6 +212,7 @@ protected virtual ColorStateList GetColorStateList()
return list;
}

[PortHandler]
void UpdateBackgroundColor()
{
if (Element.BackgroundColor == Color.Default)
Expand All @@ -225,6 +228,7 @@ void UpdateBackground()
this.UpdateBackground(background);
}

[PortHandler]
void UpdateOnColor()
{
if (Element == null || Control == null)
Expand Down
Expand Up @@ -109,6 +109,7 @@ protected override void OnFocusChangeRequested(object sender, VisualElement.Focu
}
}

[PortHandler("Partially ported, still missing code related to TitleColor, etc.")]
void IPickerRenderer.OnClick()
{
Picker model = Element;
Expand Down Expand Up @@ -168,6 +169,7 @@ protected void UpdateCharacterSpacing()
}
}

[PortHandler("Partially ported, still missing code related to TitleColor, etc.")]
void UpdatePicker()
{
UpdatePlaceHolderText();
Expand Down
Expand Up @@ -4,7 +4,7 @@ namespace Microsoft.Maui.Controls.Compatibility.Platform.Android
{
internal static class EntryRendererExtensions
{

[PortHandler]
internal static ImeAction ToAndroidImeAction(this ReturnType returnType)
{
switch (returnType)
Expand Down
Expand Up @@ -12,6 +12,7 @@ public ActivityIndicatorRenderer(Context context) : base(context)
AutoPackage = false;
}

[PortHandler]
protected override AProgressBar CreateNativeControl()
{
return new AProgressBar(Context) { Indeterminate = true };
Expand Down Expand Up @@ -42,6 +43,7 @@ protected override void OnElementPropertyChanged(object sender, PropertyChangedE
UpdateColor();
}

[PortHandler]
void UpdateColor()
{
if (Element == null || Control == null)
Expand All @@ -55,6 +57,7 @@ void UpdateColor()
Control.IndeterminateDrawable?.ClearColorFilter();
}

[PortHandler]
void UpdateVisibility()
{
if (Element == null || Control == null)
Expand Down
Expand Up @@ -216,6 +216,7 @@ protected virtual void UpdateFont()
EditText.SetTextSize(ComplexUnitType.Sp, (float)Element.FontSize);
}

[PortHandler("Partially Ported")]
void UpdateInputType()
{
Editor model = Element;
Expand Down Expand Up @@ -243,6 +244,7 @@ void UpdateInputType()
}
}

[PortHandler]
void UpdateCharacterSpacing()
{
if (Forms.IsLollipopOrNewer)
Expand Down
2 changes: 2 additions & 0 deletions src/Compatibility/Core/src/Android/Renderers/EntryRenderer.cs
Expand Up @@ -298,6 +298,7 @@ protected virtual void UpdateImeOptions()
EditText.ImeOptions = _currentInputImeFlag;
}

[PortHandler]
void UpdateHorizontalTextAlignment()
{
EditText.UpdateTextAlignment(Element.HorizontalTextAlignment, Element.VerticalTextAlignment);
Expand Down Expand Up @@ -396,6 +397,7 @@ void UpdateCharacterSpacing()
}
}

[PortHandler]
void UpdateReturnType()
{
if (Control == null || Element == null)
Expand Down
Expand Up @@ -248,6 +248,7 @@ void UpdateCharacterSpacing()
}
}

[PortHandler]
void UpdateLineHeight()
{
_lastSizeRequest = null;
Expand Down
Expand Up @@ -233,6 +233,7 @@ void ClearFocus(SearchView view)
view.ClearFocus();
}

[PortHandler]
void UpdateFont()
{
_editText = _editText ?? Control.GetChildrenOfType<EditText>().FirstOrDefault();
Expand Down Expand Up @@ -264,6 +265,7 @@ void UpdateText()
Control.SetQuery(text, false);
}

[PortHandler]
void UpdateCharacterSpacing()
{
if (!Forms.IsLollipopOrNewer)
Expand Down
Expand Up @@ -16,6 +16,7 @@ public StepperRenderer(Context context) : base(context)
AutoPackage = false;
}

[PortHandler]
protected override LinearLayout CreateNativeControl()
{
return new LinearLayout(Context)
Expand All @@ -26,6 +27,7 @@ protected override LinearLayout CreateNativeControl()
};
}

[PortHandler]
protected override void OnElementChanged(ElementChangedEventArgs<Stepper> e)
{
base.OnElementChanged(e);
Expand Down
Expand Up @@ -16,6 +16,7 @@ public abstract class TimePickerRendererBase<TControl> : ViewRenderer<TimePicker
AlertDialog _dialog;
bool _disposed;

[PortHandler]
bool Is24HourView
{
get => (DateFormat.Is24HourFormat(Context) && Element.Format == (string)TimePicker.FormatProperty.DefaultValue) || Element.Format?.Contains('H') == true;
Expand Down Expand Up @@ -154,6 +155,7 @@ void OnCancelButtonClicked(object sender, EventArgs e)
Element.Unfocus();
}

[PortHandler]
void SetTime(TimeSpan time)
{
if (String.IsNullOrEmpty(Element.Format))
Expand Down
Expand Up @@ -5,6 +5,7 @@

namespace Microsoft.Maui.Controls.Compatibility.Platform.Android
{
[PortHandler]
public static class StepperRendererManager
{
public static void CreateStepperButtons<TButton>(IStepperRenderer renderer, out TButton downButton, out TButton upButton)
Expand Down
17 changes: 9 additions & 8 deletions src/Compatibility/Core/src/AppHostBuilderExtensions.cs
Expand Up @@ -11,14 +11,15 @@ public static IAppHostBuilder RegisterCompatibilityRenderers(this IAppHostBuilde
// This won't really be a thing once we have all the handlers built
var defaultHandlers = new List<Type>
{
typeof(Button) ,
typeof(Editor),
typeof(Entry) ,
typeof(ContentPage) ,
typeof(Page) ,
typeof(Label) ,
typeof(Slider),
typeof(Switch)
typeof(Button) ,
typeof(Editor),
typeof(Entry) ,
typeof(ContentPage) ,
typeof(Page) ,
typeof(Label) ,
typeof(Slider),
typeof(Stepper),
typeof(Switch)
};

Forms.RegisterCompatRenderers(
Expand Down
1 change: 1 addition & 0 deletions src/Compatibility/Core/src/iOS/Extensions/Extensions.cs
Expand Up @@ -111,6 +111,7 @@ internal static UISearchBarStyle ToNativeSearchBarStyle(this PlatformConfigurati
}
}

[PortHandler]
internal static UIReturnKeyType ToUIReturnKeyType(this ReturnType returnType)
{
switch (returnType)
Expand Down
Expand Up @@ -5,6 +5,7 @@

namespace Microsoft.Maui.Controls.Compatibility.Platform.iOS
{
[PortHandler]
public sealed class UIActivityIndicatorViewDelegate : UIActivityIndicatorView
{
ActivityIndicator _element;
Expand Down Expand Up @@ -40,6 +41,7 @@ public ActivityIndicatorRenderer()

}

[PortHandler]
protected override void OnElementChanged(ElementChangedEventArgs<ActivityIndicator> e)
{
if (e.NewElement != null)
Expand Down Expand Up @@ -69,11 +71,13 @@ protected override void OnElementPropertyChanged(object sender, PropertyChangedE
UpdateIsRunning();
}

[PortHandler]
void UpdateColor()
{
Control.Color = Element.Color == Color.Default ? null : Element.Color.ToUIColor();
}

[PortHandler]
void UpdateIsRunning()
{
if (Control?.Superview == null)
Expand Down
Expand Up @@ -121,6 +121,7 @@ protected override void OnElementChanged(ElementChangedEventArgs<CheckBox> e)
base.OnElementChanged(e);
}

[PortHandler]
protected virtual void UpdateTintColor()
{
if (Element == null)
Expand All @@ -129,6 +130,7 @@ protected virtual void UpdateTintColor()
Control.CheckBoxTintColor = Element.Color;
}

[PortHandler]
void OnControlCheckedChanged(object sender, EventArgs e)
{
Element.IsChecked = Control.IsChecked;
Expand Down
2 changes: 2 additions & 0 deletions src/Compatibility/Core/src/iOS/Renderers/EditorRenderer.cs
Expand Up @@ -70,6 +70,7 @@ protected internal override void UpdatePlaceholderText()
_placeholderLabel.SizeToFit();
}

[PortHandler("Partially ported")]
protected internal override void UpdateCharacterSpacing()
{
var textAttr = TextView.AttributedText.AddCharacterSpacing(Element.Text, Element.CharacterSpacing);
Expand Down Expand Up @@ -305,6 +306,7 @@ protected internal virtual void UpdateFont()
TextView.Font = font;
}

[PortHandler("Partially Ported")]
void UpdateKeyboard()
{
var keyboard = Element.Keyboard;
Expand Down
2 changes: 2 additions & 0 deletions src/Compatibility/Core/src/iOS/Renderers/EntryRenderer.cs
Expand Up @@ -257,6 +257,7 @@ protected virtual bool OnShouldReturn(UITextField view)
return false;
}

[PortHandler]
void UpdateHorizontalTextAlignment()
{
Control.TextAlignment = Element.HorizontalTextAlignment.ToNativeTextAlignment(((IVisualElementController)Element).EffectiveFlowDirection);
Expand Down Expand Up @@ -401,6 +402,7 @@ bool ShouldChangeCharacters(UITextField textField, NSRange range, string replace
return newLength <= Element?.MaxLength;
}

[PortHandler]
void UpdateReturnType()
{
if (Control == null || Element == null)
Expand Down
1 change: 1 addition & 0 deletions src/Compatibility/Core/src/iOS/Renderers/FormsCheckBox.cs
Expand Up @@ -4,6 +4,7 @@

namespace Microsoft.Maui.Controls.Compatibility.Platform.iOS
{
[PortHandler("NativeCheckBox")]
public class FormsCheckBox : UIButton
{
static UIImage _checked;
Expand Down
1 change: 1 addition & 0 deletions src/Compatibility/Core/src/iOS/Renderers/LabelRenderer.cs
Expand Up @@ -431,6 +431,7 @@ void UpdateCharacterSpacing()
_perfectSizeValid = false;
}

[PortHandler("Partially. Mapped LineHeight")]
void UpdateText()
{
if (IsElementOrControlEmpty)
Expand Down
7 changes: 7 additions & 0 deletions src/Compatibility/Core/src/iOS/Renderers/PickerRenderer.cs
Expand Up @@ -11,6 +11,7 @@

namespace Microsoft.Maui.Controls.Compatibility.Platform.iOS
{
[PortHandler]
internal class ReadOnlyField : NoCaretField
{
readonly HashSet<string> enableActions;
Expand All @@ -32,6 +33,7 @@ public PickerRenderer()

}

[PortHandler]
protected override UITextField CreateNativeControl()
{
return new ReadOnlyField { BorderStyle = UITextBorderStyle.RoundedRect };
Expand All @@ -56,6 +58,8 @@ public PickerRendererBase()
}

protected abstract override TControl CreateNativeControl();

[PortHandler("Partially ported, still missing code related to TitleColor, etc.")]
protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
{
if (e.OldElement != null)
Expand Down Expand Up @@ -231,6 +235,7 @@ protected internal virtual void UpdatePlaceholder()
protected virtual void UpdateAttributedPlaceholder(NSAttributedString nsAttributedString) =>
Control.AttributedPlaceholder = nsAttributedString;

[PortHandler]
void UpdatePicker()
{
var selectedIndex = Element.SelectedIndex;
Expand Down Expand Up @@ -266,6 +271,7 @@ void UpdatePickerNativeSize(string oldText)
((IVisualElementController)Element).NativeSizeChanged();
}

[PortHandler]
void UpdatePickerSelectedIndex(int formsIndex)
{
var source = (PickerSource)_picker.Model;
Expand Down Expand Up @@ -334,6 +340,7 @@ protected override void Dispose(bool disposing)
base.Dispose(disposing);
}

[PortHandler]
class PickerSource : UIPickerViewModel
{
PickerRendererBase<TControl> _renderer;
Expand Down
2 changes: 2 additions & 0 deletions src/Compatibility/Core/src/iOS/Renderers/SearchBarRenderer.cs
Expand Up @@ -226,6 +226,7 @@ void OnTextChanged(object sender, UISearchBarTextChangedEventArgs a)
UpdateOnTextChanged();
}

[PortHandler("The code related to Placeholder remains to be ported")]
void UpdateCharacterSpacing()
{
_textField = _textField ?? Control.FindDescendantView<UITextField>();
Expand Down Expand Up @@ -290,6 +291,7 @@ public virtual void UpdateCancelButton()
}
}

[PortHandler]
void UpdateFont()
{
_textField = _textField ?? Control.FindDescendantView<UITextField>();
Expand Down
5 changes: 5 additions & 0 deletions src/Compatibility/Core/src/iOS/Renderers/StepperRenderer.cs
Expand Up @@ -65,26 +65,31 @@ protected override void OnElementPropertyChanged(object sender, PropertyChangedE
UpdateIncrement();
}

[PortHandler]
void OnValueChanged(object sender, EventArgs e)
{
((IElementController)Element).SetValueFromRenderer(Stepper.ValueProperty, Control.Value);
}

[PortHandler]
void UpdateIncrement()
{
Control.StepValue = Element.Increment;
}

[PortHandler]
void UpdateMaximum()
{
Control.MaximumValue = Element.Maximum;
}

[PortHandler]
void UpdateMinimum()
{
Control.MinimumValue = Element.Minimum;
}

[PortHandler]
void UpdateValue()
{
if (Control.Value != Element.Value)
Expand Down

0 comments on commit 25e6476

Please sign in to comment.