From: Kangho Date: Thu, 2 Feb 2017 18:23:31 +0000 (+0900) Subject: Add pressed and released events to Button (#446) X-Git-Tag: accepted/tizen/common/20170324.122620~109 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b50a12b136ef17b0bf46103821481d92ec3b2dae;p=platform%2Fupstream%2Fxamarin-forms.git Add pressed and released events to Button (#446) * Add pressed and released events to Button * Update ButtonRenderer.cs * Apply safely casting to android button renderer * Use safety casting for Android buttin renderer * [Windows] Fix modal pages being laid out below soft buttons (#395) * Add sample HanselForms and TwitterDemo to ControlGallery (#651) * [Controls] Add Hanselforms sample * Remove extra twitter sample * [Controls]Add TwitterDemo sample * [Controls] Fix build * Slider should show user-set value on initial load (#378) * [UWP] Use toolbar foreground color on primary items (#640) * Avoid duplicating code in OmPlatform (#591) * [iOS] Entry should not pass a newline to the next responder (#397) * UITextField should not return so that the next field does not get passed a newline * Added code sample * [XamlC] import members on x:Static and factories (#642) * [Xaml] support short Properties for PropertyCondition (#645) * Xamlc compile data triggers (#648) * [Xaml] DataTrigger and PropertyCondition no longer use a ServiceProvider * [XamlC] avoid generating ServiceProvider for unused ProvideValue * fix tests * Fix comment typo * [UWP] Fix TextBox style for foreground focus color (#618) * Adding image to use for CellsGalleryImageUrlCellList UI test * Update ImageCellListPage to use an image we control; Update CellsGalleryImageUrlCellList test to wait longer than 1s for images to load if necessary * fix nre when changing content in datepickerselected (#494) * Make CellsGalleryImageUrlCellList test finish early if possible * [iOS] Change keyboard type while keyboard is visible (#443) * Change keyboard while changing text * add sample code * [Android] Fix NavigationPage dispose crash when it parents a MasterDetailPage (#577) * fix navigation page dispose crash * changes after review * [XamlC] detect duplicate x:Name at compile time (#655) * [XamlC] detect duplicate x:Name at compile time * invoking methods with the right arguments produces better results * Make UWP toolbar display rules consistent with other platforms (#638) * Allow subscriber to be collected if MessagingCenter is the only reference to it (#617) * Repro * Make messaging center callbacks weak references * Preserve attribute * Fix test method name * Watch for collection of actual delegate target instead of wrapper delegate * Preserve the original platform instance when changing main page * Better tests for lambda situations * Update tests, make callback target a weakreference if it's the subscriber * Ensure old Platform MessagingCenter subs are gone before creating new Platform * [iOS] Prevent multiple ListView cells from being swiped simultaneously (#578) * disable multiple cell swipe * add sample code * refactored * convert to weakreference * remove null setting * change weakreference setting place * remove if * revert isopen changes * add instructions * [WinRT/UWP] Apply BackgroundColor to Stepper buttons (#581) * [WinRT/UWP] Apply BackgroundColor to Stepper buttons * Add explanatory text; use nameof * Move explanatory text to a label * Return group instead of internal class (#461) * [iOS/Android] Move Map camera to correct region on layout change (#548) * Move to region on layout change * remove visibility check * [iOS] Platform specifics for controlling Picker SelectedIndex change behavior (#540) * picker selected index could change when picker view is dismissed * use enum * [iOS] Ignore intermittent failing test on XTC (#666) * [UITest] Update to UITest 2.0.5 (#665) * Rebase the current branch onto upstream latest --- diff --git a/Xamarin.Forms.Core.UnitTests/ButtonUnitTest.cs b/Xamarin.Forms.Core.UnitTests/ButtonUnitTest.cs index d590f8c..eef9dfc 100644 --- a/Xamarin.Forms.Core.UnitTests/ButtonUnitTest.cs +++ b/Xamarin.Forms.Core.UnitTests/ButtonUnitTest.cs @@ -35,7 +35,7 @@ namespace Xamarin.Forms.Core.UnitTests } [Test] - public void TestTappedEvent () + public void TestClickedvent () { var view = new Button (); @@ -47,6 +47,32 @@ namespace Xamarin.Forms.Core.UnitTests Assert.True (activated); } + [Test] + public void TestPressedEvent () + { + var view = new Button(); + + bool pressed = false; + view.Pressed += (sender, e) => pressed = true; + + ((IButtonController)view).SendPressed(); + + Assert.True(pressed); + } + + [Test] + public void TestReleasedEvent () + { + var view = new Button(); + + bool released = false; + view.Released += (sender, e) => released = true; + + ((IButtonController)view).SendReleased(); + + Assert.True(released); + } + protected override Button CreateSource() { return new Button(); diff --git a/Xamarin.Forms.Core/Button.cs b/Xamarin.Forms.Core/Button.cs index 97d774c..bcd593e 100644 --- a/Xamarin.Forms.Core/Button.cs +++ b/Xamarin.Forms.Core/Button.cs @@ -116,13 +116,18 @@ namespace Xamarin.Forms void IButtonController.SendClicked() { - ICommand cmd = Command; - if (cmd != null) - cmd.Execute(CommandParameter); + Command?.Execute(CommandParameter); + Clicked?.Invoke(this, EventArgs.Empty); + } - EventHandler handler = Clicked; - if (handler != null) - handler(this, EventArgs.Empty); + void IButtonController.SendPressed() + { + Pressed?.Invoke(this, EventArgs.Empty); + } + + void IButtonController.SendReleased() + { + Released?.Invoke(this, EventArgs.Empty); } public FontAttributes FontAttributes @@ -146,6 +151,10 @@ namespace Xamarin.Forms public event EventHandler Clicked; + public event EventHandler Pressed; + + public event EventHandler Released; + public Button() { _platformConfigurationRegistry = new Lazy>(() => new PlatformConfigurationRegistry