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

[Android] Let inflight life cycle events finish up before tearing them down #3187

Merged
merged 2 commits into from
Jul 13, 2018

Conversation

PureWeen
Copy link
Contributor

@PureWeen PureWeen commented Jun 29, 2018

Description of Change

OnAppearing for Android fires sometimes during OnAttached and sometimes during "OnResume"

  • when you swapped out the MainPage it would call RemoveViews mid fragment lifecycle which would then lead to the fragment not found when FragmentManager would try to Resume the fragment

  • Added an interface to allow a renderer to be declared MarkedForDeath so that things like adding more fragments or pending operations can just be halted

  • Centralized on interactions with Fragments into a single Extension class because that just made it easier to break point or print debug messages for any Fragment modifications.

  • Moved all the code for changing out the main page into the MainLooper call so that all "active" life cycle events will just settle before the main page does it's clean up and "realizing"

  • Moved the code for when you swap out Details or Master pages it'll use MainLooper if replacing an existing page to ensure life cycle events have concluded

Issues Resolved

Platforms Affected

  • Android

PR Checklist

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

@PureWeen PureWeen requested review from hartez, rmarinho and samhouts June 29, 2018 20:16
@PureWeen PureWeen added the DO-NOT-MERGE-!!! 🛑 This is in progress and needs to be updated before it can be merged. label Jun 30, 2018
@PureWeen
Copy link
Contributor Author

PureWeen commented Jul 5, 2018

build --uitests

@PureWeen PureWeen added p/Android and removed DO-NOT-MERGE-!!! 🛑 This is in progress and needs to be updated before it can be merged. labels Jul 5, 2018
@PureWeen PureWeen requested review from rmarinho, hartez and samhouts July 6, 2018 04:07
RunningApp.Tap("Start Over");
}

// Various tests are commented out on certain platforms because
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we get references in the comments for the known issues? That way it'll be easier to clean this up once they get fixed.

using Android.Views;
using Android.Widget;

namespace Xamarin.Forms.Internals
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the correct namespace for this? Or should it be Xamarin.Forms.Platform.Android? It's already an internal interface, so I don't think we have to worry about third parties taking a dependency.

{
public static FragmentTransaction RemoveEx(this FragmentTransaction @this, Fragment fragment)
{
return @this.Remove(fragment);
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest changing @this to fragmentTransaction. Less confusing.

namespace Xamarin.Forms.Platform.Android
{
// This is a way to centralize all fragment modifications which makes it a lot easier to debug
internal static class FragmentManagerExtensions
Copy link
Contributor

Choose a reason for hiding this comment

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

While this does make the debugging easier, it's also forcing an extra method call on every fragment transaction operation. You could probably achieve the same effect by decorating FragmentTransaction with another class and only using that decorator class when DEBUG is defined. That way you have a central place for debugging but you don't impact the Release version as much.

Something like this:
https://gist.github.com/hartez/a7824a102c595ca096fce8bdca1cec78

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 extra call get optimized out don't they?

image

I like the idea of the decorator because it also provides a useful place to expand on the debug implementation but I'm concerned about other anomalies of the wrapper or parts of it that can't be overridden like

public FragmentTransaction SetBreadCrumbShortTitle(string text);
public FragmentTransaction SetBreadCrumbTitle(string text);

Though I'm pretty sure these just execute the ICharSequence Overrides

Either way I just envision some hard to find inconsistency between debug/release caused by this

Copy link
Contributor

Choose a reason for hiding this comment

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

Either way I just envision some hard to find inconsistency between debug/release caused by this

That's a reasonable fear. I'm fine with the extension method overhead trade-off for the consistency.

@PureWeen PureWeen merged commit 60c74c9 into 3.1.0 Jul 13, 2018
@PureWeen PureWeen deleted the fix-gh2338 branch July 13, 2018 06:02
@samhouts samhouts added this to the 3.1.0 milestone Aug 1, 2018
@samhouts samhouts mentioned this pull request Sep 7, 2018
3 tasks
@samhouts samhouts added i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often m/high impact ⬛ labels Mar 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often m/high impact ⬛ p/Android t/bug 🐛
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants