Last active
July 23, 2020 15:31
-
-
Save mnewlive/980509f29648d7b59912cdd8ae84ad58 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
fun FragmentActivity.currentFragmentOnTop(): Fragment? { | |
try { | |
val host = supportFragmentManager.findFragmentById(R.id.navHostFragment) as NavHostFragment | |
return host.childFragmentManager.fragments.getOrNull(0) | |
} catch (ignored: IllegalStateException) { | |
} catch (e: Exception) { | |
e.log() | |
} | |
return null | |
} |
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
class SettingsListFragment : BaseFragment(), | |
OnBackPressListener { | |
override fun onBackPress(): Boolean { | |
// findNavController().navigate(R.id.authorizations_list) | |
findNavController().popBackStack() | |
return true | |
} |
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 onBackPressed() { | |
val onBackPressListener = currentFragmentOnTop() as? OnBackPressListener | |
if (onBackPressListener?.onBackPress() != true) super.onBackPressed() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment