Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't extract native defaults, meaning users can no longer reset a color back to a platform theme #1485

Merged
merged 2 commits into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ public partial class ActivityIndicatorHandler : ViewHandler<IActivityIndicator,
Style = UI.Xaml.Application.Current.Resources["MauiActivityIndicatorStyle"] as UI.Xaml.Style
};

protected override void SetupDefaults(MauiActivityIndicator nativeView)
void SetupDefaults(MauiActivityIndicator nativeView)
{
_foregroundDefault = nativeView.GetForegroundCache();

base.SetupDefaults(nativeView);
}

public static void MapIsRunning(ActivityIndicatorHandler handler, IActivityIndicator activityIndicator)
Expand Down
4 changes: 1 addition & 3 deletions src/Core/src/Handlers/Button/ButtonHandler.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected override AppCompatButton CreateNativeView()
return nativeButton;
}

protected override void SetupDefaults(AppCompatButton nativeView)
void SetupDefaults(AppCompatButton nativeView)
{
DefaultPadding = new Thickness(
nativeView.PaddingLeft,
Expand All @@ -34,8 +34,6 @@ protected override void SetupDefaults(AppCompatButton nativeView)
nativeView.PaddingBottom);

DefaultBackground = nativeView.Background;

base.SetupDefaults(nativeView);
}

protected override void ConnectHandler(AppCompatButton nativeView)
Expand Down
4 changes: 1 addition & 3 deletions src/Core/src/Handlers/Button/ButtonHandler.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ public partial class ButtonHandler : ViewHandler<IButton, MauiButton>
protected override MauiButton CreateNativeView()
=> new MauiButton();

protected override void SetupDefaults(MauiButton nativeView)
void SetupDefaults(MauiButton nativeView)
{
DefaultPadding = (UI.Xaml.Thickness)MauiWinUIApplication.Current.Resources["ButtonPadding"];
DefaultForeground = (UI.Xaml.Media.Brush)MauiWinUIApplication.Current.Resources["ButtonForegroundThemeBrush"];
DefaultBackground = (UI.Xaml.Media.Brush)MauiWinUIApplication.Current.Resources["ButtonBackgroundThemeBrush"];

base.SetupDefaults(nativeView);
}

protected override void ConnectHandler(MauiButton nativeView)
Expand Down
4 changes: 1 addition & 3 deletions src/Core/src/Handlers/Button/ButtonHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@ protected override void DisconnectHandler(UIButton nativeView)
base.DisconnectHandler(nativeView);
}

protected override void SetupDefaults(UIButton nativeView)
void SetupDefaults(UIButton nativeView)
{
ButtonTextColorDefaultNormal = nativeView.TitleColor(UIControlState.Normal);
ButtonTextColorDefaultHighlighted = nativeView.TitleColor(UIControlState.Highlighted);
ButtonTextColorDefaultDisabled = nativeView.TitleColor(UIControlState.Disabled);

base.SetupDefaults(nativeView);
}

public static void MapText(ButtonHandler handler, IButton button)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ protected override MauiDatePicker CreateNativeView()
return mauiDatePicker;
}

protected override void SetupDefaults(MauiDatePicker nativeView)
void SetupDefaults(MauiDatePicker nativeView)
{
_defaultBackground = nativeView.Background;
_defaultTextColors = nativeView.TextColors;

base.SetupDefaults(nativeView);

}

internal DatePickerDialog? DatePickerDialog { get { return _dialog; } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ protected override void DisconnectHandler(CalendarDatePicker nativeView)
nativeView.DateChanged -= DateChanged;
}

protected override void SetupDefaults(CalendarDatePicker nativeView)
void SetupDefaults(CalendarDatePicker nativeView)
{
_defaultForeground = nativeView.Foreground;

base.SetupDefaults(nativeView);

}

public static void MapFormat(DatePickerHandler handler, IDatePicker datePicker)
Expand Down
4 changes: 1 addition & 3 deletions src/Core/src/Handlers/DatePicker/DatePickerHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,9 @@ protected override void DisconnectHandler(MauiDatePicker nativeView)
base.DisconnectHandler(nativeView);
}

protected override void SetupDefaults(MauiDatePicker nativeView)
void SetupDefaults(MauiDatePicker nativeView)
{
_defaultTextColor = nativeView.TextColor;

base.SetupDefaults(nativeView);
}

public static void MapFormat(DatePickerHandler handler, IDatePicker datePicker)
Expand Down
7 changes: 0 additions & 7 deletions src/Core/src/Handlers/Defaults.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/Core/src/Handlers/Editor/EditorHandler.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ protected override void DisconnectHandler(AppCompatEditText nativeView)
FocusChangeListener.Handler = null;
}

protected override void SetupDefaults(AppCompatEditText nativeView)
void SetupDefaults(AppCompatEditText nativeView)
{
base.SetupDefaults(nativeView);


DefaultTextColors = nativeView.TextColors;
DefaultPlaceholderTextColors = nativeView.HintTextColors;
Expand Down
4 changes: 2 additions & 2 deletions src/Core/src/Handlers/Editor/EditorHandler.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ protected override void DisconnectHandler(MauiTextBox nativeView)
nativeView.LostFocus -= OnLostFocus;
}

protected override void SetupDefaults(MauiTextBox nativeView)
void SetupDefaults(MauiTextBox nativeView)
{
_placeholderDefaultBrush = nativeView.PlaceholderForeground;
_defaultPlaceholderColorFocusBrush = nativeView.PlaceholderForegroundFocusBrush;

base.SetupDefaults(nativeView);

}

public static void MapText(EditorHandler handler, IEditor editor)
Expand Down
14 changes: 0 additions & 14 deletions src/Core/src/Handlers/Element/ElementHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ public abstract partial class ElementHandler : IElementHandler
{
};

protected abstract bool HasSetDefaults { get; set; }

protected PropertyMapper _mapper;
protected readonly PropertyMapper _defaultMapper;

Expand Down Expand Up @@ -54,13 +52,6 @@ public virtual void SetVirtualView(IElement view)
ConnectHandler(NativeView);
}

if (!HasSetDefaults)
{
SetupDefaults(NativeView);

HasSetDefaults = true;
}

_mapper = _defaultMapper;

if (VirtualView is IPropertyMapperView imv)
Expand Down Expand Up @@ -89,11 +80,6 @@ public virtual void UpdateValue(string property)
object CreateNativeElement() =>
OnCreateNativeElement();

private protected abstract void OnSetupDefaults(object nativeView);

void SetupDefaults(object nativeView) =>
OnSetupDefaults(nativeView);

private protected abstract void OnConnectHandler(object nativeView);

void ConnectHandler(object nativeView) =>
Expand Down
14 changes: 0 additions & 14 deletions src/Core/src/Handlers/Element/ElementHandlerOfT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public abstract partial class ElementHandler<TVirtualView, TNativeView> : Elemen
[HotReload.OnHotReload]
internal static void OnHotReload()
{
Defaults<ElementHandler<TVirtualView, TNativeView>>.HasSetDefaults = false;
}

protected ElementHandler(PropertyMapper mapper)
Expand All @@ -33,18 +32,8 @@ public new TVirtualView VirtualView

object? IElementHandler.NativeView => base.NativeView;

protected override bool HasSetDefaults
{
get => Defaults<ElementHandler<TVirtualView, TNativeView>>.HasSetDefaults;
set => Defaults<ElementHandler<TVirtualView, TNativeView>>.HasSetDefaults = value;
}

protected abstract TNativeView CreateNativeElement();

protected virtual void SetupDefaults(TNativeView nativeView)
{
}

protected virtual void ConnectHandler(TNativeView nativeView)
{
}
Expand All @@ -56,9 +45,6 @@ protected virtual void DisconnectHandler(TNativeView nativeView)
private protected override object OnCreateNativeElement() =>
CreateNativeElement();

private protected override void OnSetupDefaults(object nativeView) =>
SetupDefaults((TNativeView)nativeView);

private protected override void OnConnectHandler(object nativeView) =>
ConnectHandler((TNativeView)nativeView);

Expand Down
4 changes: 2 additions & 2 deletions src/Core/src/Handlers/Entry/EntryHandler.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ protected override void DisconnectHandler(AppCompatEditText nativeView)
ActionListener.Handler = null;
}

protected override void SetupDefaults(AppCompatEditText nativeView)
void SetupDefaults(AppCompatEditText nativeView)
{
base.SetupDefaults(nativeView);


ClearButtonDrawable = GetClearButtonDrawable();
DefaultTextColors = nativeView.TextColors;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/src/Handlers/Entry/EntryHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected override void DisconnectHandler(MauiTextField nativeView)
nativeView.ShouldChangeCharacters -= OnShouldChangeCharacters;
}

protected override void SetupDefaults(MauiTextField nativeView)
void SetupDefaults(MauiTextField nativeView)
{
DefaultTextColor = nativeView.TextColor;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/src/Handlers/Label/LabelHandler.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public partial class LabelHandler : ViewHandler<ILabel, TextView>

protected override TextView CreateNativeView() => new TextView(Context);

protected override void SetupDefaults(TextView nativeView)
void SetupDefaults(TextView nativeView)
{
if (nativeView.TextColors == null)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Core/src/Handlers/Picker/PickerHandler.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ protected override void DisconnectHandler(MauiPicker nativeView)
base.DisconnectHandler(nativeView);
}

protected override void SetupDefaults(MauiPicker nativeView)
void SetupDefaults(MauiPicker nativeView)
{
base.SetupDefaults(nativeView);


DefaultBackground = nativeView.Background;
DefaultTitleColors = nativeView.HintTextColors;
Expand Down
4 changes: 2 additions & 2 deletions src/Core/src/Handlers/Picker/PickerHandler.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ protected override void DisconnectHandler(MauiComboBox nativeView)
nativeView.SelectionChanged -= OnControlSelectionChanged;
}

protected override void SetupDefaults(MauiComboBox nativeView)
void SetupDefaults(MauiComboBox nativeView)
{
_defaultForeground = nativeView.Foreground;

base.SetupDefaults(nativeView);

}
void Reload()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Core/src/Handlers/SearchBar/SearchBarHandler.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ protected override SearchView CreateNativeView()
return searchView;
}

protected override void SetupDefaults(SearchView nativeView)
void SetupDefaults(SearchView nativeView)
{
DefaultBackground = nativeView.Background;

base.SetupDefaults(nativeView);

}

// This is a Android-specific mapping
Expand Down
4 changes: 2 additions & 2 deletions src/Core/src/Handlers/SearchBar/SearchBarHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected override void DisconnectHandler(UISearchBar nativeView)
base.DisconnectHandler(nativeView);
}

protected override void SetupDefaults(UISearchBar nativeView)
void SetupDefaults(UISearchBar nativeView)
{
_defaultTextColor = QueryEditor?.TextColor;

Expand All @@ -60,7 +60,7 @@ protected override void SetupDefaults(UISearchBar nativeView)
_cancelButtonTextColorDefaultDisabled = cancelButton.TitleColor(UIControlState.Disabled);
}

base.SetupDefaults(nativeView);

}

public static void MapText(SearchBarHandler handler, ISearchBar searchBar)
Expand Down
2 changes: 1 addition & 1 deletion src/Core/src/Handlers/Slider/SliderHandler.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected override void DisconnectHandler(SeekBar nativeView)
nativeView.SetOnSeekBarChangeListener(null);
}

protected override void SetupDefaults(SeekBar nativeView)
void SetupDefaults(SeekBar nativeView)
{
DefaultThumbColorFilter = nativeView.Thumb?.GetColorFilter();
DefaultProgressTintMode = nativeView.ProgressTintMode;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/src/Handlers/Slider/SliderHandler.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected override void DisconnectHandler(MauiSlider nativeView)
_pointerReleasedHandler = null;
}

protected override void SetupDefaults(MauiSlider nativeView)
void SetupDefaults(MauiSlider nativeView)
{
DefaultForegroundColor = nativeView.Foreground;
DefaultBackgroundColor = nativeView.Background;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/src/Handlers/Slider/SliderHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected override void DisconnectHandler(UISlider nativeView)
nativeView.RemoveTarget(OnTouchUpControlEvent, UIControlEvent.TouchUpInside | UIControlEvent.TouchUpOutside);
}

protected override void SetupDefaults(UISlider nativeView)
void SetupDefaults(UISlider nativeView)
{
DefaultMinTrackColor = nativeView.MinimumTrackTintColor;
DefaultMaxTrackColor = nativeView.MaximumTrackTintColor;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/src/Handlers/Switch/SwitchHandler.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected override void DisconnectHandler(ASwitch nativeView)
nativeView.SetOnCheckedChangeListener(null);
}

protected override void SetupDefaults(ASwitch nativeView)
void SetupDefaults(ASwitch nativeView)
{
DefaultTrackColorStateList = nativeView.GetDefaultSwitchTrackColorStateList();
DefaultThumbColorStateList = nativeView.GetDefaultSwitchThumbColorStateList();
Expand Down
2 changes: 1 addition & 1 deletion src/Core/src/Handlers/Switch/SwitchHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected override void DisconnectHandler(UISwitch nativeView)
nativeView.ValueChanged -= OnControlValueChanged;
}

protected override void SetupDefaults(UISwitch nativeView)
void SetupDefaults(UISwitch nativeView)
{
DefaultOnTrackColor = UISwitch.Appearance.OnTintColor;
DefaultOffTrackColor = nativeView.GetOffTrackColor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ protected override MauiTimePicker CreateNativeView()
return _timePicker;
}

protected override void SetupDefaults(MauiTimePicker nativeView)
void SetupDefaults(MauiTimePicker nativeView)
{
DefaultBackground = nativeView.Background;

base.SetupDefaults(nativeView);

}

protected override void DisconnectHandler(MauiTimePicker nativeView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ protected override void DisconnectHandler(TimePicker nativeView)
nativeView.TimeChanged -= OnControlTimeChanged;
}

protected override void SetupDefaults(TimePicker nativeView)
void SetupDefaults(TimePicker nativeView)
{
_defaultForeground = nativeView.Foreground;

base.SetupDefaults(nativeView);

}

public static void MapFormat(TimePickerHandler handler, ITimePicker timePicker)
Expand Down
5 changes: 0 additions & 5 deletions src/Core/src/Handlers/View/ViewHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,6 @@ public bool HasContainer
OnCreateNativeView();

#if !NETSTANDARD
private protected abstract void OnSetupDefaults(NativeView nativeView);

private protected sealed override void OnSetupDefaults(object nativeView) =>
OnSetupDefaults((NativeView)nativeView);

private protected abstract void OnConnectHandler(NativeView nativeView);

partial void ConnectingHandler(NativeView? nativeView);
Expand Down
Loading