Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[iOS] Prevent crash when a leaked cell has MenuItem with bindings #3288

Merged
merged 2 commits into from
Aug 6, 2018
Merged

[iOS] Prevent crash when a leaked cell has MenuItem with bindings #3288

merged 2 commits into from
Aug 6, 2018

Conversation

VitalyKnyazev
Copy link
Contributor

@VitalyKnyazev VitalyKnyazev commented Jul 12, 2018

Description of Change

Prevent NRE and crash when a leaked cell in ListView with Recycle mode has MenuItem with bindings and framework like Prism.Forms sets BindingContext to null after leaving the page. Leaked cells can appear as result of device orientation change plus scrolling or just ListView.ScrollTo call.

Issues Resolved

API Changes

N/A

Platforms Affected

  • iOS

Behavioral/Visual Changes

N/A

PR Checklist

  • Has automated tests
  • [ x] Rebased on top of the target branch at time of PR
  • [ x] Changes adhere to coding standard

…nuItem with bindings and framework like Xamarin.Forms sets BindingContext to null after leaving the page
@@ -632,6 +632,9 @@ UIView SetupButtons(nfloat width, nfloat height)

void SetupSelection(UITableView table)
{
if (table.GestureRecognizers == null)
return;
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we want to return here, or we won't run _tableView.AddGestureRecognizer(new SelectGestureRecognizer());

Copy link
Contributor Author

@VitalyKnyazev VitalyKnyazev Jul 18, 2018

Choose a reason for hiding this comment

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

It looks like when GestureRecognizers is null then there is no point in calling _tableView.AddGestureRecognizer(new SelectGestureRecognizer());, otherwise we would always had NRE. What I am trying to say is that when GestureRecognizers is null - that screen is gone and disposed.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure table and _tableView are the same reference here, though.

Copy link
Member

Choose a reason for hiding this comment

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

You may be right, though. Just discussing. :)

Copy link
Contributor Author

@VitalyKnyazev VitalyKnyazev Jul 18, 2018

Choose a reason for hiding this comment

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

It is the same reference, SetupSelection is private and called only once, right after setting _tableView to table, easy to verify :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can change _tableView to table and make the method static, nano-optimization =)

Copy link
Member

Choose a reason for hiding this comment

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

It would certainly make it more clear. I'm on board with that approach!

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 have updated PR

@samhouts
Copy link
Member

This looks good. If you're able to add a test case to the Control Gallery, too, that would be excellent. Thank you!

@rmarinho rmarinho merged commit 02f006d into xamarin:master Aug 6, 2018
PureWeen pushed a commit that referenced this pull request Aug 28, 2018
)

* Prevent crash when a leaked cell in ListView with Recycle mode has MenuItem with bindings and framework like Xamarin.Forms sets BindingContext to null after leaving the page

* Made SetupSelection static
@samhouts samhouts added this to the 3.3.0 milestone Sep 20, 2018
@samhouts samhouts added the approved Has two approvals, no pending reviews, and no changes requested label Sep 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Has two approvals, no pending reviews, and no changes requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants