Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 6239bfb

Browse files
authored
Add a message when a key response takes too long. (#31945)
This splits the nested event loop in the keyboard manager on iOS into two parts: The first times out after 2 seconds, and if that happens, prints an NSLog indicating that the framework took a long time to respond, and then it enters the event loop again, waiting forever this time. This means the behavior doesn't change from what it is now, but will log when things take a long time.
1 parent 6cac347 commit 6239bfb

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

shell/platform/darwin/ios/framework/Source/FlutterKeyboardManager.mm

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "flutter/fml/platform/darwin/message_loop_darwin.h"
88

99
static constexpr CFTimeInterval kDistantFuture = 1.0e10;
10+
static constexpr CFTimeInterval kReasonableInterval = 2.0;
1011

1112
@interface FlutterKeyboardManager ()
1213

@@ -114,7 +115,14 @@ - (void)handlePress:(nonnull FlutterUIPressProxy*)press
114115
//
115116
// We need to run in this mode so that UIKit doesn't give us new
116117
// events until we are done processing this one.
117-
CFRunLoopRunInMode(fml::MessageLoopDarwin::kMessageLoopCFRunLoopMode, kDistantFuture, NO);
118+
CFRunLoopRunResult result = CFRunLoopRunInMode(
119+
fml::MessageLoopDarwin::kMessageLoopCFRunLoopMode, kReasonableInterval, NO);
120+
if (result == kCFRunLoopRunTimedOut) {
121+
NSLog(@"Flutter framework failed to process a key event in a reasonable time. Continuing "
122+
@"to wait.");
123+
CFRunLoopRunInMode(fml::MessageLoopDarwin::kMessageLoopCFRunLoopMode, kDistantFuture, NO);
124+
NSLog(@"Flutter framework finally responded. Exiting nested event loop.");
125+
}
118126
break;
119127
}
120128
case UIPressPhaseChanged:

0 commit comments

Comments
 (0)