Skip to content

Commit

Permalink
Refactor: clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Velord committed Mar 24, 2023
1 parent 2d2566d commit ca68cda
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
package com.velord.composemultiplebackstackdemo.ui.main.bottomNavigation

import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.activity.OnBackPressedCallback
import androidx.activity.compose.BackHandler
import androidx.activity.compose.LocalOnBackPressedDispatcherOwner
import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.scale
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.core.view.forEach
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.repeatOnLifecycle
import androidx.navigation.NavController
import androidx.navigation.fragment.findNavController
import androidx.navigation.ui.NavigationUI
import com.velord.composemultiplebackstackdemo.R
import com.velord.composemultiplebackstackdemo.databinding.FragmentBottomNavBinding
import com.velord.composemultiplebackstackdemo.ui.compose.theme.setContentWithTheme
Expand Down Expand Up @@ -167,6 +159,7 @@ private fun Content(
}
}

@Preview
@Composable
private fun BottomNavContentPreview() {
Content(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.velord.composemultiplebackstackdemo.ui.main.bottomNavigation

import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.navigation.NavDestination
Expand Down Expand Up @@ -29,7 +28,6 @@ class BottomNavViewModel : ViewModel() {

fun updateBackHandling(currentNavigationDestination: NavDestination?) {
val isStart = currentNavigationDestination.isCurrentStartDestination(getNavigationItems())
Log.d("@@@", "isStart: $isStart; current: ${currentNavigationDestination?.label}")
isBackHandlingEnabledFlow.value = isStart
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package com.velord.multiplebackstackapplier

import android.annotation.SuppressLint
import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.MenuItem
import android.view.View
import androidx.annotation.IdRes
import androidx.core.view.forEach
import androidx.lifecycle.*
Expand All @@ -14,12 +11,9 @@ import androidx.navigation.NavDestination
import androidx.navigation.NavDestination.Companion.hierarchy
import androidx.navigation.ui.NavigationUI
import com.google.android.material.navigation.NavigationBarMenu
import com.velord.multiplebackstackapplier.MultipleBackstackApplier.matchDestination
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import java.lang.ref.WeakReference

object MultipleBackstackApplier {

Expand Down Expand Up @@ -89,7 +83,6 @@ class MultipleBackstack(
lifecycleOwner.lifecycleScope.launch {
lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
flowOnSelect.collectLatest { navItem ->
Log.d("@@@", "onSelect: ${navItem.navigationGraphId}")
val menu = MultipleBackstackApplier.createNavigationBarMenu(context, items)
val menuItem = menu.findItem(navItem.navigationGraphId)
NavigationUI.onNavDestinationSelected(
Expand Down

0 comments on commit ca68cda

Please sign in to comment.