Flutter iOS Embedder
FlutterKeyCallbackGuard Class Reference
Inheritance diagram for FlutterKeyCallbackGuard:

Instance Methods

(nonnull instancetype) - initWithCallback:
 
(void) - pendTo:withId:
 
(void) - resolveTo:
 

Properties

BOOL handled
 
NSString * debugHandleSource
 

Detailed Description

Guards a |FlutterAsyncKeyCallback| to make sure it's handled exactly once throughout the process of handling an event in |FlutterEmbedderKeyResponder|.

A callback can either be handled with |pendTo:withId:|, or with |resolveTo:|. Either way, the callback cannot be handled again, or an assertion will be thrown.

Definition at line 287 of file FlutterEmbedderKeyResponder.mm.

Method Documentation

◆ initWithCallback:

- (nonnull instancetype) initWithCallback: (FlutterAsyncKeyCallback callback
Initial value:

Definition at line 316 of file FlutterEmbedderKeyResponder.mm.

316  :(FlutterAsyncKeyCallback)callback {
317  self = [super init];
318  if (self != nil) {
319  _callback = [callback copy];
320  _handled = FALSE;
321  }
322  return self;
323 }

◆ pendTo:withId:

- (void) pendTo: (nonnull NSMutableDictionary<NSNumber*, FlutterAsyncKeyCallback>*)  pendingResponses
withId: (uint64_t)  responseId 

Handle the callback by storing it to pending responses.

Definition at line 325 of file FlutterEmbedderKeyResponder.mm.

325  :(nonnull NSMutableDictionary<NSNumber*, FlutterAsyncKeyCallback>*)pendingResponses
326  withId:(uint64_t)responseId {
327  NSAssert(!_handled, @"This callback has been handled by %@.", _debugHandleSource);
328  if (_handled) {
329  return;
330  }
331  pendingResponses[@(responseId)] = _callback;
332  _handled = TRUE;
333  NSAssert(
334  ((_debugHandleSource = [NSString stringWithFormat:@"pending event %llu", responseId]), TRUE),
335  @"");
336 }

◆ resolveTo:

- (void) resolveTo: (BOOL)  handled

Handle the callback by calling it with a result.

Definition at line 338 of file FlutterEmbedderKeyResponder.mm.

338  :(BOOL)handled {
339  NSAssert(!_handled, @"This callback has been handled by %@.", _debugHandleSource);
340  if (_handled) {
341  return;
342  }
343  _callback(handled);
344  _handled = TRUE;
345  NSAssert(((_debugHandleSource = [NSString stringWithFormat:@"resolved with %d", _handled]), TRUE),
346  @"");
347 }

Property Documentation

◆ debugHandleSource

- (NSString*) debugHandleSource
readatomiccopy

A string indicating how the callback is handled.

Only set in debug mode. Nil in release mode, or if the callback has not been handled.

Definition at line 308 of file FlutterEmbedderKeyResponder.mm.

◆ handled

- (BOOL) handled
readwritenonatomicassign

Definition at line 301 of file FlutterEmbedderKeyResponder.mm.


The documentation for this class was generated from the following file:
FlutterKeyCallbackGuard::handled
BOOL handled
Definition: FlutterEmbedderKeyResponder.mm:301
FlutterAsyncKeyCallback
void(^ FlutterAsyncKeyCallback)(BOOL handled)
Definition: FlutterKeyPrimaryResponder.h:10