Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
FlutterKeyboardInsetManager.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERKEYBOARDINSETMANAGER_H_
6#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERKEYBOARDINSETMANAGER_H_
7
8#import <UIKit/UIKit.h>
9
10@class FlutterEngine;
12
13/**
14 * @brief Manages the calculations and animations for software keyboard insets.
15 *
16 * This class is responsible for observing keyboard notifications, calculating the appropriate
17 * insets for the Flutter view based on the keyboard mode (docked, floating, hidden),
18 * and animating the transition of the insets.
19 */
20@protocol FlutterKeyboardInsetManagerDelegate <NSObject>
21
22/**
23 * @brief Updates the viewport metrics with the new bottom inset.
24 */
25- (void)updateViewportMetricsWithInset:(CGFloat)inset;
26
27/**
28 * @brief Returns the current physical bottom view inset.
29 */
30- (CGFloat)physicalViewInsetBottom;
31
32/**
33 * @brief Returns the view associated with the delegate.
34 */
35- (UIView*)view;
36
37/**
38 * @brief Returns the engine associated with the delegate.
39 */
41
42/**
43 * @brief Returns the UIScreen associated with the Flutter view, if the view is loaded.
44 */
45- (UIScreen*)flutterScreenIfViewLoaded;
46
47/**
48 * @brief Returns whether the device is an iPad and in Slide Over or Stage Manager mode.
49 */
50- (BOOL)isPadInSlideOverOrStageManagerMode;
51
52/**
53 * @brief Converts a rectangle from the view's coordinate system to the screen's coordinate system.
54 */
55- (CGRect)convertViewRectToScreen:(CGRect)rect;
56
57/**
58 * @brief Returns whether the delegate's view is currently loaded.
59 */
60- (BOOL)isViewLoaded;
61
62@end
63
64/**
65 * @brief Coordinates the animation of the bottom viewport inset in response to system keyboard
66 * visibility changes.
67 *
68 * This manager translates native iOS keyboard notifications into pixel insets for the engine. It
69 * ensures that the Flutter app UI correctly resizes or scrolls when the software keyboard appears
70 * or disappears.
71 *
72 * We synchronize the app's layout transitions with the native keyboard animation curve by tracking
73 * a hidden internal view. When a keyboard notification is received, this view is animated using the
74 * native iOS duration and curve. The manager tracks this animation and calls the delegate's update
75 * methods on every vsync pulse until the transition completes.
76 *
77 * iOS doesn't provide us with a frame-by-frame callback for keyboard transitions, but we need to
78 * animate our views smoothly to account for keyboard size/position changes. To ensure Flutter's
79 * layout animates in perfect sync with the system keyboard, we use a "hidden view" synchronization
80 * trick:
81 *
82 * * When a keyboard notification (e.g., UIKeyboardWillShow) is received, the manager animates a
83 * hidden UIView's frame using the native iOS duration and curve.
84 * * A FlutterVSyncClient tracks the 'presentationLayer' of this hidden view on every vsync.
85 * * The intermediate positions are then translated into physical pixel insets and sent to the
86 * engine until the animation completes.
87 *
88 * To prevent incorrect layout shifts, the manager filters notifications based on the following
89 * criteria:
90 *
91 * * Local notifications:
92 * In multitasking environments, such as iPad Split View, notifications triggered by interactions
93 * with other applications are ignored.
94 *
95 * * Keyboard attachment mode:
96 * The manager distinguishes between "docked" keyboards, which cover the bottom of the viewport,
97 * and "floating" or "undocked" keyboards. Floating keyboards do not typically require a viewport
98 * inset and are ignored to allow them to hover over the Flutter content without resizing the
99 * layout.
100 *
101 * * View lifecycle:
102 * Notifications are ignored if the associated view is not loaded or if the delegate is not the
103 * active view controller.
104 *
105 * @see [FlutterViewController], which owns this manager and acts as its delegate.
106 */
107@interface FlutterKeyboardInsetManager : NSObject
108
109/**
110 * @brief Initializes the manager with a delegate.
111 *
112 * The manager maintains a weak reference to the delegate.
113 *
114 * @param delegate The object that handles viewport updates. Typically a [FlutterViewController].
115 */
116- (instancetype)initWithDelegate:(id<FlutterKeyboardInsetManagerDelegate>)delegate;
117
118/**
119 * @brief Processes a system keyboard notification to update the target inset and begin any
120 * necessary animations.
121 *
122 * Consider calling this method from the view controller's keyboard notification observers. It
123 * automatically performs filtering for non-local or floating keyboard events.
124 *
125 * @param notification The notification received from the [NSNotificationCenter].
126 */
127- (void)handleKeyboardNotification:(NSNotification*)notification;
128
129/**
130 * @brief Immediately stops any active keyboard animations and synchronizes the engine's viewport
131 * metrics with a zero inset.
132 */
134
135/**
136 * @brief Terminates any active animations and releases internal resources.
137 *
138 * Consider calling this method when the owner of the manager is being deallocated.
139 */
140- (void)invalidate;
141
142/**
143 * @brief The physical pixel value of the bottom inset once the current animation reaches its final
144 * state.
145 */
146@property(nonatomic, assign, readonly) CGFloat targetViewInsetBottom;
147
148/**
149 * @brief Indicates whether the keyboard is currently onscreen or in the process of transitioning
150 * from the background.
151 */
153
154@end
155
156#endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERKEYBOARDINSETMANAGER_H_
FlutterEngine engine
Definition main.cc:84
FlView * view
Coordinates the animation of the bottom viewport inset in response to system keyboard visibility chan...
void invalidate()
Terminates any active animations and releases internal resources.
CGFloat targetViewInsetBottom
The physical pixel value of the bottom inset once the current animation reaches its final state.
BOOL isKeyboardInOrTransitioningFromBackground
Indicates whether the keyboard is currently onscreen or in the process of transitioning from the back...
void hideKeyboardImmediately()
Immediately stops any active keyboard animations and synchronizes the engine's viewport metrics with ...
int BOOL