Skip to content

Commit cef825e

Browse files
committed
refactor(android): pass the measured occlusion explicitly and drop the duplicate rect check
The clip rule already fails open on a keyboard frame it cannot measure, so the helper reader no longer needs its own copy of the check, and the gesture-viewport validator goes back to its original body. The refusal names its three numbers instead of spreading the clip variant, so the discriminator never leaks into error details.
1 parent 2b5e358 commit cef825e

3 files changed

Lines changed: 16 additions & 16 deletions

File tree

‎packages/platform-android/src/gesture-viewport.ts‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ export type AndroidGestureViewportReading = Readonly<{
1818
}>;
1919

2020
export function validateAndroidGestureViewport(viewport: Rect): Rect {
21-
if (!isMeasurableRect(viewport))
21+
if (
22+
!Number.isFinite(viewport.x) ||
23+
!Number.isFinite(viewport.y) ||
24+
!Number.isFinite(viewport.width) ||
25+
!Number.isFinite(viewport.height) ||
26+
viewport.width <= 0 ||
27+
viewport.height <= 0
28+
)
2229
throw new AppError('COMMAND_FAILED', 'Android helper returned an invalid gesture viewport');
2330
return viewport;
2431
}
25-
26-
export function isMeasurableRect(rect: Rect): boolean {
27-
return (
28-
[rect.x, rect.y, rect.width, rect.height].every((value) => Number.isFinite(value)) &&
29-
rect.width > 0 &&
30-
rect.height > 0
31-
);
32-
}

‎packages/platform-android/src/input-actions.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ function resolveAndroidScrollSurface(
251251
const clip = clipScrollViewportAboveKeyboard(viewport, keyboard);
252252
if (clip.kind === 'occluded') {
253253
throw scrollKeyboardOccludesSurfaceError(direction, {
254-
...clip,
254+
keyboardMinY: clip.keyboardMinY,
255+
visibleHeight: clip.visibleHeight,
255256
viewportHeight: viewport.height,
256257
});
257258
}

‎packages/platform-android/src/touch-helper.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
readInstrumentationResultNumber,
1616
} from './instrumentation-helper.ts';
1717
import {
18-
isMeasurableRect,
1918
validateAndroidGestureViewport,
2019
type AndroidGestureViewportReading,
2120
} from './gesture-viewport.ts';
@@ -348,7 +347,11 @@ function readViewportResult(record: Record<string, string>): AndroidGestureViewp
348347
};
349348
}
350349

351-
/** Absence of any keyboard key is the helper's way of saying no input method window is on screen. */
350+
/**
351+
* Absence of any keyboard key is the helper's way of saying no input method window is on screen.
352+
* The frame is not validated here: the shared clip rule fails open on one it cannot measure, and a
353+
* helper that cannot size the IME must not fail every scroll.
354+
*/
352355
function readKeyboardResult(record: Record<string, string>): Rect | undefined {
353356
const x = readInstrumentationResultNumber(record.keyboardX);
354357
const y = readInstrumentationResultNumber(record.keyboardY);
@@ -357,8 +360,5 @@ function readKeyboardResult(record: Record<string, string>): Rect | undefined {
357360
if (x === undefined || y === undefined || width === undefined || height === undefined) {
358361
return undefined;
359362
}
360-
// An IME window the helper cannot size is dropped, not refused: the clip rule already fails open
361-
// on a missing frame, and a helper that cannot see it must not fail every scroll.
362-
const keyboard = { x, y, width, height };
363-
return isMeasurableRect(keyboard) ? keyboard : undefined;
363+
return { x, y, width, height };
364364
}

0 commit comments

Comments
 (0)