Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fragment Result Bug #37

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package ua.gov.diia.core.util.extensions.fragment

import androidx.annotation.IdRes
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.fragment.app.setFragmentResult
import androidx.fragment.app.setFragmentResultListener
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.SavedStateHandle
Expand Down Expand Up @@ -66,8 +69,9 @@ inline fun Fragment.registerForTemplateDialogNavResult(
key: String = ActionsConst.FRAGMENT_USER_ACTION_RESULT_KEY,
crossinline resultEvent: (String) -> Unit
) {
registerForNavigationResult<ConsumableString>(key) { event ->
event.consumeEvent { action -> resultEvent.invoke(action) }
setFragmentResultListener(key) { _, bundle ->
val event = bundle.getParcelable<ConsumableString>(key)
event?.consumeEvent { action -> resultEvent.invoke(action) }
}
}

Expand Down Expand Up @@ -113,7 +117,7 @@ fun <T : Any> Fragment.setNavigationResult(
key: String,
navController: NavController = findNavController()
) {
navController.previousBackStackEntry?.savedStateHandle?.set(key, result)
setFragmentResult(key, bundleOf(key to result))
}

/**
Expand Down