未验证 提交 9a0b553c 编写于 作者: W Wu Zhong 提交者: GitHub

[iOS] Fixes crash of TextInputView when Flutter deallocated (#25070)

上级 8c112c61
......@@ -1234,6 +1234,30 @@ static FlutterAutofillType autofillTypeOf(NSDictionary* configuration) {
@end
@interface FlutterTextInputPlugin ()
- (void)enableActiveViewAccessibility;
@end
@interface FlutterTimerProxy : NSObject
@property(nonatomic, assign) FlutterTextInputPlugin* target;
@end
@implementation FlutterTimerProxy
+ (instancetype)proxyWithTarget:(FlutterTextInputPlugin*)target {
FlutterTimerProxy* proxy = [[self new] autorelease];
if (proxy) {
proxy.target = target;
}
return proxy;
}
- (void)enableActiveViewAccessibility {
[self.target enableActiveViewAccessibility];
}
@end
@interface FlutterTextInputPlugin ()
@property(nonatomic, strong) FlutterTextInputView* reusableInputView;
......@@ -1266,6 +1290,7 @@ static FlutterAutofillType autofillTypeOf(NSDictionary* configuration) {
- (void)dealloc {
[self hideTextInput];
_activeView.textInputDelegate = nil;
[_reusableInputView release];
[_activeView release];
[_inputHider release];
......@@ -1344,15 +1369,15 @@ static FlutterAutofillType autofillTypeOf(NSDictionary* configuration) {
if (!_enableFlutterTextInputViewAccessibilityTimer) {
_enableFlutterTextInputViewAccessibilityTimer =
[[NSTimer scheduledTimerWithTimeInterval:kUITextInputAccessibilityEnablingDelaySeconds
target:self
selector:@selector(enableActiveViewAccessibility:)
target:[FlutterTimerProxy proxyWithTarget:self]
selector:@selector(enableActiveViewAccessibility)
userInfo:nil
repeats:NO] retain];
}
[_activeView becomeFirstResponder];
}
- (void)enableActiveViewAccessibility:(NSTimer*)time {
- (void)enableActiveViewAccessibility {
if (_activeView.isFirstResponder) {
_activeView.accessibilityEnabled = YES;
}
......
......@@ -240,6 +240,18 @@ FLUTTER_ASSERT_ARC
XCTAssert([[passwordView.textField description] containsString:@"TextField"]);
}
- (void)testInputViewCrash {
FlutterTextInputView* activeView = nil;
@autoreleasepool {
FlutterTextInputPlugin* inputPlugin = [FlutterTextInputPlugin new];
activeView = inputPlugin.activeView;
FlutterEngine* flutterEngine = [[FlutterEngine alloc] init];
activeView.textInputDelegate = (id<FlutterTextInputDelegate>)flutterEngine;
}
XCTAssert(!activeView.textInputDelegate);
[activeView updateEditingState];
}
- (void)ensureOnlyActiveViewCanBecomeFirstResponder {
for (FlutterTextInputView* inputView in self.installedInputViews) {
XCTAssertEqual(inputView.canBecomeFirstResponder, inputView == textInputPlugin.activeView);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册