Skip to content

Conversation

3noch
Copy link
Member

@3noch 3noch commented Jul 16, 2020

Some events like touchstart and touchmove behave differently (by default) on different browsers. However, changing the default settings in addEventHandler is not at all straightforward. This PR attempts to solve two problems:

  1. Make it easy to customize options for addEventHandler.
  2. Offer a version of on for DOM events that always normalizes the behavior between browers so there is no discrepancy.

The changes are added in a new Reflex.Dom.Event module. Bikeshed away. Many things in Immediate.hs should probably be moved to this module as well.

@3noch 3noch force-pushed the eac@expose-addEventListener-options branch from d1f7535 to 1dd4cf8 Compare July 16, 2020 22:15
@3noch
Copy link
Member Author

3noch commented Jul 16, 2020

These changes could all go in ghcjs-dom and jsaddle-dom TBH except for the normalization bit.

-- for differences.
normalizedDefaultEventListenerOptions :: EventName t e -> EventListenerOptions
normalizedDefaultEventListenerOptions e = case eventNameString e of
name | name == "touchstart" || name == "touchmove" -> defaultEventListenerOptions { _eventListenerOptions_passive = True }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Downside to this approach is that it's a perf hit to every usage of on

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