From f522de0d27163e5e3c6b21f822a49f84f6e89d8b Mon Sep 17 00:00:00 2001 From: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com> Date: Thu, 30 Jul 2020 11:32:49 -0700 Subject: [PATCH] [iOS] Fixes text input plugin crash (flutter/engine#20127) --- .../framework/Source/FlutterTextInputPlugin.mm | 4 ++-- .../framework/Source/FlutterTextInputPluginTest.m | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm index a135c4fcc7..1e04170da2 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm @@ -387,8 +387,8 @@ static FlutterAutofillType autofillTypeOf(NSDictionary* configuration) { } - (UITextField*)textField { - if (_textField == nil) { - _textField = [[[UITextField alloc] init] autorelease]; + if (!_textField) { + _textField = [[UITextField alloc] init]; } return _textField; } diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.m b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.m index 21b1d1cf5a..7f69a19664 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.m +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.m @@ -17,6 +17,10 @@ FLUTTER_ASSERT_ARC - (BOOL)isVisibleToAutofill; @end +@interface FlutterSecureTextInputView : FlutterTextInputView +@property(nonatomic, strong) UITextField* textField; +@end + @interface FlutterTextInputPlugin () @property(nonatomic, strong) FlutterTextInputView* reusableInputView; @property(nonatomic, assign) FlutterTextInputView* activeView; @@ -496,4 +500,15 @@ FLUTTER_ASSERT_ARC [inputView unmarkText]; XCTAssertEqual(updateCount, 6); } + +- (void)testNoZombies { + // Regression test for https://github.com/flutter/flutter/issues/62501. + FlutterSecureTextInputView* passwordView = [[FlutterSecureTextInputView alloc] init]; + + @autoreleasepool { + // Initialize the lazy textField. + [passwordView.textField description]; + } + XCTAssert([[passwordView.textField description] containsString:@"TextField"]); +} @end