Created
December 19, 2019 16:55
-
-
Save IlyaGulya/05360e9437721bf21c6c5f316dfe047c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun onDestroy() { | |
super.onDestroy() | |
if (needCloseScope()) { | |
// Destroy this fragment with scope | |
Timber.d("Destroy UI scope: $fragmentScopeName") | |
Toothpick.closeScope(scope.name) | |
} | |
} | |
// This is android, baby! | |
private fun isRealRemoving(): Boolean = | |
(isRemoving && !instanceStateSaved) || // Because isRemoving == true for fragment in backstack on screen rotation | |
((parentFragment as? BaseFragment)?.isRealRemoving() ?: false) | |
// It will be valid only for 'onDestroy()' method | |
private fun needCloseScope(): Boolean = | |
when { | |
activity?.isChangingConfigurations == true -> false | |
activity?.isFinishing == true -> true | |
else -> isRealRemoving() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment