Skip to content

Commit 4238b4a

Browse files
committed
fix search icon
1 parent e08d6bb commit 4238b4a

File tree

4 files changed

+53
-22
lines changed

4 files changed

+53
-22
lines changed

app/src/main/java/st/slex/csplashscreen/ui/InitialApp.kt

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package st.slex.csplashscreen.ui
22

33
import android.annotation.SuppressLint
4+
import androidx.compose.animation.AnimatedVisibility
5+
import androidx.compose.animation.core.tween
6+
import androidx.compose.animation.slideInVertically
7+
import androidx.compose.animation.slideOutVertically
8+
import androidx.compose.foundation.background
49
import androidx.compose.foundation.isSystemInDarkTheme
510
import androidx.compose.foundation.layout.WindowInsets
611
import androidx.compose.foundation.layout.systemBarsPadding
@@ -17,10 +22,11 @@ import androidx.compose.ui.graphics.Color
1722
import androidx.compose.ui.unit.dp
1823
import androidx.navigation.NavHostController
1924
import com.google.accompanist.systemuicontroller.rememberSystemUiController
25+
import org.koin.androidx.compose.koinViewModel
2026
import st.slex.csplashscreen.core.navigation.AppDestination
2127
import st.slex.csplashscreen.navigation.NavigationHost
28+
import st.slex.csplashscreen.ui.components.bottom_appbar.BottomAppBarResource
2229
import st.slex.csplashscreen.ui.components.bottom_appbar.MainBottomAppBar
23-
import org.koin.androidx.compose.koinViewModel
2430

2531
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
2632
@Composable
@@ -51,17 +57,25 @@ fun InitialApp(
5157
Scaffold(
5258
modifier = modifier,
5359
contentColor = MaterialTheme.colorScheme.onBackground,
54-
containerColor = Color.Transparent,
60+
containerColor = MaterialTheme.colorScheme.background,
5561
bottomBar = {
56-
MainBottomAppBar(
57-
onBottomAppBarClick = viewModel::navigate,
58-
currentDestination = currentDestination
59-
)
62+
AnimatedVisibility(
63+
visible = BottomAppBarResource.isAppbar(currentDestination),
64+
enter = slideInVertically(tween(300)) { it },
65+
exit = slideOutVertically(tween(300)) { it }
66+
) {
67+
MainBottomAppBar(
68+
onBottomAppBarClick = viewModel::navigate,
69+
currentDestination = currentDestination
70+
)
71+
}
6072
},
6173
contentWindowInsets = WindowInsets(0.dp),
6274
content = {
6375
NavigationHost(
64-
modifier = Modifier.systemBarsPadding(),
76+
modifier = Modifier
77+
.background(MaterialTheme.colorScheme.background)
78+
.systemBarsPadding(),
6579
navController = navController,
6680
)
6781
},

app/src/main/java/st/slex/csplashscreen/ui/components/bottom_appbar/BottomAppBarNavigation.kt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,22 @@ fun MainBottomAppBar(
3030
onBottomAppBarClick(item.screen)
3131
},
3232
icon = {
33-
val icon = if (isSelected) {
34-
item.selectedIcon
35-
} else {
36-
item.unselectedIcon
37-
}
38-
Icon(icon, item.appDestination.route)
33+
Icon(
34+
imageVector = if (isSelected) {
35+
item.selectedIcon
36+
} else {
37+
item.unselectedIcon
38+
},
39+
contentDescription = item.appDestination.name
40+
)
41+
},
42+
label = {
43+
Text(
44+
text = stringResource(id = item.titleResource)
45+
)
3946
},
40-
label = { Text(text = stringResource(id = item.titleResource)) },
4147
alwaysShowLabel = false
4248
)
4349
}
4450
}
45-
}
51+
}

app/src/main/java/st/slex/csplashscreen/ui/components/bottom_appbar/BottomAppBarResource.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import st.slex.csplashscreen.R
1212
import st.slex.csplashscreen.core.navigation.AppDestination
1313
import st.slex.csplashscreen.core.navigation.NavigationScreen
1414

15-
@Suppress("UNUSED")
1615
enum class BottomAppBarResource(
1716
val unselectedIcon: ImageVector,
1817
val selectedIcon: ImageVector,
@@ -40,5 +39,12 @@ enum class BottomAppBarResource(
4039
appDestination = AppDestination.SEARCH_PHOTOS,
4140
titleResource = R.string.nav_title_search,
4241
screen = NavigationScreen.SearchPhotosScreen(query = " ")
43-
)
42+
);
43+
44+
companion object {
45+
46+
fun isAppbar(
47+
appDestination: AppDestination?
48+
): Boolean = entries.any { it.appDestination == appDestination }
49+
}
4450
}

core/navigation/src/main/java/st/slex/csplashscreen/core/navigation/AppDestination.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,18 @@ enum class AppDestination(vararg val argsNames: String) {
2626
}
2727

2828
companion object {
29+
2930
private const val SEPARATOR_ROUTE = "_"
3031
private const val TAG_ROUTE = "route"
3132

32-
fun findByRoute(route: String?) = AppDestination
33-
.entries
34-
.firstOrNull {
35-
it.route == route
36-
}
33+
fun findByRoute(route: String?) = if (route == null) {
34+
UNDEFINED
35+
} else {
36+
AppDestination
37+
.entries
38+
.firstOrNull { destination ->
39+
destination.navigationRoute == route
40+
}
41+
}
3742
}
3843
}

0 commit comments

Comments
 (0)