This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bring ImageButton API additions in line with current code (#4328)
* Bring ImageButton API additions in line with current code * [Core] putting things in better places * [Core] first round of changes * fix issue with checking if bindable properties are set
- Loading branch information
Showing
22 changed files
with
477 additions
and
455 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
using System; | ||
using System.Windows.Input; | ||
using Xamarin.Forms.Internals; | ||
|
||
namespace Xamarin.Forms | ||
{ | ||
static class ButtonElement | ||
{ | ||
public static readonly BindableProperty CommandProperty = BindableProperty.Create(nameof(IButtonElement.Command), typeof(ICommand), typeof(IButtonElement), null, propertyChanging: OnCommandChanging, propertyChanged: OnCommandChanged); | ||
|
||
public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create(nameof(IButtonElement.CommandParameter), typeof(object), typeof(IButtonElement), null, | ||
propertyChanged: (bindable, oldvalue, newvalue) => CommandCanExecuteChanged(bindable, EventArgs.Empty)); | ||
|
||
static void OnCommandChanged(BindableObject bo, object o, object n) | ||
{ | ||
IButtonElement button = (IButtonElement)bo; | ||
if (n is ICommand newCommand) | ||
newCommand.CanExecuteChanged += button.OnCommandCanExecuteChanged; | ||
|
||
CommandChanged(button); | ||
} | ||
|
||
static void OnCommandChanging(BindableObject bo, object o, object n) | ||
{ | ||
IButtonElement button = (IButtonElement)bo; | ||
if (o != null) | ||
{ | ||
(o as ICommand).CanExecuteChanged -= button.OnCommandCanExecuteChanged; | ||
} | ||
} | ||
|
||
public const string PressedVisualState = "Pressed"; | ||
|
||
public static void CommandChanged(IButtonElement sender) | ||
{ | ||
if (sender.Command != null) | ||
{ | ||
CommandCanExecuteChanged(sender, EventArgs.Empty); | ||
} | ||
else | ||
{ | ||
sender.IsEnabledCore = true; | ||
} | ||
} | ||
|
||
public static void CommandCanExecuteChanged(object sender, EventArgs e) | ||
{ | ||
IButtonElement ButtonElementManager = (IButtonElement)sender; | ||
ICommand cmd = ButtonElementManager.Command; | ||
if (cmd != null) | ||
{ | ||
ButtonElementManager.IsEnabledCore = cmd.CanExecute(ButtonElementManager.CommandParameter); | ||
} | ||
} | ||
|
||
public static void ElementClicked(VisualElement visualElement, IButtonElement ButtonElementManager) | ||
{ | ||
if (visualElement.IsEnabled == true) | ||
{ | ||
ButtonElementManager.Command?.Execute(ButtonElementManager.CommandParameter); | ||
ButtonElementManager.PropagateUpClicked(); | ||
} | ||
} | ||
|
||
public static void ElementPressed(VisualElement visualElement, IButtonElement ButtonElementManager) | ||
{ | ||
if (visualElement.IsEnabled == true) | ||
{ | ||
ButtonElementManager.SetIsPressed(true); | ||
visualElement.ChangeVisualStateInternal(); | ||
ButtonElementManager.PropagateUpPressed(); | ||
} | ||
} | ||
|
||
public static void ElementReleased(VisualElement visualElement, IButtonElement ButtonElementManager) | ||
{ | ||
if (visualElement.IsEnabled == true) | ||
{ | ||
IButtonController buttonController = ButtonElementManager as IButtonController; | ||
ButtonElementManager.SetIsPressed(false); | ||
visualElement.ChangeVisualStateInternal(); | ||
ButtonElementManager.PropagateUpReleased(); | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.