Skip to content

Commit

Permalink
[add/#21] 바텀시트 이동 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
imtaejugkim committed Jan 16, 2025
1 parent 12d0af1 commit 2291e54
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 19 deletions.
91 changes: 90 additions & 1 deletion app/src/main/java/org/memento/presentation/main/MainScreen.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
package org.memento.presentation.main

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.Scaffold
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.launch
import org.memento.presentation.navigator.MainNavigator
import org.memento.presentation.navigator.component.BottomNavigationType
import org.memento.presentation.navigator.component.MainBottomBar
import org.memento.presentation.navigator.component.MainNavHost
import org.memento.presentation.navigator.rememberMainNavigator
import org.memento.presentation.plusbottomsheet.AddToDoDeadLineScreen
import org.memento.presentation.plusbottomsheet.AddToDoTagScreen
import org.memento.presentation.plusbottomsheet.MainPlusBottomSheet
import org.memento.ui.theme.darkModeColors

@Composable
fun MainScreen(
Expand All @@ -20,11 +38,73 @@ fun MainScreen(
)
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MainScreenContent(
modifier: Modifier = Modifier,
navigator: MainNavigator,
) {
val coroutineScope = rememberCoroutineScope()
val bottomSheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
var currentBottomSheet by remember { mutableStateOf<BottomSheetType?>(null) }

var selectedDeadLine by remember { mutableStateOf("Add DeadLine") }
var selectedTagColor by remember { mutableStateOf("#F0F0F3") }

if (currentBottomSheet != null) {
ModalBottomSheet(
onDismissRequest = { currentBottomSheet = null },
sheetState = bottomSheetState,
shape = RoundedCornerShape(topStart = 0.dp, topEnd = 0.dp),
containerColor = darkModeColors.gray10,
dragHandle = null
) {
Column(
modifier = Modifier
.fillMaxWidth()
.fillMaxHeight(0.73f)
) {
when (currentBottomSheet) {
BottomSheetType.MAIN -> MainPlusBottomSheet(
tagColor = selectedTagColor,
deadLineText = selectedDeadLine,
onNavigateDeadLineSetting = {
currentBottomSheet = BottomSheetType.DEADLINE
},
onNavigateTagSetting = {
currentBottomSheet = BottomSheetType.TAG

}
)

BottomSheetType.DEADLINE -> AddToDoDeadLineScreen(
onClose = { currentBottomSheet = null },
onDone = { deadLine ->
selectedDeadLine = deadLine
currentBottomSheet = BottomSheetType.MAIN
}
)


BottomSheetType.TAG -> AddToDoTagScreen(
onClose = { currentBottomSheet = null },
onDone = { tagColor ->
selectedTagColor = tagColor
currentBottomSheet = BottomSheetType.MAIN
}
)

BottomSheetType.URGENCY -> AddToDoDeadLineScreen(
onClose = { currentBottomSheet = null },
onDone = { }
)

null -> {}
}
}
}
}

Scaffold(
modifier = modifier,
content = { padding ->
Expand All @@ -39,12 +119,21 @@ fun MainScreenContent(
navigationBarItems = BottomNavigationType.entries,
currentNavigationBarItem = navigator.currentMainNavigationBarItem,
onNavigationBarItemSelected = { navigator.navigateMainNavigation(it) },
onAddButtonClick = { navigator.navigateToBottomSheet() },
onAddButtonClick = {
currentBottomSheet = BottomSheetType.MAIN
coroutineScope.launch {
bottomSheetState.show()
}
},
)
},
)
}

enum class BottomSheetType {
MAIN, DEADLINE, TAG, URGENCY
}

@Preview(showBackground = true)
@Composable
fun Main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import org.memento.presentation.navigator.component.BottomNavigationType
import org.memento.presentation.navigator.route.MainNavigationBarRoute
import org.memento.presentation.onboarding.navigation.OnboardingRoute
import org.memento.presentation.onboarding.navigation.navigationOnboarding2
import org.memento.presentation.plusbottomsheet.navigation.navigationBottomSheet
import org.memento.presentation.reqres.navigation.navigationReqres
import org.memento.presentation.today.navigation.navigationToday
import org.memento.presentation.todo.navigation.navigationTodo
Expand Down Expand Up @@ -49,9 +48,9 @@ class MainNavigator(
navHostController.navigationReqres()
}

fun navigateToBottomSheet() {
navHostController.navigationBottomSheet()
}
// fun navigateToBottomSheet() {
// navHostController.navigationBottomSheet()
// }

fun navigateToOnboarding2() {
navHostController.navigationOnboarding2()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import androidx.compose.ui.graphics.Color
import androidx.navigation.compose.NavHost
import org.memento.presentation.navigator.MainNavigator
import org.memento.presentation.onboarding.navigation.onboardingNavGraph
import org.memento.presentation.plusbottomsheet.navigation.bottomSheetNavGraph
import org.memento.presentation.reqres.navigation.reqresNavGraph
import org.memento.presentation.today.navigation.todayNavGraph
import org.memento.presentation.todo.navigation.todoGraph
Expand Down Expand Up @@ -47,9 +46,6 @@ fun MainNavHost(
reqresNavGraph(
navigateBack = { navigator.navHostController.popBackStack() },
)
bottomSheetNavGraph(
navigateBack = { navigator.navigateToBottomSheet() },
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,99 @@
package org.memento.presentation.plusbottomsheet

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Tab
import androidx.compose.material3.TabRow
import androidx.compose.material3.TabRowDefaults.tabIndicatorOffset
import androidx.compose.material3.Text
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.launch
import org.memento.R
import org.memento.presentation.util.noRippleClickable
import org.memento.ui.MementoBottomSheet
import org.memento.ui.RepeatSelectorContent
import org.memento.ui.theme.darkModeColors

@Composable
fun MainPlusBottomSheet() {
Column(
modifier =
Modifier
.fillMaxWidth()
.padding(16.dp),
fun MainPlusBottomSheet(
tagColor: String,
deadLineText : String,
onNavigateDeadLineSetting: () -> Unit,
onNavigateTagSetting: () -> Unit
) {
val pages = listOf(R.drawable.ic_check_tab, R.drawable.ic_check_tab, R.drawable.ic_check_tab)
val pagerState = rememberPagerState(
pageCount = { 3 }
)
val coroutineScope = rememberCoroutineScope()

TabRow(
selectedTabIndex = pagerState.currentPage,
modifier = Modifier
.padding(vertical = 13.dp),
containerColor = darkModeColors.gray09,
indicator = { tabPositions ->
Modifier.tabIndicatorOffset(tabPositions[pagerState.currentPage])
},
divider = { }
) {
Text(text = "바텀시트 내용")
Spacer(modifier = Modifier.height(100.dp))
pages.forEachIndexed { index, _ ->
Tab(
selected = pagerState.currentPage == index,
onClick = {
coroutineScope.launch {
pagerState.scrollToPage(index)
}
},
modifier = Modifier.padding(all = 3.dp)
) {
Image(
painter = painterResource(pages[index]),
contentDescription = "탭 아이콘",
modifier = Modifier.padding(all = 3.dp)
)
}
}
}

HorizontalPager(
state = pagerState,
) { page ->
when (page) {
0 -> AddToDoScreen (
deadLineText = deadLineText,
tagColor = tagColor,
onNavigateDeadLineSetting = onNavigateDeadLineSetting,
onNavigateTagSetting = onNavigateTagSetting
)
1 -> AddPlanScreen()
2 -> BrainDumpScreen()
else -> AddToDoScreen(
deadLineText = deadLineText,
tagColor = tagColor,
onNavigateDeadLineSetting = onNavigateDeadLineSetting,
onNavigateTagSetting = onNavigateTagSetting
)
}
}
}
}
3 changes: 2 additions & 1 deletion app/src/main/java/org/memento/ui/MementoBottomSheet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.ExperimentalMaterial3Api
Expand All @@ -22,6 +23,7 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.launch
Expand All @@ -41,7 +43,6 @@ fun MementoBottomSheet(
onDismissRequest: () -> Unit = {},
) {
val coroutineScope = rememberCoroutineScope()

if (isOpenBottomSheet) {
coroutineScope.launch {
sheetState.show()
Expand Down

0 comments on commit 2291e54

Please sign in to comment.