Skip to content

Commit

Permalink
[#3510] Track exception for destination not found (#3511)
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafaozhan authored Jun 3, 2024
1 parent 7d78111 commit aea6bae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class CalculatorFragment : BaseVBFragment<FragmentCalculatorBinding>() {
private fun observeNavigationResults() = getNavigationResult<String>(
CHANGE_BASE_EVENT,
R.id.calculatorFragment
).observe(viewLifecycleOwner) {
)?.observe(viewLifecycleOwner) {
Logger.i { "CalculatorFragment observeNavigationResults $it" }
calculatorViewModel.event.onBaseChange(it)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import co.touchlab.kermit.Logger
import com.github.submob.scopemob.castTo
import com.oztechan.ccc.android.core.ad.AdManager
import com.oztechan.ccc.android.core.ad.BannerAdView
Expand Down Expand Up @@ -75,19 +76,28 @@ fun View.animateHeight(startHeight: Int, endHeight: Int) {
fun <T> Fragment.getNavigationResult(
key: String,
destinationId: Int
) = findNavController()
.getBackStackEntry(destinationId)
.savedStateHandle
.getLiveData<T>(key)
) = try {
findNavController()
.getBackStackEntry(destinationId)
.savedStateHandle
.getLiveData<T>(key)
} catch (e: IllegalArgumentException) {
Logger.e(e) { "$destinationId is not found in the backstack when getting navigation result for key $key" }
null
}

fun <T> Fragment.setNavigationResult(
destinationId: Int,
result: T,
key: String
) = findNavController()
.getBackStackEntry(destinationId)
.savedStateHandle
.set(key, result)
) = try {
findNavController()
.getBackStackEntry(destinationId)
.savedStateHandle
.set(key, result)
} catch (e: IllegalArgumentException) {
Logger.e(e) { "$destinationId is not found in the backstack when setting navigation result for key $key" }
}

fun View?.visibleIf(visible: Boolean, bringFront: Boolean = false) = this?.apply {
if (visible) {
Expand Down

0 comments on commit aea6bae

Please sign in to comment.