Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate iOS text input plugin to use ARC #38179

Merged
merged 5 commits into from
Dec 15, 2022

Conversation

LongCatIsLooong
Copy link
Contributor

Extracted from #38044

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@LongCatIsLooong LongCatIsLooong force-pushed the ios-text-input-arc2 branch 2 times, most recently from 11571ce to 441a66f Compare December 12, 2022 05:35
@property(nonatomic, readonly) id<FlutterTextInputDelegate> textInputDelegate;
@property(nonatomic, readonly) UIView* hostView;
@end

@interface FlutterTextInputView ()
@property(nonatomic, readonly) FlutterTextInputPlugin* textInputPlugin;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be weak?

@@ -725,6 +722,7 @@ - (void)setEditableTransform:(NSArray*)matrix;
@end

@implementation FlutterTextInputView {
__weak FlutterTextInputPlugin* _textInputPlugin;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate ivar? (already in property)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits: prefer using property.

// The active view will be decommissioned and removed from its superview too, if
// includeActiveView is YES.
// The active view will be removed from its superview too, if includeActiveView is
// YES.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: merge lines

@LongCatIsLooong LongCatIsLooong marked this pull request as ready for review December 14, 2022 21:48
Copy link
Contributor

@hellohuanlin hellohuanlin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM. Just a question on decommissioned in case of behavior change by accident.

@@ -30,8 +29,8 @@ typedef NS_ENUM(NSInteger, FlutterScribbleInteractionStatus) {
@interface FlutterTextInputPlugin
: NSObject <FlutterKeySecondaryResponder, UIIndirectScribbleInteractionDelegate>

@property(nonatomic, assign) UIViewController* viewController;
@property(nonatomic, assign) id<FlutterIndirectScribbleDelegate> indirectScribbleDelegate;
@property(nonatomic, weak) UIViewController* viewController;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does flutter view controller retains the FlutterTextInputPlugin (opposite direction)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes FlutterViewController seems to retain an engine instance: fml::scoped_nsobject<FlutterEngine> _engine

@@ -2454,7 +2394,6 @@ - (void)cleanUpViewHierarchy:(BOOL)includeActiveView
if (clearText) {
[inputView replaceRangeLocal:NSMakeRange(0, inputView.text.length) withText:@""];
}
[inputView decommission];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to nil out the delegate here? The original code is strange because the _decommissioned ivar doesn't seem to be used anywhere except for an NSAssert, but it could be a bug)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the original issue was that a FlutterInputView can be retained by UIKit even if it's no longer in the view hierarchy, so it can outlive the engine instance, and when that happens the reference to the engine becomes a dangling pointer. With ARC I think textInputDelegate will be set to nil once the engine is deallocated.

@end

@implementation FlutterTimerProxy

+ (instancetype)proxyWithTarget:(FlutterTextInputPlugin*)target {
FlutterTimerProxy* proxy = [[self new] autorelease];
FlutterTimerProxy* proxy = [self new];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: prefer alloc/init

Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -725,6 +722,7 @@ - (void)setEditableTransform:(NSArray*)matrix;
@end

@implementation FlutterTextInputView {
__weak FlutterTextInputPlugin* _textInputPlugin;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits: prefer using property.

@@ -2090,8 +2045,7 @@ @interface FlutterTextInputPlugin ()

@implementation FlutterTextInputPlugin {
NSTimer* _enableFlutterTextInputViewAccessibilityTimer;
std::unique_ptr<fml::WeakPtrFactory<FlutterTextInputPlugin>> _weakFactory;
id<FlutterTextInputDelegate> _textInputDelegate;
__weak id<FlutterTextInputDelegate> _textInputDelegate;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits: prefer property

@jmagman
Copy link
Member

jmagman commented Dec 15, 2022

../../flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm:2044:1: error: property has a previous declaration
@property(nonatomic, readonly, weak) id<FlutterTextInputDelegate> textInputDelegate;
^
../../flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm:705:61: note: property declared here
@property(nonatomic, readonly) id<FlutterTextInputDelegate> textInputDelegate;
                                                            ^
../../flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm:2056:5: error: use of undeclared identifier '_textInputDelegate'; did you mean 'textInputDelegate'?
    _textInputDelegate = textInputDelegate;
    ^~~~~~~~~~~~~~~~~~
    textInputDelegate
../../flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm:2051:64: note: 'textInputDelegate' declared here
- (instancetype)initWithDelegate:(id<FlutterTextInputDelegate>)textInputDelegate {
                                                               ^
../../flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm:2056:24: error: explicitly assigning value of variable of type '__strong id<FlutterTextInputDelegate>' to itself [-Werror,-Wself-assign]
    _textInputDelegate = textInputDelegate;
    ~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~
../../flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm:2081:10: error: use of undeclared identifier '_textInputDelegate'
  return _textInputDelegate;
         ^

@LongCatIsLooong LongCatIsLooong added the autosubmit Merge PR when tree becomes green via auto submit App label Dec 15, 2022
@auto-submit auto-submit bot merged commit d9580a5 into flutter:main Dec 15, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 15, 2022
@LongCatIsLooong LongCatIsLooong deleted the ios-text-input-arc2 branch December 15, 2022 20:48
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 15, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 15, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 15, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 16, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 16, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 16, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 16, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 16, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 16, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 16, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 16, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 16, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 16, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 16, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 16, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 16, 2022
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Dec 16, 2022
…117242)

* e28b26e1d [linux] Allow overriding asset, ICU data path (flutter/engine#38296)

* 35bdb8bfc Roll Skia from 9f728d78f10d to f549128104ba (1 revision) (flutter/engine#38319)

* 97e246cb5 Roll Dart SDK from 358d0d1aa3e7 to 1dd5b1bf1099 (7 revisions) (flutter/engine#38320)

* d9580a5e7 Migrate iOS text input plugin to use ARC (flutter/engine#38179)

* c9e9fa5a9 Update web_sdk -> package test dependency to get updated package matcher (flutter/engine#38323)

* a7ec07f13 [fuchsia] Manually roll Fuchsia Linux SDK. (flutter/engine#38324)

* 61e95bacb Remove doc reference to the compute method (flutter/engine#38246)

* 353d6949e make sure CanvasRecorder updates clip bounds methods (flutter/engine#38325)

* 47a358c5e Started using FlutterEngineGroups by default on Android  (flutter/engine#37822)

* 7d8e10652 Bump github/codeql-action from 2.1.35 to 2.1.36 (flutter/engine#38210)

* 8915b81d4 Update buildroot to b2ab6e1. (flutter/engine#38329)

* 4fe620643 Revert "Roll Dart SDK from 358d0d1aa3e7 to 1dd5b1bf1099 (7 revisions) (#38320)" (flutter/engine#38331)

* 2ff490c1e Roll Skia from f549128104ba to 5e69caecd166 (11 revisions) (flutter/engine#38333)

* 22251857f Add missing include to FlutterThreadSynchronizer (flutter/engine#38337)

* 467cfd7ef Roll Fuchsia Mac SDK from VEOIaacOA75U7PYyz... to KtItDj-MERuua77aS... (flutter/engine#38339)

* 010f4ee7a Roll Fuchsia Linux SDK from zwfwHRSLdmV61hYqe... to urDNtEiHFAcBBhYe0... (flutter/engine#38340)

* 773b43571 Sped up reading with FlutterStandardCodec. (flutter/engine#38327)

* 70439f606 Roll Skia from 5e69caecd166 to 62f22c9c7d67 (3 revisions) (flutter/engine#38341)

* bc1647f0d Roll the test package used by Web in preparation for a Dart 3 SDK roll (flutter/engine#38342)

* cac228aff Roll Dart SDK from 358d0d1aa3e7 to 7b4d4ec3cad1 (14 revisions) (flutter/engine#38344)

* 13ae6eb75 Revert "Started using FlutterEngineGroups by default on Android  (#37822)" (flutter/engine#38351)

* ed8063861 Add an explicit constraint on the matcher package version to ensure Dart 3 compatibility (flutter/engine#38352)

* dcafebf44 Roll Skia from 62f22c9c7d67 to 1b1f53d77ced (1 revision) (flutter/engine#38343)

* 6f6158580 Roll Fuchsia Mac SDK from KtItDj-MERuua77aS... to bn5VF1-xDf-wKjIw8... (flutter/engine#38348)

* 0c00bc0a9 Remove 30fps cap from playgrounds (flutter/engine#38347)

* 38340bb57 [Impeller] Fix SceneC crash for nodes with children (flutter/engine#38346)

* 3a6b3f986 Roll Fuchsia Linux SDK from urDNtEiHFAcBBhYe0... to H6B0UgW07fc1nBtnc... (flutter/engine#38357)

* 81b453535 Roll Skia from 1b1f53d77ced to 7b0a9d9a3008 (8 revisions) (flutter/engine#38358)

* d91e20879 Port touch-based tests from embedder integration test (flutter/engine#38234)
loic-sharma pushed a commit to loic-sharma/flutter-engine that referenced this pull request Jan 3, 2023
* migrate iOS text input plugin to ARC

* review

* review

* review
gspencergoog pushed a commit to gspencergoog/flutter that referenced this pull request Jan 19, 2023
…lutter#117242)

* e28b26e1d [linux] Allow overriding asset, ICU data path (flutter/engine#38296)

* 35bdb8bfc Roll Skia from 9f728d78f10d to f549128104ba (1 revision) (flutter/engine#38319)

* 97e246cb5 Roll Dart SDK from 358d0d1aa3e7 to 1dd5b1bf1099 (7 revisions) (flutter/engine#38320)

* d9580a5e7 Migrate iOS text input plugin to use ARC (flutter/engine#38179)

* c9e9fa5a9 Update web_sdk -> package test dependency to get updated package matcher (flutter/engine#38323)

* a7ec07f13 [fuchsia] Manually roll Fuchsia Linux SDK. (flutter/engine#38324)

* 61e95bacb Remove doc reference to the compute method (flutter/engine#38246)

* 353d6949e make sure CanvasRecorder updates clip bounds methods (flutter/engine#38325)

* 47a358c5e Started using FlutterEngineGroups by default on Android  (flutter/engine#37822)

* 7d8e10652 Bump github/codeql-action from 2.1.35 to 2.1.36 (flutter/engine#38210)

* 8915b81d4 Update buildroot to b2ab6e1. (flutter/engine#38329)

* 4fe620643 Revert "Roll Dart SDK from 358d0d1aa3e7 to 1dd5b1bf1099 (7 revisions) (flutter#38320)" (flutter/engine#38331)

* 2ff490c1e Roll Skia from f549128104ba to 5e69caecd166 (11 revisions) (flutter/engine#38333)

* 22251857f Add missing include to FlutterThreadSynchronizer (flutter/engine#38337)

* 467cfd7ef Roll Fuchsia Mac SDK from VEOIaacOA75U7PYyz... to KtItDj-MERuua77aS... (flutter/engine#38339)

* 010f4ee7a Roll Fuchsia Linux SDK from zwfwHRSLdmV61hYqe... to urDNtEiHFAcBBhYe0... (flutter/engine#38340)

* 773b43571 Sped up reading with FlutterStandardCodec. (flutter/engine#38327)

* 70439f606 Roll Skia from 5e69caecd166 to 62f22c9c7d67 (3 revisions) (flutter/engine#38341)

* bc1647f0d Roll the test package used by Web in preparation for a Dart 3 SDK roll (flutter/engine#38342)

* cac228aff Roll Dart SDK from 358d0d1aa3e7 to 7b4d4ec3cad1 (14 revisions) (flutter/engine#38344)

* 13ae6eb75 Revert "Started using FlutterEngineGroups by default on Android  (flutter#37822)" (flutter/engine#38351)

* ed8063861 Add an explicit constraint on the matcher package version to ensure Dart 3 compatibility (flutter/engine#38352)

* dcafebf44 Roll Skia from 62f22c9c7d67 to 1b1f53d77ced (1 revision) (flutter/engine#38343)

* 6f6158580 Roll Fuchsia Mac SDK from KtItDj-MERuua77aS... to bn5VF1-xDf-wKjIw8... (flutter/engine#38348)

* 0c00bc0a9 Remove 30fps cap from playgrounds (flutter/engine#38347)

* 38340bb57 [Impeller] Fix SceneC crash for nodes with children (flutter/engine#38346)

* 3a6b3f986 Roll Fuchsia Linux SDK from urDNtEiHFAcBBhYe0... to H6B0UgW07fc1nBtnc... (flutter/engine#38357)

* 81b453535 Roll Skia from 1b1f53d77ced to 7b0a9d9a3008 (8 revisions) (flutter/engine#38358)

* d91e20879 Port touch-based tests from embedder integration test (flutter/engine#38234)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App platform-ios
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants