-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[UI/#20] 캘린더뷰 / 주간 캘린더 구현 #33
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
24bc3e2
[MOD/#20] selectedDate 로직 변경
boiledEgg-s da62b7d
[UI/#20] 주간 캘린더 UI 구현
boiledEgg-s 9c70c38
[UI/#20] 주간 캘린더 + 당일 스크랩 목록 표시 화면 구현
boiledEgg-s ab47b7b
[FEAT/#20] 캘린더 전환 구현
boiledEgg-s 629b177
Merge remote-tracking branch 'origin/develop' into ui/#20-calendar-vi…
boiledEgg-s b0cc77f
[CHORE/#20] 애니메이션 라벨 추가
boiledEgg-s cdd13f8
[MOD/#20] LocalDate 확장함수 구현
boiledEgg-s 21a8942
[MOD/#20] 확장함수 기반 코드 수정
boiledEgg-s 76615cc
[FEAT/#20] 주간->월간 전환 구현
boiledEgg-s 6e89f2a
[ADD/#20] SelectedDateState 추가
boiledEgg-s 05f7daf
[REFACTOR/#20] SelectedDateState 기반 코드 수정
boiledEgg-s 43482a4
[ADD/#38] ScrapBox 컴포넌트 추가
boiledEgg-s d10d547
[ADD/#38] 주석 추가
boiledEgg-s 3b9c59f
[CHORE/#38] 프리뷰 수정
boiledEgg-s d8ae9e2
[MERGE] #38 -> #20
boiledEgg-s 067947a
[REFACTOR/#20] 리뷰 기반 코드 수정
boiledEgg-s File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
core/src/main/java/com/terning/core/designsystem/component/box/ScrapBox.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package com.terning.core.designsystem.component.box | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.border | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.shadow | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.unit.dp | ||
import com.terning.core.designsystem.theme.CalPink | ||
import com.terning.core.designsystem.theme.CalPurple | ||
import com.terning.core.designsystem.theme.Grey150 | ||
import com.terning.core.designsystem.theme.White | ||
|
||
/** | ||
* ScrapBox is made for easy customization of scrap box used in Calendar & Home Screen | ||
* | ||
* [modifier] must be assigned for assigning size of the box and padding | ||
* [elevation] must be set greater than zero for shadow effect, mainly used in Calendar | ||
* [borderWidth] must be set greater than zero for border effect, mainly used in Home | ||
*/ | ||
|
||
@Composable | ||
fun ScrapBox( | ||
cornerRadius: Dp, | ||
scrapColor: Color, | ||
modifier: Modifier = Modifier, | ||
elevation: Dp = 0.dp, | ||
borderWidth: Dp = 0.dp, | ||
borderColor: Color = Grey150, | ||
content: @Composable () -> Unit, | ||
) { | ||
Box( | ||
modifier = modifier | ||
.border( | ||
width = borderWidth, | ||
color = borderColor, | ||
RoundedCornerShape(cornerRadius), | ||
) | ||
.shadow( | ||
elevation = elevation, | ||
RoundedCornerShape(cornerRadius), | ||
) | ||
) { | ||
Box( | ||
modifier = Modifier | ||
.background( | ||
color = scrapColor, | ||
shape = RoundedCornerShape(cornerRadius) | ||
) | ||
.fillMaxSize() | ||
) | ||
Box( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(start = 9.dp) | ||
.background( | ||
shape = RoundedCornerShape( | ||
topEnd = cornerRadius, bottomEnd = cornerRadius | ||
), color = White | ||
) | ||
) { | ||
content() | ||
} | ||
} | ||
} | ||
|
||
@Preview(showBackground = true) | ||
@Composable | ||
fun BorderedScrapBoxPreview() { | ||
ScrapBox( | ||
modifier = Modifier | ||
.height(116.dp) | ||
.width(140.dp), | ||
scrapColor = CalPink, | ||
cornerRadius = 5.dp, | ||
borderWidth = 1.dp | ||
) {} | ||
} | ||
|
||
@Preview(showBackground = true) | ||
@Composable | ||
fun ShadowedScrapBoxPreview() { | ||
ScrapBox( | ||
modifier = Modifier | ||
.height(height = 92.dp) | ||
.fillMaxWidth(), | ||
scrapColor = CalPurple, | ||
cornerRadius = 10.dp, | ||
elevation = 1.dp | ||
) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
package com.terning.feature.calendar | ||
|
||
import androidx.activity.compose.BackHandler | ||
import androidx.compose.animation.AnimatedContent | ||
import androidx.compose.animation.SizeTransform | ||
import androidx.compose.animation.slideInVertically | ||
import androidx.compose.animation.slideOutVertically | ||
import androidx.compose.animation.togetherWith | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Spacer | ||
|
@@ -21,14 +26,18 @@ import androidx.compose.runtime.rememberCoroutineScope | |
import androidx.compose.runtime.setValue | ||
import androidx.compose.runtime.snapshotFlow | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
import com.terning.core.designsystem.theme.Grey200 | ||
import com.terning.feature.R | ||
import com.terning.feature.calendar.component.CalendarTopBar | ||
import com.terning.feature.calendar.component.WeekDaysHeader | ||
import com.terning.feature.calendar.models.CalendarState | ||
import kotlinx.coroutines.flow.distinctUntilChanged | ||
import kotlinx.coroutines.launch | ||
import java.time.LocalDate | ||
|
||
@Composable | ||
fun CalendarRoute() { | ||
|
@@ -40,35 +49,33 @@ fun CalendarScreen( | |
modifier: Modifier = Modifier, | ||
viewModel: CalendarViewModel = hiltViewModel() | ||
) { | ||
val selectedDate by viewModel.selectedDate.collectAsState() | ||
val state by remember{ mutableStateOf(CalendarState()) } | ||
val selectedDate by viewModel.selectedDate.collectAsStateWithLifecycle() | ||
val state by remember { mutableStateOf(CalendarState()) } | ||
|
||
val listState = rememberLazyListState( | ||
initialFirstVisibleItemIndex = state.getInitialPage() | ||
) | ||
|
||
var currentDate by remember { mutableStateOf(selectedDate) } | ||
var currentPage by remember { mutableIntStateOf(listState.firstVisibleItemIndex)} | ||
var currentDate by remember { mutableStateOf(LocalDate.now()) } | ||
var currentPage by remember { mutableIntStateOf(listState.firstVisibleItemIndex) } | ||
|
||
var isListExpanded by remember { mutableStateOf(false) } | ||
var isWeekEnabled by remember { mutableStateOf(false) } | ||
|
||
LaunchedEffect(key1 = listState) { | ||
snapshotFlow { listState.firstVisibleItemIndex } | ||
.distinctUntilChanged() | ||
.collect{ | ||
val swipeDirection = (listState.firstVisibleItemIndex - currentPage).coerceIn(-1, 1).toLong() | ||
.collect { | ||
val swipeDirection = | ||
(listState.firstVisibleItemIndex - currentPage).coerceIn(-1, 1).toLong() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오!! coerceIn() 처음 보는 것 같은데!! 새로운거 알아갑니당ㅎㅎ |
||
currentDate = currentDate.plusMonths(swipeDirection) | ||
currentPage = listState.firstVisibleItemIndex | ||
} | ||
} | ||
|
||
LaunchedEffect(key1 = selectedDate) { | ||
isWeekEnabled = true | ||
} | ||
|
||
BackHandler { | ||
isWeekEnabled = false | ||
if (selectedDate.isEnabled) { | ||
viewModel.updateSelectedDate(selectedDate.selectedDate) | ||
} | ||
} | ||
|
||
Scaffold( | ||
|
@@ -91,26 +98,57 @@ fun CalendarScreen( | |
) { paddingValues -> | ||
Column( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.fillMaxSize() | ||
.padding(top = paddingValues.calculateTopPadding()) | ||
) { | ||
WeekDaysHeader() | ||
Spacer(modifier = Modifier | ||
.fillMaxWidth() | ||
.height(1.dp) | ||
.background(color = Grey200) | ||
Spacer( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.height(1.dp) | ||
.background(color = Grey200) | ||
) | ||
CalendarMonths( | ||
modifier = Modifier.fillMaxSize(), | ||
selectedDate = selectedDate, | ||
onDateSelected = { | ||
viewModel.updateSelectedDate(it) | ||
|
||
AnimatedContent( | ||
targetState = selectedDate.isEnabled, | ||
transitionSpec = { | ||
if (!targetState) { | ||
slideInVertically { fullHeight -> -fullHeight } togetherWith | ||
slideOutVertically { fullHeight -> fullHeight } | ||
} else { | ||
slideInVertically { fullHeight -> fullHeight } togetherWith | ||
slideOutVertically { fullHeight -> -fullHeight } | ||
}.using( | ||
sizeTransform = SizeTransform(clip = true) | ||
) | ||
}, | ||
listState = listState, | ||
pages = state.getPageCount(), | ||
scrapLists = viewModel.mockScrapList | ||
) | ||
label = stringResource(id = R.string.calendar_animation_label) | ||
) { targetState -> | ||
if (!targetState) { | ||
CalendarMonths( | ||
modifier = Modifier.fillMaxSize(), | ||
selectedDate = selectedDate, | ||
onDateSelected = { | ||
viewModel.updateSelectedDate(it) | ||
}, | ||
listState = listState, | ||
pages = state.getPageCount(), | ||
scrapLists = viewModel.mockScrapList, | ||
) | ||
} else { | ||
CalendarWeekWithScrap( | ||
modifier = Modifier | ||
.fillMaxSize(), | ||
selectedDate = selectedDate, | ||
scrapLists = viewModel.mockScrapList, | ||
onDateSelected = { | ||
viewModel.updateSelectedDate(it) | ||
} | ||
) | ||
} | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요거 rememberSaveable로 해야 되나 했는데 저희 서비스는 가로모드 대응 안 하기 때문에 안 바꿔도 될 것 같네용