-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[webview_flutter_android][webview_flutter_wkwebview] Adds support for setOnScrollPositionChange
for webview_flutter platform implementations
#5664
Conversation
Hi @bparrishMines, could you please review and merge it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reviewed ios part
// references. | ||
@property(nonatomic, weak) id<FlutterBinaryMessenger> binaryMessenger; | ||
// InstanceManager must be weak to prevent a circular reference with the object it stores. | ||
@property(nonatomic, weak) FWFInstanceManager *instanceManager; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you explain more about this circular reference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, but that comment is actually not come up by me, you can see that comment throughout the code base wherever the property of FWFInstanceManager
is declared, I just followed the convention.
However, from my understanding, it is a safety measure to prevent a memory leak in case the instance of FWFInstanceManager
is used to store the object that contains it (circular relation).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hellohuanlin This is the pattern for all the api implementations in the plugin. The full reasoning is that the ScrollViewDelegate
instance contains an instance of the ScrollViewDelegateFlutterApi
. And the ScrollViewDelegateFlutterApi
contains an instance of the FWFInstanceManager
. And the FWFInstanceManager
contains an instance of the ScrollViewDelegate
.
ScrollViewDelegate
-> FlutterApi
-> InstanceManager
-> ScrollViewDelegate
.
I'm currently working on flutter/flutter#134777 to eventually make this a part of generated code and not copy pasted.
uiScrollView:(UIScrollView *)scrollView | ||
completion:(void (^)(FlutterError *_Nullable))completion { | ||
[self scrollViewDidScrollWithIdentifier:[self identifierForDelegate:instance] | ||
uiScrollViewIdentifier:[self.instanceManager |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if instanceManager is weak, do you want to deal with nil case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think instanceManager
can be nil here. Again, I just followed the pattern of other host API was implemented before me.
The reason why I think instanceManager
couldn't be nil is because it is strongly referenced by the plugin here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instanceManager
can be null in an add-to-app scenario. However, Objective-c will just return nil
and not cause a crash. This is the desired behavior since the plugin holds the only strong reference and we want this to be null when that changes. I will make this clearer when flutter/flutter#134777 is implemented in this language.
[self.scrollViewDelegateAPI scrollViewDidScrollForDelegate:self | ||
uiScrollView:scrollView | ||
completion:^(FlutterError *error) { | ||
NSAssert(!error, @"%@", error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we pipe the error to flutter side?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand, the completion
callback here is for the native side to handle the error pipe from the flutter side, so I don't think it is logical to passing it back to the flutter side. Besides, every callback that was implemented before me is doing the same, I just followed the convention.
if (self) { | ||
_scrollViewDelegateAPI = | ||
[[FWFScrollViewDelegateFlutterApiImpl alloc] initWithBinaryMessenger:binaryMessenger | ||
instanceManager:instanceManager]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems to be just a 1-line wrapper. can FWFScrollViewDelegate
itself conform to FWFScrollViewDelegateFlutterApi
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it's possible, but I adhered to the conventions established by the previously implemented API, such as the FWFUIDelegate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason this pattern doesn't have the wrapped class implement their own FlutterApi is because it wouldn't work well with inheritance. For example if we had
class A { }
class B implements A { }
interface AFlutterApi { }
interface BFlutterApi { }
class B
would need access to an implementation of AFlutterApi
and BFlutterApi
. So, there wouldn't be an easy way to do this if we did class A implements AFlutterApi
.
Note that this will also be solved by flutter/flutter#134777 by handling inherited flutter api automatically.
@hellohuanlin Thank you for your review! By the way, this PR of mine is extracted from my PR here, which has already been reviewed and approved by 2 people. That is why, in my opinion, it is a waste of effort to be thoroughly reviewed again. What I think should be reviewed here is that are there any difference between the code change here compared to the PR that contains a full changes (including platform interface,...) |
…l-listener-platforms
…l-listener-platforms
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@hellohuanlin This code was already reviewed in #3444 and follows the design from https://docs.google.com/document/d/1wXB1zNzYhd2SxCu1_BK3qmNWRhonTB6qdv4erdtBQqo/edit?usp=sharing&resourcekey=0-WOBqqOKiO9SARnziBg28pg. Let me know if you have questions about it.
I merged in the latest changes from the main branch, but this is still blocked by an ifra error failing the tests. |
I just changed the unit test a bit. |
@stuartmorgan This is ready for a secondary review. @hellohuanlin You can secondary review the iOS portion too if you would like. I will handle the version bump once this is done. |
FWFScrollViewDelegateFlutterApiImpl *flutterAPI = [[FWFScrollViewDelegateFlutterApiImpl alloc] | ||
initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger)) | ||
instanceManager:instanceManager]; | ||
return OCMPartialMock(flutterAPI); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd just inline these 2 helpers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with nit
@FlutterApi() | ||
abstract class UIScrollViewDelegateFlutterApi { | ||
@ObjCSelector( | ||
'scrollViewDidScrollWithIdentifier:uiScrollViewIdentifier:x:y:', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: ObjC naming should be ...:UIScrollViewIdentifier:x:y:
. Capitalizing acronyms trumps first letter being lower case for camel case in Obj-C naming conventions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lemme fix that.
@TheVinhLuong can you fix up the conflicts, including the CHANGELOG and pubspec version? Once @stuartmorgan's |
3b75f43
to
bb67922
Compare
Adhere to ObjC naming Update AUTHORS
bb67922
to
72a9988
Compare
I fixed up the code conflict. Also, the |
…port for `setOnScrollPositionChange` for webview_flutter platform implementations (flutter/packages#5664)
flutter/packages@e4ea6bf...29d8cc0 2024-02-07 td@technodisaster.com [local_auth] fix: isDeviceSupported on ios (flutter/packages#5125) 2024-02-07 jason-simmons@users.noreply.github.com [image_picker] Suppress analyzer warning about deprecation of UnmodifiableUint8ListView (flutter/packages#6076) 2024-02-07 58767497+GiftShower@users.noreply.github.com Add transitionDuration parameter (flutter/packages#5854) 2024-02-07 engine-flutter-autoroll@skia.org Roll Flutter from e6ba809 to 8431cae (23 revisions) (flutter/packages#6075) 2024-02-07 ltv.luongthevinh@gmail.com [webview_flutter_android][webview_flutter_wkwebview] Adds support for `setOnScrollPositionChange` for webview_flutter platform implementations (flutter/packages#5664) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC flutter-ecosystem@google.com,rmistry@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
… `setOnScrollPositionChange` for webview_flutter platform implementations (flutter#5664) Adds iOS and Android implementation for content offset listener This PR is part of a series of PRs that aim to close flutter/flutter#31027. The PR that contains all changes can be found at flutter#3444.
Adds iOS and Android implementation for content offset listener
This PR is part of a series of PRs that aim to close flutter/flutter#31027.
The PR that contains all changes can be found at #3444.
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.