Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(ui): stop released scroll flings on input cancellation

yhh3d68aedd74d8
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b179aac25..841db48b9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,8 @@ published separately; it ships inside the editor.
### Fixed
+- **Input cancellation stops released scroll flings.** UI scrolling discards existing coast state when the host cancels input, so a list already gliding after release remains at its current offset when the app resumes. A new press can still start a fresh drag in the same frame.
+
- **Native input resets when the host hides.** The native adapter cancels held touches, mouse buttons, keys and frame edges on hide or input teardown, resets the primary finger, removes its hide subscription and ignores late releases from the previous gesture.
- **Reused touch IDs preserve both gestures.** When a host reuses a touch ID between frames, UI releases the old gesture before capturing the new one, retains quick-tap clicks and projects the held finger's current position for dragging and scrolling.
diff --git a/sdk/src/ui/behavior/plugin.ts b/sdk/src/ui/behavior/plugin.ts
index 3f278072b..b0217d3b0 100644
--- a/sdk/src/ui/behavior/plugin.ts
+++ b/sdk/src/ui/behavior/plugin.ts
@@ -242,6 +242,7 @@ export class UIBehaviorPlugin implements Plugin {
const cancellationVersion = primaryPointerCancellationVersion(input);
const cancelled = cancellationVersion !== lastCancellationVersion;
lastCancellationVersion = cancellationVersion;
+ if (cancelled) dynamics.clear();
if (!camera.valid && !overlay.active) {
activeEntity = pendingEntity = null;
capturedContainer = null;
diff --git a/sdk/tests/ui-scroll-motion-wasm.test.ts b/sdk/tests/ui-scroll-motion-wasm.test.ts
index 49a5092ec..e794ec10b 100644
--- a/sdk/tests/ui-scroll-motion-wasm.test.ts
+++ b/sdk/tests/ui-scroll-motion-wasm.test.ts
@@ -32,6 +32,8 @@ describe.skipIf(!HAS_WASM)('scroll motion ownership on real WASM', () => {
vpW: 100, vpH: 100, screenW: 100, screenH: 100 });
plugin = new UIBehaviorPlugin(); plugin.build(app); flushPendingRegistrations(app);
entity = app.world.spawn(); app.world.insert(entity, UIInteraction, { hovered: true });
+ // Refresh the shared WASM layout cache for this registry before pointer projection.
+ engine.uiLayout_update(registry, -50, -50, 50, 50, true);
});
afterEach(() => { app.quit({ keepRenderer: true }); registry.delete(); });
async function step(y: number) {
@@ -104,4 +106,14 @@ describe.skipIf(!HAS_WASM)('scroll motion ownership on real WASM', () => {
for (let i = 0; i < 10; i++) await step(100);
expect(scroll.getOffset().y).toBe(before);
});
+ it('host input cancellation stops a released fling before the next frame', async () => {
+ const scroll = container(); plugin.attachScrollContainer(entity, scroll); await drag();
+ input.noteMouseUp(0); await step(100); await step(100);
+ const before = scroll.getOffset().y;
+ expect(before).toBeGreaterThan(100);
+ inputEventCallbacks(input).onInputCancel!();
+ takePrimaryPointerCancellation(input);
+ for (let i = 0; i < 10; i++) await step(100);
+ expect(scroll.getOffset().y).toBe(before);
+ });
});
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index 790ff8daf..b885c9ab9 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -28,6 +28,8 @@ export const NOTES_FLOOR = 'v0.65.0';
* the reader recognises anyway.
*/
export const NOTED = {
+ 'fix(ui): stop released scroll flings on input cancellation':
+ { note: 'Input cancellation stops released scroll flings.' },
'fix(input): reset native input when the host hides':
{ note: 'Native input resets when the host hides.' },
'fix(input): preserve gestures when touch IDs are reused':