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

Flutter iOS Interactive Keyboard: Fixing Animation Issue #44514

Merged
merged 3 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
// it is activated.
static constexpr double kUITextInputAccessibilityEnablingDelaySeconds = 0.5;

// A delay before reenabling the UIView areAnimationsEnabled to YES
// in order for becomeFirstResponder to receive the proper value
static const NSTimeInterval kKeyboardAnimationDelaySeconds = 0.1;

// The "canonical" invalid CGRect, similar to CGRectNull, used to
// indicate a CGRect involved in firstRectForRange calculation is
// invalid. The specific value is chosen so that if firstRectForRange
Expand Down Expand Up @@ -2369,8 +2373,13 @@ - (void)dismissKeyboardScreenshot {
- (void)showKeyboardAndRemoveScreenshot {
[UIView setAnimationsEnabled:NO];
[_cachedFirstResponder becomeFirstResponder];
[UIView setAnimationsEnabled:YES];
[self dismissKeyboardScreenshot];
// UIKit does not immediately access the areAnimationsEnabled Boolean so a delay is needed before
// returned
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, kKeyboardAnimationDelaySeconds * NSEC_PER_SEC),
dispatch_get_main_queue(), ^{
[UIView setAnimationsEnabled:YES];
[self dismissKeyboardScreenshot];
});
}

- (void)handlePointerMove:(CGFloat)pointerY {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ - (void)cleanUpViewHierarchy:(BOOL)includeActiveView
- (UIView*)hostView;
- (void)addToInputParentViewIfNeeded:(FlutterTextInputView*)inputView;
- (void)startLiveTextInput;
- (void)showKeyboardAndRemoveScreenshot;

@end

@interface FlutterTextInputPluginTest : XCTestCase
Expand Down Expand Up @@ -2890,5 +2892,25 @@ - (void)testInteractiveKeyboardKeyboardAnimatesToDismissalPositionalOnPointerUp
}];
textInputPlugin.cachedFirstResponder = nil;
}
- (void)testInteractiveKeyboardShowKeyboardAndRemoveScreenshotAnimationIsNotImmediatelyEnable {
[UIView setAnimationsEnabled:YES];
[textInputPlugin showKeyboardAndRemoveScreenshot];
XCTAssertFalse(
UIView.areAnimationsEnabled,
@"The animation should still be disabled following showKeyboardAndRemoveScreenshot");
}

- (void)testInteractiveKeyboardShowKeyboardAndRemoveScreenshotAnimationIsReenabledAfterDelay {
[UIView setAnimationsEnabled:YES];
[textInputPlugin showKeyboardAndRemoveScreenshot];

NSPredicate* predicate = [NSPredicate predicateWithBlock:^BOOL(id item, NSDictionary* bindings) {
// This will be enabled after a delay
return UIView.areAnimationsEnabled;
}];
XCTNSPredicateExpectation* expectation =
[[XCTNSPredicateExpectation alloc] initWithPredicate:predicate object:nil];
[self waitForExpectations:@[ expectation ] timeout:10.0];
}

@end