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

[feat] Custom SnackBar 제작 #23

Merged
merged 5 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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,37 @@
package org.android.bbangzip.presentation.component.snackbar

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp

@Composable
fun BbangZipSnackBar(
text: String,
textStyle: TextStyle,
textColor: Color,
containerColor: Color,
modifier: Modifier = Modifier,
) {
Box(
modifier =
modifier
.padding(12.dp)
.background(color = containerColor, shape = RoundedCornerShape(size = 16.dp))
.padding(vertical = 11.dp, horizontal = 24.dp),
contentAlignment = Alignment.Center,
) {
Text(
text = text,
style = textStyle,
color = textColor,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.android.bbangzip.presentation.component.snackbar

import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import org.android.bbangzip.ui.theme.BbangZipTheme

@Composable
fun BbangZipSnackBarHost(
Copy link
Contributor

Choose a reason for hiding this comment

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

p5
좋다..

snackBarHostState: SnackbarHostState,
modifier: Modifier = Modifier,
) {
SnackbarHost(
modifier = modifier,
hostState = snackBarHostState,
snackbar = { data ->
BbangZipSnackBar(
text = data.visuals.message,
textStyle = BbangZipTheme.typography.label2Bold,
textColor = BbangZipTheme.colors.staticWhite_FFFFFF,
containerColor = BbangZipTheme.colors.labelAlternative_282119_61,
)
},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.SnackbarHostState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.compose.NavHost
Expand All @@ -20,6 +21,7 @@ fun MainNavHost(
modifier: Modifier = Modifier,
navigator: MainNavigator,
padding: PaddingValues,
snackBarHostState: SnackbarHostState,
) {
Box(
modifier =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHostState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import okhttp3.internal.toImmutableList
import org.android.bbangzip.presentation.component.snackbar.BbangZipSnackBarHost
import org.android.bbangzip.presentation.type.BottomNavigationType
import org.android.bbangzip.presentation.ui.navigator.component.BottomNavigationBar
import org.android.bbangzip.ui.theme.BBANGZIPTheme
Expand All @@ -24,17 +27,20 @@ fun MainScreen(

@Composable
private fun MainScreenContent(
modifier: Modifier = Modifier,
navigator: MainNavigator,
hostState: SnackbarHostState = remember { SnackbarHostState() },
modifier: Modifier = Modifier,
) {
Scaffold(
modifier = modifier.padding(WindowInsets.navigationBars.asPaddingValues()),
content = { padding ->
MainNavHost(
navigator = navigator,
padding = padding,
snackBarHostState = hostState,
)
},
snackbarHost = { BbangZipSnackBarHost(hostState) },
bottomBar = {
BottomNavigationBar(
isVisible = navigator.showBottomBar(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,57 @@ package org.android.bbangzip.presentation.ui.subject
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Button
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.android.bbangzip.ui.theme.defaultBbangZipColors

@Composable
fun SubjectScreen(
modifier: Modifier = Modifier,
) {
Column(modifier = Modifier.fillMaxSize().background(color = defaultBbangZipColors.backgroundNormal_FFFFFF)) {
Column(
modifier =
modifier
.fillMaxSize()
.background(color = defaultBbangZipColors.backgroundNormal_FFFFFF),
) {
Text("subject 탭")
}
}

@Preview
@Composable
private fun SubjectScreenPreview() {
val snackBarHostState = remember { SnackbarHostState() }
val coroutineScope = rememberCoroutineScope()
Column(
modifier =
Modifier
.fillMaxSize()
.background(color = defaultBbangZipColors.backgroundNormal_FFFFFF),
) {
Text("subject 탭")
Button(
onClick = {
coroutineScope.launch {
val job =
launch {
snackBarHostState.currentSnackbarData?.dismiss()
snackBarHostState.showSnackbar("안녕안녕")
Copy link
Contributor

Choose a reason for hiding this comment

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

p5
안녕안녕 언제바꾸실건가요?

}
delay(2000)
job.cancel()
}
},
) { Text("눌러") }
}
}
// 위에 코드는 클릭마다 스낵바가뜨고 2초후에 사라지게 만든 코드입니다
Loading