[forms-devel] Offer to provide press and release events on Button

Kangho Hur rookiejava at gmail.com
Tue Aug 16 12:13:08 UTC 2016


Hi,

I'm writing to discuss about "Pressed" and "Released" events on Button. I
believe that it is useful to application developers who want to detect when
a button is first pressed and ends when it is released. These events work
across platforms (android, iOS and UWP).

In android, users can use OnTouchListener.onTouch(View v, MotionEvent
event) as following.
  button.setOnTouchListener(new OnTouchListener() {
     @Override
     public boolean onTouch(View v, MotionEvent event) {
        if(event.getAction() == MotionEvent.ACTION_DOWN) {
          // Pressed
        } else if (event.getAction() == MotionEvent.ACTION_UP) {
          // Released
        }
    }
};

In iOS, we can use addTarget:action:forControlEvents: method in UIControl
class as below.
  [button addTarget:self
action:@selector(buttonDown):forControlEvents:UIControlEventTouchDown];
// Pressed
  [button addTarget:self action:@selector(buttonUp):
forControlEvents:UIControlEventTouchUpInside]; // Released

In UWP, as you may already know, there is Click event and ClickMode
property in ButtonBase class.
<Button x:Name="btn1" Content="Press to Click" Click="OnClick1"
ClickMode="Press"/>
<Button x:Name="btn2" Content="Release to Click" Click="OnClick2"
ClickMode="Release"/>

I could do a PR for

a) Adding the Button.Pressed and Button.Released events. (In this case,
events occur in the following order. pressed -> released -> clicked)

or

b) Adding the Button.ClickMode (Press/Release) property similar to UWP way.

or

c) Adding a new GestureRecognizer (e.g. TouchGestureRecognizer).

What do you prefer? Or, any other suggestions?

Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dot.net/pipermail/forms-devel/attachments/20160816/75d7293c/attachment.html>


More information about the forms-devel mailing list