From 2159f63e32f14494c8b5cb982731795805b99394 Mon Sep 17 00:00:00 2001 From: Matt2D Date: Tue, 8 Aug 2023 17:05:01 -0400 Subject: [PATCH 1/3] Fix animation bug caused by lack of delay --- .../Source/FlutterTextInputPlugin.mm | 8 +++++-- .../Source/FlutterTextInputPluginTest.mm | 22 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm index c263b37f961d4..7d90951a3407f 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm @@ -2369,8 +2369,12 @@ - (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, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ + [UIView setAnimationsEnabled:YES]; + [self dismissKeyboardScreenshot]; + }); } - (void)handlePointerMove:(CGFloat)pointerY { diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm index d34101397ec61..edc95d8b3b4be 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm @@ -75,6 +75,8 @@ - (void)cleanUpViewHierarchy:(BOOL)includeActiveView - (UIView*)hostView; - (void)addToInputParentViewIfNeeded:(FlutterTextInputView*)inputView; - (void)startLiveTextInput; +- (void)showKeyboardAndRemoveScreenshot; + @end @interface FlutterTextInputPluginTest : XCTestCase @@ -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 From 5efae032dfaf7eabac17f3b62421fd2ec3ffb617 Mon Sep 17 00:00:00 2001 From: Matt2D Date: Wed, 9 Aug 2023 11:40:11 -0400 Subject: [PATCH 2/3] Updated Constant --- .../ios/framework/Source/FlutterTextInputPlugin.mm | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm index 7d90951a3407f..0b80916159f8c 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm @@ -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 recieve 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 @@ -2371,10 +2375,11 @@ - (void)showKeyboardAndRemoveScreenshot { [_cachedFirstResponder becomeFirstResponder]; // UIKit does not immediately access the areAnimationsEnabled Boolean so a delay is needed before // returned - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ - [UIView setAnimationsEnabled:YES]; - [self dismissKeyboardScreenshot]; - }); + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, kKeyboardAnimationDelaySeconds * NSEC_PER_SEC), + dispatch_get_main_queue(), ^{ + [UIView setAnimationsEnabled:YES]; + [self dismissKeyboardScreenshot]; + }); } - (void)handlePointerMove:(CGFloat)pointerY { From f256bb8956644b96b0b15004076ea16a06739f3c Mon Sep 17 00:00:00 2001 From: Matt2D Date: Wed, 9 Aug 2023 12:56:59 -0400 Subject: [PATCH 3/3] Correcting Spelling Mistake --- .../darwin/ios/framework/Source/FlutterTextInputPlugin.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm index 0b80916159f8c..a4fb7a04d82f4 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm @@ -22,7 +22,7 @@ static constexpr double kUITextInputAccessibilityEnablingDelaySeconds = 0.5; // A delay before reenabling the UIView areAnimationsEnabled to YES -// in order for becomeFirstResponder to recieve the proper value +// in order for becomeFirstResponder to receive the proper value static const NSTimeInterval kKeyboardAnimationDelaySeconds = 0.1; // The "canonical" invalid CGRect, similar to CGRectNull, used to