Skip to content

Commit 1b48c05

Browse files
committed
fix(ios): improve keyboard dismissal to prevent accidental UI interactions
The previous implementation used a swipe down gesture at a fixed screen position (1/3 from top) which could accidentally click on search results or other UI elements that appeared after text input. Changes: - Use WDA's dismissKeyboard API as the primary method (more reliable) - Fall back to safer swipe gesture (from bottom up) if API fails - Increase wait time from 300ms to 500ms for UI stability - Update autoDismissKeyboard documentation to reflect default behavior Technical details: - WDA API tries common keyboard button names: return, done, go, search, etc. - Swipe fallback uses safer coordinates: from 90% height to 50% height - This prevents accidental taps on UI elements in the upper portion of screen Related to #1282
1 parent 27f8d91 commit 1b48c05

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

packages/ios/src/device.ts

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class IOSDevice implements AbstractInterface {
8080
.boolean()
8181
.optional()
8282
.describe(
83-
'If true, the keyboard will be dismissed after the input is completed. Do not set it unless the user asks you to do so.',
83+
'Whether to dismiss the keyboard after input. Defaults to true if not specified. Set to false to keep the keyboard visible after input.',
8484
),
8585
mode: z
8686
.enum(['replace', 'clear', 'append'])
@@ -763,32 +763,42 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
763763

764764
async hideKeyboard(keyNames?: string[]): Promise<boolean> {
765765
try {
766-
// If keyNames are provided, use them instead of manual swipe down
767-
if (keyNames && keyNames.length > 0) {
766+
// Always try WDA's dismissKeyboard API first (most reliable)
767+
// Use common keyboard button names if not specified
768+
const dismissKeys =
769+
keyNames && keyNames.length > 0
770+
? keyNames
771+
: ['return', 'done', 'go', 'search', 'next', 'send'];
772+
773+
debugDevice(
774+
`Attempting to dismiss keyboard using WDA API with keys: ${dismissKeys.join(', ')}`,
775+
);
776+
777+
try {
778+
await this.wdaBackend.dismissKeyboard(dismissKeys);
779+
debugDevice('Successfully dismissed keyboard using WDA API');
780+
await sleep(500); // Wait longer to ensure UI is stable
781+
return true;
782+
} catch (wdaError) {
768783
debugDevice(
769-
`Using keyNames to dismiss keyboard: ${keyNames.join(', ')}`,
784+
`WDA dismissKeyboard failed, falling back to swipe gesture: ${wdaError}`,
770785
);
771-
await this.wdaBackend.dismissKeyboard(keyNames);
772-
debugDevice('Dismissed keyboard using provided keyNames');
773-
await sleep(300);
774-
return true;
775786
}
776787

777-
// Default behavior: Get window size for swipe coordinates
788+
// Fallback: Use swipe gesture if WDA API fails
789+
// Use safer coordinates: swipe up from bottom of screen
778790
const windowSize = await this.wdaBackend.getWindowSize();
779-
780-
// Calculate swipe coordinates at one-third position of the screen
781791
const centerX = Math.round(windowSize.width / 2);
782-
const startY = Math.round(windowSize.height * 0.33); // Start at one-third from top
783-
const endY = Math.round(windowSize.height * 0.33 + 10); // Swipe down
792+
const startY = Math.round(windowSize.height * 0.9); // Start near bottom
793+
const endY = Math.round(windowSize.height * 0.5); // Swipe up to middle
784794

785-
// Perform swipe down gesture to dismiss keyboard
786-
await this.swipe(centerX, startY, centerX, endY, 50);
795+
// Perform swipe up gesture to dismiss keyboard
796+
await this.swipe(centerX, startY, centerX, endY, 300);
787797
debugDevice(
788-
'Dismissed keyboard with swipe down gesture at screen one-third position',
798+
'Dismissed keyboard with swipe up gesture from bottom of screen',
789799
);
790800

791-
await sleep(300);
801+
await sleep(500); // Wait longer to ensure UI is stable
792802
return true;
793803
} catch (error) {
794804
debugDevice(`Failed to hide keyboard: ${error}`);

0 commit comments

Comments
 (0)