@SuppressLint("UnusedMaterialScaffoldPaddingParameter", "CoroutineCreationDuringComposition") @Composable fun SnackBarShow( message:String, actionLabel: String, doDismissed:() -> Unit, doActionPerformed:() -> Unit ) { val scaffoldState = rememberScaffoldState() // this contains the `SnackbarHostState` val coroutineScope = rememberCoroutineScope()
Scaffold( modifier = Modifier, scaffoldState = scaffoldState // attaching `scaffoldState` to the `Scaffold` ) { coroutineScope.launch { // using the `coroutineScope` to `launch` showing the snackbar // taking the `snackbarHostState` from the attached `scaffoldState` val snackbarResult = scaffoldState.snackbarHostState.showSnackbar( message = message, actionLabel = actionLabel ) when (snackbarResult) { SnackbarResult.Dismissed -> { Log.e("SnackBarShow", "Dismissed") doDismissed() } SnackbarResult.ActionPerformed -> { Log.e("SnackBarShow", "SnackBar's button clicked") doActionPerformed() } } } } }
코드를 일부 동작할 수 있도록 수정했다. @SuppressLint("UnusedMaterialScaffoldPaddingParameter", "CoroutineCreationDuringComposition")는 코드에서 오류 표시가 나는 것 때문에 수정을 하기는 했다. Padding Parameter을 사용하지 않는 것과 DuringComposition 부분인 것 같기는 하지만, 아직은 잘 모른다.
그리고 doDismissed(), doActionPerformed() 함수는 화면의 버튼을 클릭 했을 때 동작을 처리하는 부분을 구현해야 하기 때문에 return 될 함수의 선언으로 추가해 주었다.
어디에서는 간에 setCotent 로 감싸고 나서 위에서 작성한 SnackBarShow을 호출해 주는 것이다. 파라미터는 메시지로 보여줄 것과 버튼에 들어갈 문구를 전달하고 return 되는 함수는 SnackBar의 버튼을 클릭하지 않은 경우 처리와 , 버튼을 클릭했을 때 사용할 처리를 위해서 구현한 함수 2개를 돌려받았다.
이 부분이 들어가면 gradle 빌드를 통해서 kotlin 이라는 폴더가 생기면서 필요한 class 등을 만들어 주는 경로를 설정하는 것으로 이해가 되었다.
dependencies {
... // compose destination // https://github.com/raamcosta/compose-destinations 에서 최종 버전을 확인 implementation 'io.github.raamcosta.compose-destinations:animations-core:1.7.15-beta' ksp 'io.github.raamcosta.compose-destinations:ksp:1.7.15-beta' implementation "androidx.hilt:hilt-navigation-compose:1.0.0"
}
다음은 implementation 을 선언해 주는 것인데, 버전 확인은 원작자의 github 에서 확인하여 수정하면 최신 버전이 사용될 것 같다.
다음은 activity 을 만들어 주어야 하는 데... 지금은 테스트 하는 것이기 때문에 간단하게 수정해 보았다.
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState)
doUpdateCheck()
setContent {
MainTheme { // A surface container using the 'background' color from the theme Surface( modifier = Modifier.fillMaxSize(), color = softBlue ) { // github 에서 본 것 처럼 추가. val navHostEngine = rememberAnimatedNavHostEngine() DestinationsNavHost(navGraph = NavGraphs.root, engine = navHostEngine)
} } } }
이렇게 추가를 해 주고 나면 NavGraphs 가 생성이 되지 않아서 오류 표시가 나오지만, 일단은 무시하고 화면을 구성할 부분을 만들어 주었다.
이렇게 실행해 보면 navigation 선언등등 이전 포스팅에서 적었던 것 같은 NavigationItem 등등 선언하지 않아도 navigation 을 구현할 수 있으므로 추가 하거나 할 때 다른 작업들을 잊어 버려도 오류가 나지 않을 것 같다. (기능등을 비교해 보면 좋을 것 같다.)
#스하리1000명프로젝트, A veces es difícil hablar con trabajadores extranjeros, ¿verdad? ¡Hice una aplicación sencilla que ayuda! Escribes en tu idioma y los demás lo ven en el suyo. Se traduce automáticamente según la configuración. Súper útil para chatear fácilmente. ¡Echa un vistazo cuando tengas la oportunidad! https://play.google.com/store/apps/details?id=com.billcoreatech.multichat416
이 글을 읽고 있는 중이다... kotlin을 이용해서 앱을 구현해 보고 있는 중이라서... 이글에는 splash 화면에 대한 이야기도 있는 것 같고, navigation에 대한 이야기도 있는 듯하다. navigation 은 원래 이분이 작성한 것은 아닌 듯하고,
저 글에서 봐야 하는 것은 splash 화면에 대한 부분인데, 난 그것도 보다도 아래 나와 있는 navigation에 대한 부분이 보였다.
@Destination 태그를 이용해서 android 가 제공하는 navigation 보다 수월하게 사용할 수 있다는 이야기를 하고 싶은 것 같다. 아직은 조금 더 배워야 할 것 같아서 링크를 달아 두려고 한다. 아래 링크는 라이브러리 형태로 활용하는 설명이 나와 있는 원본 게시물이다. 이것도 나중에 정독을 해야 할 것 같다.
#billcorea #운동동아리관리앱 🏸 Schneedle, ¡una aplicación imprescindible para los clubes de bádminton! 👉 Match Play: registra puntuaciones y encuentra oponentes 🎉 ¡Perfecto para cualquier lugar, solo, con amigos o en un club! 🤝 Si te gusta el bádminton, definitivamente pruébalo.
Ir a la aplicación 👉 https://play.google.com/store/apps/details?id=com.billcorea.matchplay