Skip to content
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 2 commits into from
Jun 30, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
BottomSheetScaffold(sheetBackgroundColor = Color.Transparent,
sheetPeekHeight = 0.dp,
BottomSheetScaffold(
sheetBackgroundColor = Color.Transparent,
sheetPeekHeight = 0.dp,

아래 포맷과 동일하게 내려주면 좋을 것 같아요!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

b1e8b5a
수정했습니다~!

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) { },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

혹시 이건 어떤 코드인가여

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

위에 dim 영역인 Box 를 클릭하면 sheetState.collapse() 하도록 해주었는데
Box

  • Surface

구조여서 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}")
}

}
}