Skip to content

Instantly share code, notes, and snippets.

@mnewlive
Last active July 23, 2020 15:31
Show Gist options
  • Save mnewlive/980509f29648d7b59912cdd8ae84ad58 to your computer and use it in GitHub Desktop.
Save mnewlive/980509f29648d7b59912cdd8ae84ad58 to your computer and use it in GitHub Desktop.
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
}
class SettingsListFragment : BaseFragment(),
OnBackPressListener {
override fun onBackPress(): Boolean {
// findNavController().navigate(R.id.authorizations_list)
findNavController().popBackStack()
return true
}
override fun onBackPressed() {
val onBackPressListener = currentFragmentOnTop() as? OnBackPressListener
if (onBackPressListener?.onBackPress() != true) super.onBackPressed()
}
<fragment
android:id="@+id/settingsListFragment"
android:name="com.saltedge.authenticator.features.settings.list.SettingsListFragment"
android:label="SettingsListFragment">
<action
android:id="@+id/authorizations_list"
app:popUpTo="@id/authorizationsListFragment" />
</fragment>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment