-
Notifications
You must be signed in to change notification settings - Fork 12
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
๐ 3๋จ๊ณ - GitHub(UI ์ํ) #33
base: simuelunbo
Are you sure you want to change the base?
Conversation
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.
์๋
ํ์ธ์ ์ค๋ณด๋!
3๋จ๊ณ ๊ณ ์ํ์
จ์ต๋๋ค :) ์ ๊ตฌํํด์ฃผ์
จ๋ค์ !
๋ช๊ฐ์ง ์ฐธ๊ณ ํ์ค๋งํ ์ฝ๋ฉํธ ๋๋ ธ์ผ๋, ํ์ธํด์ฃผ์ธ์ :)
๋ง์ง๋ง๊น์ง ํ์ดํ
์
๋๋ค!
import nextstep.github.ui.theme.GithubTheme | ||
|
||
@Composable | ||
fun GithubRepoSuccess( |
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.
GithubRepoSuccess๋ผ๋ ์ด๋ฆ์ ๋ฐ์ดํฐ ๊ด์ ์ ๋ค์ด๋ฐ์๋๊น์?
GithubRepoList ๊ฐ์ ์ง๊ด์ ์ธ ๋ค์ด๋ฐ์ด ์ข๋ ๊ฐ๋
์ฑ์์ง ์์๊น์ :)
@Composable | ||
private fun GithubRepoSuccessPreview() { | ||
GithubTheme { | ||
GithubRepoSuccess( |
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.
๋ฆฌ์คํธ๊ฐ ๋น์ด์์๋๋ ์ด๋ค ํ๋ฉด์ด ๋์ค๋์?
์๊ตฌ์ฌํญ ๋ชฉ๋ก์ด ๋น ๊ฒฝ์ฐ์๋ ๋น ํ๋ฉด UI๋ฅผ ๋
ธ์ถํ๋ค.(ํผ๊ทธ๋ง ์ฐธ์กฐ)
์ ์ถ๊ฐํด์ฃผ์ธ์ :)
message = context.getString(R.string.error_message), | ||
actionLabel = context.getString(R.string.error_retry) | ||
) | ||
if (snackBarResult == SnackbarResult.ActionPerformed) run { viewModel::retryGithubRepo } |
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.
๋ณดํต ๋ฒ์ ์ง์ ํจ์๋ ์ธ์ ์ฐ์๋์?
๋ฒ์๋ฅผ ์ง์ ํ๊ฑฐ๋, ๊ฐ๋
์ฑ์ ์ํด ์ฌ์ฉํ๊ณคํ์ง๋ง
ํ์ฌ๋ ๋ฌด์๋ฏธ ํด๋ณด์ด๊ณ , ์คํ๋ ค ์ค์๋ฅผ ์ ๋ฐํ๋ ์ํํ ์ฝ๋๋ ์๋๊น์ :)
run { viewModel::retryGithubRepo }
์ ๊ฒฐ๊ณผ๊ฐ์ ๋ฌด์์ผ๊น์? :)
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.
ํด๋น ์ฝ๋๊ฐ ๋์ํ๋์ง ํ ์คํธํ ์์๋ ์ฝ๋๋ฅผ ์ง๋ด๋ ์ข์๊ฑฐ ๊ฐ์์ :)
val coroutineScope = rememberCoroutineScope() | ||
val snackBarHostState = remember { SnackbarHostState() } | ||
LaunchedEffect(Unit) { | ||
coroutineScope.launch { | ||
snackBarHostState.showSnackbar( | ||
message = "์๋ฌ ๋ฉ์ธ์ง", | ||
actionLabel = "์ฌ์๋" | ||
) | ||
} | ||
} |
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.
์ค๋ณด๋์ด ์๊ฐํ์๋ Preview์ ๊ธฐ์ค์ ๋ฌด์์ธ๊ฐ์ :)
์์ ๋ก์ง์ Preview๋ก ๋ณด๊ธด ํ๋ค์ง ์์๊น์?
์ด๋ฒคํธ๋ค์ ui ํ ์คํธ๋ก ์์ฑํด๋ณด๋ฉด ์ด๋จ๊น์? :)
|
||
private fun fetchRepositories() { | ||
viewModelScope.launch(CoroutineExceptionHandler { _, throwable -> | ||
_errorFlow.tryEmit(throwable) |
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.
์๋ฌ๊ฐ ๋ฐ์ํ๋ค๋ฉด, tryEmit์ด ์ ์๋ํ ๊น์? :)
}) { | ||
_githubUiState.update { it.copy(isLoading = true) } | ||
val repositories = githubRepoRepository.getRepositories("next-step") | ||
_githubUiState.update { it.copy(repositories = repositories, isLoading = false) } |
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.
์ค๋ณด๋์ด ์๊ฐํ๋ UiState๋ฅผ ์ค๊ณํ๋ ๊ธฐ์ค์ด ๋ฌด์์ธ๊ฐ์?
์์ํ๊ฒ ๊ถ๊ธํฉ๋๋ค :)
LaunchedEffect(true) { | ||
viewModel.errorFlow.collect { |
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.
๊ฐ์ ์๊ฐ์์๋ ๋ค๋ฃฌ ๋ด์ฉ์ด๊ธดํ๋ฐ,
https://medium.com/androiddevelopers/viewmodel-one-off-event-antipatterns-16a1da869b95
์ค๋ณด๋์ ์๊ฒฌ์ด ๊ถ๊ธํฉ๋๋ค! (์๊ฒฌ๋ง ์ฃผ์
๋ ์ข์๊ฑฐ ๊ฐ์์!)
์๋ ํ์ธ์
๋ฆ์์ง๋ง ์ด๋ฒ 3๋จ๊ณ ๋ฏธ์ ๋ ๋ฆฌ๋ทฐ ์ ๋ถํ๋๋ฆฝ๋๋ค ๐