Skip to content

Commit

Permalink
[#3482] Set and Get navigation results according to destination's bac…
Browse files Browse the repository at this point in the history
…kstacks (#3483)
  • Loading branch information
mustafaozhan authored May 31, 2024
1 parent 1e83765 commit 7578901
Show file tree
Hide file tree
Showing 2 changed files with 7 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 @@ -22,7 +22,6 @@ import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import com.github.submob.scopemob.castTo
import com.github.submob.scopemob.whether
import com.oztechan.ccc.android.core.ad.AdManager
import com.oztechan.ccc.android.core.ad.BannerAdView
import com.oztechan.ccc.android.ui.mobile.R
Expand Down Expand Up @@ -77,19 +76,18 @@ fun <T> Fragment.getNavigationResult(
key: String,
destinationId: Int
) = findNavController()
.currentBackStackEntry
?.whether { it.destination.id == destinationId }
?.savedStateHandle
?.getLiveData<T>(key)
.getBackStackEntry(destinationId)
.savedStateHandle
.getLiveData<T>(key)

fun <T> Fragment.setNavigationResult(
destinationId: Int,
result: T,
key: String
) = findNavController()
.previousBackStackEntry
?.whether { it.destination.id == destinationId }
?.savedStateHandle?.set(key, result)
.getBackStackEntry(destinationId)
.savedStateHandle
.set(key, result)

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

0 comments on commit 7578901

Please sign in to comment.