Skip to content

Conversation

@aneteanetes
Copy link

TL;DR

For now Myra handle events from controls from 'outer' to 'nested', i.e.:

  1. Desktop
  2. Panel
  3. Button
  4. Image

In this PR i added event-bubbling strategy. With this strategy events fires in this order:

  1. Image
  2. Button
  3. Panel
  4. Desktop

Event queing does not changed.

EventHandlingStrategy

public static EventHandlingStrategy EventHandlingModel { get; set; } = EventHandlingStrategy.EventCapturing;

Myra env now have EventHandlingStrategy property, wich default value is Myra.Events.EventHandlingStrategy.EventCapturing, which means, behaiour is same as previously.

Event-bubbling

In this RP i added option Myra.Events.EventHandlingStrategy.EventBubbling, which changes behaviour for 'from nested to outer'. If you set env for event-bubbling:

MyraEnvironment.EventHandlingModel = Myra.Events.EventHandlingStrategy.EventBubbling;

All events will be captured as usually, but will fire in 'reverse' order.

Propagation stopping

This option allows to stop fire next events (regardless of event handling strategy) and can be run from new class MyraEventArgs for prevent next events of the same type raise:

btn.TouchDown += (s, e) =>
{
    action.OnClick(); // do logic
    e.StopPropagation(); // prevent Parents from raising 'TouchDown' event
};

MyraEventArgs

For ability to use StopPropagation() only for same event type, i changed EventArgs and all its derivatives uses to MyraEventArgs and MyraEventHandler(T).

This allows detect event type inside user-defined event handler (for StopPropagation) but has significant implications for existed code bases.

Tests

Tests didn't added, but all current is passed.

* added EventBubbling strategy
* EventArgs changed to MyraEventArgs for support EventType and custom behaviour
* added StopPropagation() method for event handlers (works only with EventBubbling strategy)
@aneteanetes
Copy link
Author

TextBox control works wrong with EventHandlingStrategy.EventBubbling, and needs special fixes, may be as other controls which depend on EventHandlingStrategy.EventCapturing strategy.

* TextBox event bubbling fix
@aneteanetes
Copy link
Author

TextBox and ComboView controls fixed and now work as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant