mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
When Flutter web runs embedded in a page, scrolling by dragging is interrupted very early by the browser. It turns out that our `pointer` events receive a `pointercancel` + `pointerleave` by the browser because they happen in an area (the flutter glasspane) that is not really scrollable. [See documentation](https://developer.mozilla.org/en-US/docs/Web/API/Element/pointercancel_event). > [!NOTE] > After the pointercancel event is fired, the browser will also send [pointerout](https://developer.mozilla.org/en-US/docs/Web/API/Element/pointerout_event) followed by [pointerleave](https://developer.mozilla.org/en-US/docs/Web/API/Element/pointerleave_event). (Firefox is a good browser to test this, because the browser will cancel our events **only if there's scrollable areas around the embedded flutter app**.) There's several solutions, but one of them (used by PixiJS as well) is to cancel the `touchstart` event that fires with the `pointerdown` event. (This PR also removes an unnecessary call to `addEventListener` in the `Listener` helper class, and adds some testing to it). ## Testing * Added a happy case test for the fix (preventDefault on 'touchstart' events) * Deployed demo app here: https://dit-multiview-scroll.web.app ## Issues * Fixes https://github.com/flutter/flutter/issues/138985 * Fixes https://github.com/flutter/flutter/issues/146732 * Related to https://github.com/flutter/flutter/issues/139263 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style