Skip to content

Commit

Permalink
[FIX/#322] 컨플릭트 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
leeeyubin committed Jan 9, 2025
2 parents 76611f2 + f51f632 commit 7720087
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 81 deletions.
4 changes: 2 additions & 2 deletions core/designsystem/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

<!--SortByBottom-->
<string name="sort_by_earliest">채용 마감 이른 순</string>
<string name="sort_by_shortest">짧은 근무 기간 순</string>
<string name="sort_by_longest">근무 기간 순</string>
<string name="sort_by_shortest">근무 기간 짧은 순</string>
<string name="sort_by_longest">근무 기간 순</string>
<string name="sort_by_scrap">스크랩 많은 순</string>
<string name="sort_by_view_count">조회수 많은 순</string>
<string name="sort_button_description">정렬 기준</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.foundation.pager.PagerState
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material3.HorizontalDivider
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope
Expand Down Expand Up @@ -47,6 +48,7 @@ fun CalendarRoute(
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
val amplitudeTracker = LocalTracker.current


CalendarScreen(
uiState = uiState,
navigateToAnnouncement = navigateToAnnouncement,
Expand All @@ -65,6 +67,12 @@ fun CalendarRoute(
},
modifier = modifier,
)

DisposableEffect(true) {
onDispose {
viewModel.resetUiState()
}
}
}

@Composable
Expand All @@ -90,6 +98,10 @@ private fun CalendarScreen(
pageCount = { uiState.calendarModel.pageCount }
)

LaunchedEffect(true) {
pagerState.scrollToPage(uiState.calendarModel.initialPage)
}

LaunchedEffect(key1 = pagerState, key2 = uiState.selectedDate) {
snapshotFlow { pagerState.currentPage }
.collect { current ->
Expand All @@ -115,7 +127,7 @@ private fun CalendarScreen(
date = uiState.calendarModel.getYearMonthByPage(pagerState.settledPage),
isListExpanded = uiState.isListEnabled,
onListButtonClicked = {
if(!calendarListTransition.isRunning)
if (!calendarListTransition.isRunning)
onClickListButton()
},
onMonthNavigationButtonClicked = { direction ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ class CalendarViewModel @Inject constructor() : ViewModel() {
}
}

fun resetUiState() = _uiState.update { currentState ->
currentState.copy(
selectedDate = DayModel(),
isListEnabled = false,
isWeekEnabled = false
)
}

fun updateSelectedDate(value: DayModel) = _uiState.update { currentState ->
currentState.copy(
selectedDate = value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Text
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
Expand Down Expand Up @@ -69,8 +68,12 @@ internal fun HomeFilteringBottomSheet(
val density = LocalDensity.current
var pageHeight by remember { mutableIntStateOf(0) }

LaunchedEffect(pagerState.currentPage) {
currentFilteringInfo = defaultFilteringInfo
var isCheckBoxChecked by remember {
mutableStateOf(
with(currentFilteringInfo) {
listOf(grade, workingPeriod, startYear, startMonth).all { it == null || it == 0 }
}
)
}

GetPagerHeight(
Expand Down Expand Up @@ -142,6 +145,7 @@ internal fun HomeFilteringBottomSheet(
1 -> {
PlanFilteringScreen(
currentFilteringInfo = currentFilteringInfo,
isCheckBoxChecked = isCheckBoxChecked,
updateGrade = {
currentFilteringInfo = currentFilteringInfo.copy(
grade = if (it != null) {
Expand All @@ -166,6 +170,9 @@ internal fun HomeFilteringBottomSheet(
startMonth = it
)
},
updateIsCheckBoxChecked = {
isCheckBoxChecked = it
}
)
}
}
Expand All @@ -189,7 +196,10 @@ internal fun HomeFilteringBottomSheet(
)
}
},
isEnabled = checkButtonEnable(currentFilteringInfo = currentFilteringInfo)
isEnabled = checkButtonEnable(
currentFilteringInfo = currentFilteringInfo,
isCheckBoxChecked = isCheckBoxChecked
)
)
}

Expand Down Expand Up @@ -243,10 +253,12 @@ fun TerningTab(
}
}

private fun checkButtonEnable(currentFilteringInfo: HomeFilteringInfo): Boolean =
private fun checkButtonEnable(
currentFilteringInfo: HomeFilteringInfo,
isCheckBoxChecked: Boolean
): Boolean =
with(currentFilteringInfo) {
listOf(grade, workingPeriod, startYear, startMonth).all { it == null || it == 0 } ||
listOf(grade, workingPeriod, startYear, startMonth).none { it == null || it == 0 }
isCheckBoxChecked || listOf(grade, workingPeriod, startYear, startMonth).none { it == null }
}

@Composable
Expand All @@ -255,6 +267,7 @@ private fun GetPagerHeight(
) {
PlanFilteringScreen(
currentFilteringInfo = HomeFilteringInfo(null, null, null, null, "total"),
isCheckBoxChecked = false,
modifier = Modifier
.onGloballyPositioned {
onHeightMeasured(it.size.height)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ private fun DatePicker(
if (itemHeightPixel > 0 && startIndex >= 0) scrollState.scrollToItem(startIndex)
}

val savedIndex by remember { mutableIntStateOf(startIndex) }

LaunchedEffect(itemHeightPixel, savedIndex) {
scrollState.scrollToItem(savedIndex)
}

LaunchedEffect(scrollState) {
snapshotFlow { scrollState.firstVisibleItemIndex }
.map { index ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ import kotlinx.collections.immutable.toImmutableList
@Composable
internal fun PlanFilteringScreen(
currentFilteringInfo: HomeFilteringInfo,
isCheckBoxChecked: Boolean,
modifier: Modifier = Modifier,
updateGrade: (Int?) -> Unit = {},
updateWorkingPeriod: (Int?) -> Unit = {},
updateStartYear: (Int?) -> Unit = {},
updateStartMonth: (Int?) -> Unit = {},
updateIsCheckBoxChecked: (Boolean) -> Unit = {},
) {
var isYearNull by remember { mutableStateOf(currentFilteringInfo.startYear == 0 || currentFilteringInfo.startYear == null) }
var isMonthNull by remember { mutableStateOf(currentFilteringInfo.startMonth == 0 || currentFilteringInfo.startMonth == null) }

var isCheckBoxChecked by remember { mutableStateOf(false) }

val yearsList by remember(isYearNull) {
mutableStateOf(
if (isYearNull) years + NULL_DATE
Expand Down Expand Up @@ -91,7 +91,7 @@ internal fun PlanFilteringScreen(
).toImmutableList(),
onButtonClick = {
updateGrade(it)
isCheckBoxChecked = false
updateIsCheckBoxChecked(false)
},
columns = 4,
modifier = Modifier
Expand All @@ -116,7 +116,7 @@ internal fun PlanFilteringScreen(
).toImmutableList(),
onButtonClick = {
updateWorkingPeriod(it)
isCheckBoxChecked = false
updateIsCheckBoxChecked(false)
},
modifier = Modifier
.padding(horizontal = 23.dp),
Expand All @@ -134,14 +134,14 @@ internal fun PlanFilteringScreen(
onYearChosen = { year ->
updateStartYear(year)
if (year != null) {
isCheckBoxChecked = false
updateIsCheckBoxChecked(false)
isYearNull = false
}
},
onMonthChosen = { month ->
updateStartMonth(month)
if (month != null) {
isCheckBoxChecked = false
updateIsCheckBoxChecked(false)
isMonthNull = false
}
},
Expand Down Expand Up @@ -174,7 +174,7 @@ internal fun PlanFilteringScreen(
updateStartYear(null)
updateStartMonth(null)
}
isCheckBoxChecked = isChecked
updateIsCheckBoxChecked(isChecked)
},
colors = CheckboxDefaults.colors(
checkedColor = TerningMain,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,11 @@ package com.terning.feature.main
import android.app.Activity
import android.content.Intent
import androidx.activity.compose.BackHandler
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideIn
import androidx.compose.animation.slideOut
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.NavigationBarItemDefaults
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarDuration
import androidx.compose.material3.SnackbarHost
Expand All @@ -30,20 +21,13 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavOptions
import androidx.navigation.compose.NavHost
import androidx.navigation.navOptions
import com.terning.core.analytics.EventType
import com.terning.core.designsystem.component.snackbar.TerningBasicSnackBar
import com.terning.core.designsystem.theme.Grey300
import com.terning.core.designsystem.theme.TerningMain
import com.terning.core.designsystem.theme.White
import com.terning.core.designsystem.util.NoRippleInteractionSource
import com.terning.feature.calendar.calendar.navigation.calendarNavGraph
import com.terning.feature.calendar.calendar.navigation.navigateCalendar
import com.terning.feature.filtering.filteringone.navigation.filteringOneNavGraph
Expand All @@ -57,6 +41,7 @@ import com.terning.feature.home.navigation.homeNavGraph
import com.terning.feature.home.navigation.navigateHome
import com.terning.feature.intern.navigation.internNavGraph
import com.terning.feature.intern.navigation.navigateIntern
import com.terning.feature.main.component.MainBottomBar
import com.terning.feature.mypage.mypage.navigation.myPageNavGraph
import com.terning.feature.mypage.profileedit.navigation.profileEditNavGraph
import com.terning.feature.onboarding.signin.navigation.navigateSignIn
Expand All @@ -68,7 +53,6 @@ import com.terning.feature.onboarding.splash.navigation.splashNavGraph
import com.terning.feature.search.search.navigation.searchNavGraph
import com.terning.feature.search.searchprocess.navigation.navigateSearchProcess
import com.terning.feature.search.searchprocess.navigation.searchProcessNavGraph
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.launch

Expand Down Expand Up @@ -277,49 +261,3 @@ fun MainScreen(
}
}
}

@Composable
private fun MainBottomBar(
isVisible: Boolean,
tabs: ImmutableList<MainTab>,
currentTab: MainTab?,
onTabSelected: (MainTab) -> Unit,
) {
AnimatedVisibility(
visible = isVisible,
enter = fadeIn() + slideIn { IntOffset(0, 0) },
exit = fadeOut() + slideOut { IntOffset(0, 0) }
) {
NavigationBar(containerColor = White) {
tabs.forEach { itemType ->
NavigationBarItem(
interactionSource = NoRippleInteractionSource,
selected = currentTab == itemType,
onClick = {
onTabSelected(itemType)
},
icon = {
Icon(
painter = painterResource(id = (itemType.icon)),
contentDescription = stringResource(id = itemType.contentDescription)
)
},
label = {
Text(
stringResource(id = itemType.contentDescription),
fontSize = 9.sp
)
},
colors = NavigationBarItemDefaults
.colors(
selectedIconColor = TerningMain,
selectedTextColor = TerningMain,
unselectedIconColor = Grey300,
unselectedTextColor = Grey300,
indicatorColor = White
)
)
}
}
}
}
Loading

0 comments on commit 7720087

Please sign in to comment.