2727
2828NSNotificationName const FlutterViewControllerWillDealloc = @" FlutterViewControllerWillDealloc" ;
2929
30- // / Class to coalesce calls for a period of time.
31- // /
32- // / This is used to filter out the conflicting notifications that can get sent
33- // / in rapid succession when the app gets foregrounded.
34- @interface FlutterCoalescer : NSObject
35- @property (nonatomic , assign ) BOOL isTriggered;
36- @property (nonatomic , assign ) BOOL isCoalescing;
37- @property (nonatomic , copy ) dispatch_block_t block;
38- @end
39-
40- @implementation FlutterCoalescer
41- - (instancetype )initWithBlock : (dispatch_block_t )block {
42- self = [super init ];
43- if (self) {
44- self.block = block;
45- }
46- return self;
47- }
48-
49- - (void )dealloc {
50- [_block release ];
51- [super dealloc ];
52- }
53-
54- - (void )trigger {
55- if (_isCoalescing) {
56- _isTriggered = YES ;
57- } else {
58- _isTriggered = NO ;
59- if (_block) {
60- _block ();
61- }
62- }
63- }
64-
65- - (void )coalesceForSeconds : (double )seconds {
66- if (self.isCoalescing || !self.block ) {
67- return ;
68- }
69- self.isCoalescing = YES ;
70- dispatch_after (dispatch_time (DISPATCH_TIME_NOW, seconds * NSEC_PER_SEC),
71- dispatch_get_main_queue (), ^{
72- if (self.isTriggered && self.block ) {
73- self.block ();
74- }
75- self.isTriggered = NO ;
76- self.isCoalescing = NO ;
77- });
78- }
79-
80- - (void )invalidate {
81- self.block = nil ;
82- }
83-
84- @end // FlutterCoalescer
85-
8630// This is left a FlutterBinaryMessenger privately for now to give people a chance to notice the
8731// change. Unfortunately unless you have Werror turned on, incompatible pointers as arguments are
8832// just a warning.
@@ -120,9 +64,6 @@ @implementation FlutterViewController {
12064 BOOL _viewOpaque;
12165 BOOL _engineNeedsLaunch;
12266 NSMutableSet <NSNumber *>* _ongoingTouches;
123- // Coalescer that filters out superfluous keyboard notifications when the app
124- // is being foregrounded.
125- fml::scoped_nsobject<FlutterCoalescer> _updateViewportMetrics;
12667}
12768
12869@synthesize displayingFlutterUI = _displayingFlutterUI;
@@ -206,11 +147,6 @@ - (void)performCommonViewControllerInitialization {
206147 _statusBarStyle = UIStatusBarStyleDefault;
207148
208149 [self setupNotificationCenterObservers ];
209-
210- __block FlutterViewController* blockSelf = self;
211- _updateViewportMetrics.reset ([[FlutterCoalescer alloc ] initWithBlock: ^{
212- [blockSelf updateViewportMetricsImplementation ];
213- }]);
214150}
215151
216152- (FlutterEngine*)engine {
@@ -595,7 +531,6 @@ - (void)dealloc {
595531 userInfo: nil ];
596532 [[NSNotificationCenter defaultCenter ] removeObserver: self ];
597533 [_ongoingTouches release ];
598- [_updateViewportMetrics invalidate ];
599534 [super dealloc ];
600535}
601536
@@ -622,7 +557,6 @@ - (void)applicationDidEnterBackground:(NSNotification*)notification {
622557- (void )applicationWillEnterForeground : (NSNotification *)notification {
623558 TRACE_EVENT0 (" flutter" , " applicationWillEnterForeground" );
624559 [self goToApplicationLifecycle: @" AppLifecycleState.inactive" ];
625- [_updateViewportMetrics coalesceForSeconds: 0.5 ];
626560}
627561
628562// Make this transition only while this current view controller is visible.
@@ -807,13 +741,6 @@ - (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event {
807741#pragma mark - Handle view resizing
808742
809743- (void )updateViewportMetrics {
810- [_updateViewportMetrics trigger ];
811- }
812-
813- // / The direct implementation of updateViewportMetrics, it doesn't conform to
814- // / the coalescing logic when foregrounding the app. Most calls should be
815- // / directed to [updateViewportMetrics].
816- - (void )updateViewportMetricsImplementation {
817744 [_engine.get () updateViewportMetrics: _viewportMetrics];
818745}
819746
@@ -837,7 +764,7 @@ - (void)viewDidLayoutSubviews {
837764 _viewportMetrics.physical_height = viewSize.height * scale;
838765
839766 [self updateViewportPadding ];
840- [self updateViewportMetricsImplementation ];
767+ [self updateViewportMetrics ];
841768
842769 // This must run after updateViewportMetrics so that the surface creation tasks are queued after
843770 // the viewport metrics update tasks.
0 commit comments