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

fix(ios): navigation delegate class name conflict, closes #817 #824

Merged
merged 1 commit into from Dec 27, 2022

Conversation

pewsheen
Copy link
Contributor

@pewsheen pewsheen commented Dec 26, 2022

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Docs
  • New Binding issue #___
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change?

  • Yes, and the changes were approved in issue #___
  • No

Checklist

  • When resolving issues, they are referenced in the PR's title (e.g fix: remove a typo, closes #___, #___)
  • A change file is added if any packages will require a version bump due to this PR per the instructions in the readme.
  • I have added a convincing reason for adding this feature, if necessary

Other information

issue #817

Class name UIViewController was used in iOS's UIKit thus ClassDecl will fail and return None.

let navigation_delegate_cls = match ClassDecl::new("UIViewController", class!(NSObject)) {
Some(mut cls) => {
cls.add_ivar::<*mut c_void>("pending_scripts");
cls.add_ivar::<*mut c_void>("navigation_policy_function");
cls.add_ivar::<*mut c_void>("HasDownloadHandler");
cls.add_method(
sel!(webView:decidePolicyForNavigationAction:decisionHandler:),
navigation_policy as extern "C" fn(&Object, Sel, id, id, id),
);
cls.add_method(
sel!(webView:decidePolicyForNavigationResponse:decisionHandler:),
navigation_policy_response as extern "C" fn(&Object, Sel, id, id, id),
);
cls.add_method(
sel!(webView:didCommitNavigation:),
did_commit_navigation as extern "C" fn(&Object, Sel, id, id),
);
add_download_methods(&mut cls);
cls.register()
}
None => class!(UIViewController),
};

Later set_ivar with pending_scripts to UIKit's UIViewController will panic because there is no ivar pending_scripts in it.

(*navigation_policy_handler).set_ivar(
"pending_scripts",
Box::into_raw(Box::new(pending_scripts.clone())) as *mut c_void,

@pewsheen pewsheen requested a review from a team as a code owner December 26, 2022 13:51
@pewsheen pewsheen linked an issue Dec 26, 2022 that may be closed by this pull request
2 tasks
@wusyong wusyong merged commit fca42a0 into dev Dec 27, 2022
@wusyong wusyong deleted the navigation-delegate-cls branch December 27, 2022 05:52
@github-actions github-actions bot mentioned this pull request Dec 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[iOS] Ivar pending_scripts not found on class UIViewController
2 participants