-
Notifications
You must be signed in to change notification settings - Fork 0
[FEAT/#419] 이미지 로딩 뷰를 추가했어요 #420
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
Changes from 2 commits
43d5ddf
93b26e3
66accd6
c7f9ba7
3cdbb3e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,11 @@ | ||
| package com.spoony.spoony.core.designsystem.component.image | ||
|
|
||
| import androidx.compose.foundation.Image | ||
| import androidx.compose.foundation.layout.Box | ||
| import androidx.compose.foundation.layout.fillMaxSize | ||
| import androidx.compose.material3.CircularProgressIndicator | ||
| 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.RectangleShape | ||
|
|
@@ -10,16 +14,19 @@ import androidx.compose.ui.graphics.vector.ImageVector | |
| import androidx.compose.ui.layout.ContentScale | ||
| import androidx.compose.ui.platform.LocalInspectionMode | ||
| import androidx.compose.ui.res.vectorResource | ||
| import coil3.compose.AsyncImage | ||
| import coil3.compose.SubcomposeAsyncImage | ||
| import coil3.compose.SubcomposeAsyncImageContent | ||
| import com.spoony.spoony.R | ||
| import com.spoony.spoony.core.designsystem.theme.SpoonyAndroidTheme | ||
|
|
||
| @Composable | ||
| fun SpoonyImage( | ||
| model: Any?, | ||
| modifier: Modifier = Modifier, | ||
| shape: Shape = RectangleShape, | ||
| contentScale: ContentScale = ContentScale.Crop, | ||
| contentDescription: String? = null | ||
| contentDescription: String? = null, | ||
| showLoadingIndicator: Boolean = false | ||
| ) { | ||
| if (LocalInspectionMode.current) { | ||
| Image( | ||
|
|
@@ -29,11 +36,26 @@ fun SpoonyImage( | |
| modifier = modifier.clip(shape) | ||
| ) | ||
| } else { | ||
| AsyncImage( | ||
| SubcomposeAsyncImage( | ||
| model = model, | ||
| contentDescription = contentDescription, | ||
| contentScale = contentScale, | ||
| modifier = modifier.clip(shape) | ||
| modifier = modifier.clip(shape), | ||
| loading = { | ||
| if (showLoadingIndicator) { | ||
| Box( | ||
| modifier = Modifier.fillMaxSize(), | ||
| contentAlignment = Alignment.Center | ||
| ) { | ||
| CircularProgressIndicator( | ||
| color = SpoonyAndroidTheme.colors.gray300 | ||
| ) | ||
| } | ||
|
||
| } | ||
|
||
| }, | ||
| success = { | ||
| SubcomposeAsyncImageContent() | ||
| } | ||
| ) | ||
| } | ||
| } | ||
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.
오..이건 몰랐네...
기본
AsyncImage는 placeholder에 painter만 가능해서 요거로 한건가요???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.
SubcomposeAsyncImage 넣야지 painter 뿐만 아니라 커스텀한 로딩 UI 를 넣을 수 있어서 저렇게 작업했습니다! 사용하진 않았지만loading 상태, success 상태, error 상태를 분기해서 뷰를 구성할 수도 있다고 합니다.