-
Notifications
You must be signed in to change notification settings - Fork 0
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
[ISSUE-53] 공통 바텀시트 생성 #70
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
presentation/src/main/java/com/yapp/growth/presentation/ui/utils/BottomSheet.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.yapp.growth.presentation.ui.utils | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material.* | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.launch | ||
|
||
/** | ||
* How to use? | ||
* val sheetState = rememberBottomSheetState( | ||
* initialValue = BottomSheetValue.Collapsed | ||
* ) | ||
* val scaffoldState = rememberBottomSheetScaffoldState( | ||
* bottomSheetState = sheetState | ||
* ) | ||
* val scope = rememberCoroutineScope() | ||
* BottomSheetScreen( | ||
* sheetState = sheetState, scaffoldState = scaffoldState, scope = scope | ||
* ) | ||
*/ | ||
|
||
@OptIn(ExperimentalMaterialApi::class) | ||
@Composable | ||
fun BottomSheetScreen( | ||
sheetState: BottomSheetState, scaffoldState: BottomSheetScaffoldState, scope: CoroutineScope | ||
) { | ||
BottomSheetScaffold(sheetBackgroundColor = Color.Transparent, | ||
sheetPeekHeight = 0.dp, | ||
scaffoldState = scaffoldState, | ||
sheetContent = { | ||
Box( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.background(Color.Black.copy(alpha = 0.7f)) | ||
.clickable(sheetState.isExpanded) { | ||
scope.launch { | ||
sheetState.collapse() | ||
} | ||
} | ||
) { | ||
Surface( | ||
modifier = Modifier | ||
.height(200.dp) | ||
.align(Alignment.BottomCenter) | ||
.clickable(false) { }, | ||
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. 혹시 이건 어떤 코드인가여 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. 위에 dim 영역인 Box 를 클릭하면 sheetState.collapse() 하도록 해주었는데
구조여서 Surface (바텀시트 영역) 클릭 시 sheetState 에 영향이 안가도록 저렇게 조치했는데 리펙토링 일감일 것 같아요 |
||
shape = RoundedCornerShape(topStart = 20.dp, topEnd = 20.dp), | ||
) { | ||
Box( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.background(Color.White) | ||
) { | ||
Text( | ||
modifier = Modifier | ||
.clickable(sheetState.isExpanded) { | ||
scope.launch { sheetState.collapse() } | ||
}, | ||
text = "Bottom sheet", | ||
fontSize = 40.sp | ||
) | ||
} | ||
} | ||
} | ||
}) { | ||
HomeButton(sheetState, scope) | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalMaterialApi::class) | ||
@Composable | ||
fun HomeButton(sheetState: BottomSheetState, scope: CoroutineScope) { | ||
Box( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.clip(RoundedCornerShape(10.dp)), | ||
contentAlignment = Alignment.Center | ||
) { | ||
Button(onClick = { | ||
scope.launch { | ||
if (sheetState.isCollapsed) { | ||
sheetState.expand() | ||
} else { | ||
sheetState.collapse() | ||
} | ||
} | ||
}) { | ||
Text(text = "Bottom sheet state: ${sheetState.currentValue}") | ||
} | ||
|
||
} | ||
} |
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.
아래 포맷과 동일하게 내려주면 좋을 것 같아요!
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.
b1e8b5a
수정했습니다~!