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

Fix crash when Exit event is fired multiple times #13281

Merged
merged 3 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
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
Expand Up @@ -261,6 +261,7 @@ class VariationDetailFragment :
}
}

@Suppress("LongMethod")
private fun setupObservers(viewModel: VariationDetailViewModel) {
viewModel.variationViewStateData.observe(viewLifecycleOwner) { old, new ->
new.variation.takeIfNotEqualTo(old?.variation) { newVariation ->
Expand Down Expand Up @@ -318,8 +319,13 @@ class VariationDetailFragment :
is ExitWithResult<*> -> navigateBackWithResult(KEY_VARIATION_DETAILS_RESULT, event.data)
is ShowDialog -> event.showDialog()
is ShowDialogFragment -> event.showIn(parentFragmentManager, this)
is Exit -> requireActivity().onBackPressedDispatcher.onBackPressed()
is VariationDetailViewModel.ShowUpdateVariationError -> showUpdateVariationError(event.message)
is Exit -> {
// Ensure subsequent Exit events are ignored to avoid IllegalStateException
viewModel.event.removeObservers(viewLifecycleOwner)
requireActivity().onBackPressedDispatcher.onBackPressed()
}

else -> event.isHandled = false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ abstract class VariationsBulkUpdateBaseFragment(@LayoutRes layoutId: Int) : Base
viewModel.onDoneClicked()
true
}

else -> false
}
}
Expand All @@ -68,7 +69,12 @@ abstract class VariationsBulkUpdateBaseFragment(@LayoutRes layoutId: Int) : Base
ActivityUtils.hideKeyboard(requireActivity())
uiMessageResolver.showSnack(event.message)
}
is MultiLiveEvent.Event.Exit -> requireActivity().onBackPressedDispatcher.onBackPressed()

is MultiLiveEvent.Event.Exit -> {
// Ensure subsequent Exit events are ignored to avoid IllegalStateException
viewModel.event.removeObservers(viewLifecycleOwner)
requireActivity().onBackPressedDispatcher.onBackPressed()
}
}
}
}
Expand Down
Loading