{"id":356082,"date":"2024-05-20T23:22:09","date_gmt":"2024-05-20T23:22:09","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=356082"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=356082","title":{"rendered":"<span>NoArchitecture Kotlin Compose<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>\u041d\u0430\u0447\u0430\u043b\u043e<\/h2>\n<p>\u0412\u0441\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0432 <em>setContent<\/em>. <em>ComposeGenAppTheme<\/em> \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u0430. <em>Surface<\/em> \u043a\u0441\u0442\u0430\u0442\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0435\u0431\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 <em>Box.<\/em> \u041d\u0435 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u043e \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0431\u0435\u0437 XML. \u0425\u043e\u0442\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0432\u043e Fragmets \u043a\u0430\u043a View \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u0430 <a href=\"https:\/\/developer.android.com\/jetpack\/compose\/migrate\/interoperability-apis\/compose-in-views\" rel=\"noopener noreferrer nofollow\">Using Compose in Views<\/a>.<\/p>\n<pre><code class=\"kotlin\">        setContent {             ComposeGenAppTheme {                 Surface(                     modifier = Modifier.fillMaxSize(),                     color = MaterialTheme.colorScheme.background                 ) { <\/code><\/pre>\n<p>\u041f\u0440\u043e TabRow \u0440\u0430\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0443. \u041a\u043e\u043c\u0443 \u043d\u0430\u0434\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u0441\u043a\u043e\u043f\u0438\u043f\u0430\u0441\u0442\u0438\u0442 \u0438\u0437 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 <a href=\"https:\/\/github.com\/app-z\/NoArchitecture-Kotlin-Compose.git\" rel=\"noopener noreferrer nofollow\"><abbr class=\"habraabbr\" title=\"NoArchitecture\u2011Kotlin\u2011Compose\" data-title=\"&lt;p>NoArchitecture\u2011Kotlin\u2011Compose&lt;\/p>&#187; data-abbr=&#187;https:\/\/github.com\/app\u2011z\/NoArchitecture\u2011Kotlin\u2011Compose.git&#187;>NoArchitecture\u2011Kotlin\u2011Compose.git<\/abbr><\/a> \u0430 \u043a\u0442\u043e \u0437\u0430\u0445\u043e\u0447\u0435\u0442 \u0432\u043d\u0438\u043a\u043d\u0443\u0442\u044c, \u043d\u0430 Youtybe \u0435\u0441\u0442\u044c \u0432\u0438\u0434\u0435\u043e. \u041d\u0430 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u043c \u0432\u0435\u0441\u044c\u043c\u0430 \u043f\u043e\u043d\u044f\u0442\u043d\u043e. \u0421\u0441\u044b\u043b\u043a\u0430 \u0432\u043d\u0438\u0437\u0443 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<pre><code>                        TabRow(selectedTabIndex = selectedTabIndex) {                             tabItems.forEachIndexed { index, item ->                                 Tab(selected = index == selectedTabIndex,                                     onClick = {                                         selectedTabIndex = index                                     },                                     text = {                                         Text(item.title)                                     },                                     icon = {                                         Icon(                                             imageVector = if (index == selectedTabIndex) {                                                 item.selectedItem                                             } else {                                                 item.unselectedItem                                             },                                             contentDescription = item.title                                         )                                     })                             }                         } <\/code><\/pre>\n<h2>\u041f\u0440\u0435\u0434\u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440<\/h2>\n<p>\u0414\u043b\u044f preview \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 \u0441 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439 <a class=\"mention\" href=\"\/users\/Preview\">@Preview<\/a>. \u041f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0447\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432\u044b\u0439\u0434\u0435\u0442 \u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u044d\u0442\u043e\u0439 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439. \u041f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u0440\u0443\u0447\u043d\u0443\u044e.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/40d\/cb8\/720\/40dcb8720fb36f3f06b126d4e0f55744.png\" alt=\"Preview\" title=\"Preview\" width=\"1258\" height=\"655\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/40d\/cb8\/720\/40dcb8720fb36f3f06b126d4e0f55744.png\"\/><\/p>\n<div><figcaption>Preview<\/figcaption><\/div>\n<\/figure>\n<pre><code class=\"kotlin\">@Preview @Composable fun PreviewConversation() {     ComposeGenAppTheme {         FalconInfoListView(SampleData.getRockets())     } } <\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0441\u043f\u0438\u0441\u043e\u043a, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u0437 <em>FalconInfo.<\/em><\/p>\n<pre><code>class SampleData {     companion object {         private const val mesageSize = 10;         private val conversationSample: List&lt;FalconInfo> = buildList&lt;FalconInfo>(mesageSize) {             for (i in 0 until mesageSize) {                 add(FalconInfo(name = \"Name $i\",                     rocket = \"Rocket $i\",                     details = \"Detail can be long, Detail can be long, Detail can be long, Detail can be long, Detail can be long, Detail can be long, \"))             }         }          fun getRockets(): List&lt;FalconInfo> {             return conversationSample         }     } } <\/code><\/pre>\n<h2>\u041d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u0438<\/h2>\n<p>Re<em>member<\/em> &#8212; \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 State, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <em>mutableIntStateOf<\/em>.  \u0417\u0430\u0442\u0435\u043c \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 selectedTabIndex \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043b\u044e\u0447\u0430 LaunchedEffect(key) \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u044f. Compose \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0436\u0438\u0432\u0435\u0442 \u043a\u0430\u043a \u0431\u044b \u0432 \u0432\u043e\u0437\u0434\u0443\u0445\u0435. \u041e\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0441\u0430\u043c\u0430 \u0441\u0435\u0431\u044f \u0438 \u0447\u0442\u043e\u0431\u044b \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0441\u044f selectedTabIndex \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <em>remember. <\/em><\/p>\n<pre><code class=\"kotlin\">                    var selectedTabIndex by remember {                         mutableIntStateOf(0)                     }                       LaunchedEffect(selectedTabIndex) {                         pagerState.animateScrollToPage(selectedTabIndex)                     } <\/code><\/pre>\n<h2>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0441\u0435\u0442\u0438. \u0412\u044b\u0432\u043e\u0434 \u0441\u043f\u0438\u0441\u043a\u0430<\/h2>\n<p>\u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 FalconInfo \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f http \u0437\u0430\u043f\u0440\u043e\u0441. \u042d\u0442\u043e \u043a\u043e\u0434 \u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430. \u0427\u0442\u043e\u0431\u044b \u043a\u0430\u043a \u0442\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0432\u0432\u0435\u043b <em>mutableStateOf <\/em>\u043d\u0430 \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441 \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442. \u0427\u0442\u043e \u043d\u0435 \u043e\u0441\u043e\u0431\u043e \u043f\u043e\u043c\u043e\u0433\u043b\u043e. \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u0441\u0435 \u0441\u0442\u0430\u043b\u043e \u0431\u0435\u0441\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044c\u043d\u043e \u0442\u0440\u0438\u0433\u0433\u0435\u0440\u0438\u0442\u0441\u044f \u0438 \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u043e\u0448\u0438\u0431\u043a\u0438.<\/p>\n<pre><code class=\"kotlin\">                    var status by remember { mutableStateOf(\"Loading\") }                     ...                     LaunchedEffect(true) {                         scope.launch {                             status = try {                                 rockets = Greeting().greeting()                                 \"Ok\"                             } catch (e: Exception) {                                 e.localizedMessage ?: \"error\"                             }                         }                     }                     GreetingView(text)                      <\/code><\/pre>\n<p>Http \u0437\u0430\u043f\u0440\u043e\u0441 \u0438 json \u043f\u0430\u0440\u0441\u0435\u0440 Ktor. \u0410 \u043a\u0430\u043a \u0436\u0435 Retrofit?<\/p>\n<pre><code class=\"kotlin\">  class SpaceX {      private val httpClient = HttpClient {         install(HttpCache)         install(ContentNegotiation) {             json(Json {                 prettyPrint = true                 isLenient = true                 ignoreUnknownKeys = true             })         }     }      @Throws(Exception::class)     suspend fun getRockets(): List&lt;FalconInfo> {         val rockets: Array&lt;FalconInfo> =             httpClient.get(\"https:\/\/api.spacexdata.com\/v4\/launches\").body()         return rockets.asList()     } } <\/code><\/pre>\n<p>\u0424\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. <em>Preview<\/em> \u0441 \u043c\u043e\u043a\u0430\u043c\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0435\u0433\u043e \u0436\u0435. \u041c\u0430\u0433\u0438\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u043e\u0432 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 <em>LazyColumn<\/em> \u0438 \u043d\u0430\u0434\u043e \u0435\u0433\u043e \u043a\u043e\u043f\u043d\u0443\u0442\u044c \u043d\u0430 \u043f\u0440\u0435\u0434\u043c\u0435\u0442 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438. \u041f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u0442\u0430\u0440\u0442\u0435 \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u0442\u043e\u0440\u043c\u0430\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u043d\u0430 \u0441\u0442\u0430\u0440\u043e\u043c \u0444\u043b\u0430\u0433\u043c\u0430\u043d\u0435. \u041f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u043a\u0440\u0443\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u0432\u0441\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043f\u043b\u0430\u0432\u043d\u044b\u043c. \u041d\u0430\u0434\u043e \u043e\u0442\u0434\u0430\u0442\u044c \u0434\u043e\u043b\u0436\u043d\u043e\u0435 \u0430\u0432\u0442\u043e\u0440\u0430\u043c. \u0421 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043a\u043e\u0434\u0430, \u0431\u0435\u0437 \u0445\u043e\u043b\u0434\u0435\u0440\u043e\u0432 \u0438 \u043f\u044d\u0439\u043b\u043e\u0430\u0434\u0435\u0440\u043e\u0432 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a. \u041d\u0430\u0434\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043a\u0430\u043a \u0435\u0433\u043e &#171;\u043f\u0440\u043e\u0433\u0440\u0435\u0442\u044c&#187; \u043f\u0440\u0438 \u0441\u0442\u0430\u0440\u0442\u0435 \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e.<\/p>\n<pre><code class=\"kotlin\">@Composable fun FalconInfoListView(falconInfos: List&lt;FalconInfo>) {     LazyColumn {         items(falconInfos) { falconInfos ->             FalconInfoCard(falconInfos)         }     } } <\/code><\/pre>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u043a\u0430\u0440\u0442\u043e\u0447\u043a\u0438. \u041d\u0438\u0436\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u0434 \u0433\u0434\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u0441\u043f\u0438\u0441\u043e\u043a. PreviewMessageCard \u044d\u0442\u043e \u043f\u0440\u0435\u0434\u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441\u043f\u0438\u0441\u043a\u0430. \u0418\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043e\u0442 \u0413\u0443\u0433\u043b\u0430 \u0432\u0437\u044f\u043b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0435\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430. \u0415\u0441\u043b\u0438 \u0442\u0435\u043a\u0441\u0442 \u0434\u043b\u0438\u043d\u043d\u0435\u0435 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438. \u041a\u0441\u0442\u0430\u0442\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043d\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0441\u043a\u0440\u043e\u043b\u0438\u0442\u044c \u0432\u0432\u0435\u0440\u0445 \u0438\u043b\u0438 \u0432\u043d\u0438\u0437, \u043a\u043e\u0433\u0434\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0435\u0432\u0438\u0434\u0438\u043c\u044b\u043c. recyclerview \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c?<\/p>\n<p>AsyncImage &#8212; \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438<code>coil<\/code><\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u0430\u0440\u0442\u043e\u0447\u043a\u0438<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"kotlin\">@Composable fun FalconInfoCard(falconInfo: FalconInfo) {     Row(modifier = Modifier.padding(all = 8.dp)) {          AsyncImage(             placeholder = rememberVectorPainter(Icons.Filled.Rocket),             model = falconInfo.links?.patch?.small,             contentDescription = null,             contentScale = ContentScale.FillWidth,             modifier = Modifier                 .size(40.dp)                 .clip(CircleShape)             \/\/.aspectRatio(0.8F)         )          Spacer(modifier = Modifier.width(8.dp))          var isExpanded by remember { mutableStateOf(false) }          val surfaceColor by animateColorAsState(             if (isExpanded) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.surface,             label = \"surf_color\",         )          Column(modifier = Modifier.clickable { isExpanded = !isExpanded })         {             falconInfo.name?.let {                 Text(                     text = it,                     color = MaterialTheme.colorScheme.secondary                 )             }              Spacer(modifier = Modifier.height(4.dp))              Surface(                 shape = MaterialTheme.shapes.medium,                 shadowElevation = 1.dp,                 \/\/ surfaceColor color will be changing gradually from primary to surface                 color = surfaceColor,                 \/\/ animateContentSize will change the Surface size gradually                 modifier = Modifier                     .animateContentSize()                     .padding(1.dp)             ) {                 falconInfo.details?.let {                     Text(                         text = it,                         maxLines = if (isExpanded) Int.MAX_VALUE else 1,                         style = MaterialTheme.typography.bodyMedium                     )                 }             }         }     } }  @Preview @Composable fun PreviewMessageCard() {     FalconInfoCard(         FalconInfo(             staticFireDateUtc = \"234234234\",             staticFireDateUnix = 1,             name = \"Rocket\", rocket = \"N1\",             details = \"Detail can be long, Detail can be long, Detail can be long, \"         )     )  }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/6e6\/88c\/992\/6e688c9922bfdb41611ed535e5070967.png\" alt=\"\u041a\u0430\u0440\u0442\u043e\u0447\u043a\u0430\" title=\"\u041a\u0430\u0440\u0442\u043e\u0447\u043a\u0430\" width=\"904\" height=\"449\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6e6\/88c\/992\/6e688c9922bfdb41611ed535e5070967.png\"\/><\/p>\n<div><figcaption>\u041a\u0430\u0440\u0442\u043e\u0447\u043a\u0430<\/figcaption><\/div>\n<\/figure>\n<h2>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u044b<\/h2>\n<p>\u041f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432 Runtime. \u041f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043f\u043e\u043a\u0443\u0440\u0438\u0442\u044c \u043c\u0430\u043d\u0443\u0430\u043b\u044b<\/p>\n<details class=\"spoiler\">\n<summary> The coroutine scope left the composition<\/summary>\n<div class=\"spoiler__content\">\n<p><a href=\"https:\/\/developer.android.com\/jetpack\/compose\/side-effects\" rel=\"noopener noreferrer nofollow\">https:\/\/developer.android.com\/jetpack\/compose\/side-effects<\/a><\/p>\n<p><code>produceState<\/code><br \/> launches a coroutine scoped to the Composition that can push values into a<br \/> returned <code>State<\/code>. Use it to<br \/> convert non-Compose state into Compose state, for example bringing external<br \/> subscription-driven state such as <code>Flow<\/code>, <code>LiveData<\/code>, or <code>RxJava<\/code> into the<br \/> Composition<\/p>\n<\/div>\n<\/details>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0439 \u043e\u0431\u0435\u0440\u0442\u043a\u043e\u0439. \u0422\u0435\u043f\u0435\u0440\u044c \u0443\u0436\u0435 \u0432\u0441\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e. \u041d\u041e \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u043c\u0435\u0436\u0434\u0443 \u0442\u0430\u0431\u0430\u043c\u0438, \u043f\u0440\u043e\u0441\u043a\u0430\u043a\u0438\u0432\u0430\u0435\u0442 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430. \u0432 \u0432\u0435\u0440\u0441\u0438\u0438 \u0441 LaunchedEffect \u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043e\u043d\u0430 \u043d\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u043b\u0430. <em>initialValue = ResponseResult.Loading <\/em>&#8212; \u0441\u0442\u043e\u0438\u0442 \u043b\u0438 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439?<\/p>\n<pre><code class=\"kotlin\">    val resLoad =         produceState&lt;ResponseResult&lt;List&lt;FalconInfo>>>(initialValue = ResponseResult.Loading) {             value = try {                 ResponseResult.Success(SpaceX().getRockets())             } catch (e: Exception) {                 ResponseResult.Error(e.localizedMessage ?: \"error\")             }         } <\/code><\/pre>\n<p>\u041a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0442\u0438 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u0430\u0440\u0438\u044f. produceState \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c. install(HttpCache) \u0432 \u043f\u0430\u043a\u0435\u0442\u0435 io.ktor.client.plugins.cache \u0442\u0430\u043a \u0436\u0435 \u0438\u043c\u0435\u0435\u0442\u0441\u044f.<\/p>\n<pre><code>return produceState&lt;Result&lt;Image>>(initialValue = Result.Loading, url, imageRepository) { <\/code><\/pre>\n<h2>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c KtorFit+Room \u0438 Clean Architecture \u043e\u043f\u0438\u0441\u0430\u043d\u0430 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 <a href=\"https:\/\/habr.com\/ru\/articles\/765416\/\" rel=\"noopener noreferrer nofollow\">https:\/\/habr.com\/ru\/articles\/765416\/<\/a><\/p>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u0432 \u0432\u0435\u0442\u043a\u0435 \u043d\u0430 GitHub <a href=\"https:\/\/github.com\/app-z\/NoArchitecture-Kotlin-Compose\/tree\/architecture\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/app-z\/NoArchitecture-Kotlin-Compose\/tree\/architecture<\/a><\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0425\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043a\u0440\u043e\u0441\u0441-\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435. Compose \u044d\u0442\u043e \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u0432 \u0447\u0430\u0441\u0442\u0438 UI. \u041c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043a\u0430 \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442?<\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c xcode-kotlin \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c. \u041f\u043e\u0441\u043b\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043f\u043b\u0430\u0433\u0438\u043d\u0430 XCode \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043b\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c\u0441\u044f. \u0423\u0434\u0430\u043b\u043e\u0441\u044c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043e\u0442 \u0440\u0443\u0442\u0430 sudo .\/Xcode \u0445\u043e\u0442\u044f kdoctor \u043d\u0435 \u043d\u0430\u0448\u0435\u043b \u043f\u0440\u043e\u0431\u043b\u0435\u043c.<\/p>\n<p><code>brew install xcode-kotlin<\/code><\/p>\n<p><code>xcode-kotlin install<\/code><\/p>\n<pre><code>MacBook MacOS % kdoctor                                                                                                     Environment diagnose (to see all details, use -v option): [\u2713] Operation System [\u2713] Java [\u2713] Android Studio [\u2713] Xcode [\u2713] Cocoapods  Conclusion:   \u2713 Your system is ready for Kotlin Multiplatform Mobile Development!<\/code><\/pre>\n<p>\u041c\u043d\u0435\u043d\u0438\u0435 \u043e\u043f\u044b\u0442\u043d\u044b\u0445 \u041a\u043e\u043c\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u043e\u0432 \u0441\u0442\u0440\u043e\u0433\u043e \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442\u0441\u044f.<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u0441\u044b\u043b\u043a\u0438<\/summary>\n<div class=\"spoiler__content\">\n<p><a href=\"https:\/\/github.com\/app-z\/NoArchitecture-Kotlin-Compose\/tree\/main\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/app-z\/NoArchitecture-Kotlin-Compose\/tree\/main<\/a><\/p>\n<p><a href=\"https:\/\/developer.android.com\/jetpack\/compose\/tutorial\" rel=\"noopener noreferrer nofollow\">https:\/\/developer.android.com\/jetpack\/compose\/tutorial<\/a><\/p>\n<p><a href=\"https:\/\/kotlinlang.org\/docs\/multiplatform-mobile-upgrade-app.html\" rel=\"noopener noreferrer nofollow\">https:\/\/kotlinlang.org\/docs\/multiplatform-mobile-upgrade-app.html<\/a><\/p>\n<p><a href=\"https:\/\/developer.android.com\/jetpack\/compose\/touch-input\/handling-interactions\" rel=\"noopener noreferrer nofollow\">https:\/\/developer.android.com\/jetpack\/compose\/touch-input\/handling-interactions<\/a><\/p>\n<p><a href=\"https:\/\/ktor.io\/docs\/getting-started-ktor-client-multiplatform-mobile.html\" rel=\"noopener noreferrer nofollow\">https:\/\/ktor.io\/docs\/getting-started-ktor-client-multiplatform-mobile.html<\/a><\/p>\n<p><a href=\"https:\/\/developer.android.com\/jetpack\/compose\/side-effects\" rel=\"noopener noreferrer nofollow\">https:\/\/developer.android.com\/jetpack\/compose\/side-effects<\/a><\/p>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/6514c5f9e993b17686a280e5\" data-style=\"\" id=\"6514c5f9e993b17686a280e5\" width=\"\"><\/div>\n<\/p>\n<\/div>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><\/p>\n<div class=\"tm-article-poll-container\"><!--[--><\/p>\n<div class=\"tm-article-poll tm-article-poll_variant-bordered\">\n<div class=\"tm-notice tm-notice_positive tm-article-poll__notice\"><!----><\/p>\n<div class=\"tm-notice__inner\"><!----><\/p>\n<div class=\"tm-notice__content\" data-test-id=\"notice-content\"><!--[--><span>\u0422\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043c\u043e\u0433\u0443\u0442 \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432 \u043e\u043f\u0440\u043e\u0441\u0435. <a rel=\"nofollow\" href=\"\/kek\/v1\/auth\/habrahabr\/?back=\/ru\/articles\/763980\/&#038;hl=ru\">\u0412\u043e\u0439\u0434\u0438\u0442\u0435<\/a>, \u043f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430.<\/span><!--]--><\/div>\n<\/div>\n<\/div>\n<p><!--[--><\/p>\n<div class=\"tm-article-poll__header\">\u0417\u0430 Compose \u0431\u0443\u0434\u0443\u0449\u0435\u0435<\/div>\n<div class=\"tm-article-poll__answers\"><!--[--><\/p>\n<div class=\"tm-article-poll__answer\">\n<div class=\"tm-article-poll__answer-data\"><span class=\"tm-article-poll__answer-percent tm-article-poll__answer-percent_winning\">85.19% <\/span><span class=\"tm-article-poll__answer-label\">\u0414\u0430<\/span><span class=\"tm-article-poll__answer-votes\">23<\/span><\/div>\n<div class=\"tm-article-poll__answer-bar\">\n<div class=\"tm-article-poll__answer-progress tm-article-poll__answer-progress_winning\" style=\"width: 85.19%\"><\/div>\n<\/div>\n<\/div>\n<div class=\"tm-article-poll__answer\">\n<div class=\"tm-article-poll__answer-data\"><span class=\"tm-article-poll__answer-percent\">14.81% <\/span><span class=\"tm-article-poll__answer-label\">\u041d\u0435\u0442. \u041f\u043e\u0438\u0433\u0440\u0430\u044e\u0442 \u0438 \u0431\u0440\u043e\u0441\u044f\u0442<\/span><span class=\"tm-article-poll__answer-votes\">4<\/span><\/div>\n<div class=\"tm-article-poll__answer-bar\">\n<div class=\"tm-article-poll__answer-progress\" style=\"width: 14.81%\"><\/div>\n<\/div>\n<\/div>\n<p><!--]--><\/div>\n<div class=\"tm-article-poll__stats\"> \u041f\u0440\u043e\u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043b\u0438 27 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439.   \u0412\u043e\u0437\u0434\u0435\u0440\u0436\u0430\u043b\u0438\u0441\u044c 11 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439. <\/div>\n<p><!--]--><\/div>\n<p><!--]--><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/763980\/\"> https:\/\/habr.com\/ru\/articles\/763980\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>\u041d\u0430\u0447\u0430\u043b\u043e<\/h2>\n<p>\u0412\u0441\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0432 <em>setContent<\/em>. <em>ComposeGenAppTheme<\/em> \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u0430. <em>Surface<\/em> \u043a\u0441\u0442\u0430\u0442\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0435\u0431\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 <em>Box.<\/em> \u041d\u0435 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u043e \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0431\u0435\u0437 XML. \u0425\u043e\u0442\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0432\u043e Fragmets \u043a\u0430\u043a View \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u0430 <a href=\"https:\/\/developer.android.com\/jetpack\/compose\/migrate\/interoperability-apis\/compose-in-views\" rel=\"noopener noreferrer nofollow\">Using Compose in Views<\/a>.<\/p>\n<pre><code class=\"kotlin\">        setContent {             ComposeGenAppTheme {                 Surface(                     modifier = Modifier.fillMaxSize(),                     color = MaterialTheme.colorScheme.background                 ) { <\/code><\/pre>\n<p>\u041f\u0440\u043e TabRow \u0440\u0430\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0443. \u041a\u043e\u043c\u0443 \u043d\u0430\u0434\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u0441\u043a\u043e\u043f\u0438\u043f\u0430\u0441\u0442\u0438\u0442 \u0438\u0437 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 <a href=\"https:\/\/github.com\/app-z\/NoArchitecture-Kotlin-Compose.git\" rel=\"noopener noreferrer nofollow\"><abbr class=\"habraabbr\" title=\"NoArchitecture\u2011Kotlin\u2011Compose\" data-title=\"&lt;p>t;p>NoArchitecture\u2011Kotlin\u2011Compose&lt;\/p>&#187; data-abbr=&#187;https:\/\/github.com\/app\u2011z\/NoArchitecture\u2011Kotlin\u2011Compose.git&#187;>NoArchitecture\u2011Kotlin\u2011Compose.git<\/abbr><\/a> \u0430 \u043a\u0442\u043e \u0437\u0430\u0445\u043e\u0447\u0435\u0442 \u0432\u043d\u0438\u043a\u043d\u0443\u0442\u044c, \u043d\u0430 Youtybe \u0435\u0441\u0442\u044c \u0432\u0438\u0434\u0435\u043e. \u041d\u0430 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u043c \u0432\u0435\u0441\u044c\u043c\u0430 \u043f\u043e\u043d\u044f\u0442\u043d\u043e. \u0421\u0441\u044b\u043b\u043a\u0430 \u0432\u043d\u0438\u0437\u0443 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<pre><code>                        TabRow(selectedTabIndex = selectedTabIndex) {                             tabItems.forEachIndexed { index, item ->                                 Tab(selected = index == selectedTabIndex,                                     onClick = {                                         selectedTabIndex = index                                     },                                     text = {                                         Text(item.title)                                     },                                     icon = {                                         Icon(                                             imageVector = if (index == selectedTabIndex) {                                                 item.selectedItem                                             } else {                                                 item.unselectedItem                                             },                                             contentDescription = item.title                                         )                                     })                             }                         } <\/code><\/pre>\n<h2>\u041f\u0440\u0435\u0434\u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440<\/h2>\n<p>\u0414\u043b\u044f preview \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 \u0441 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439 <a class=\"mention\" href=\"\/users\/Preview\">@Preview<\/a>. \u041f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0447\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432\u044b\u0439\u0434\u0435\u0442 \u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u044d\u0442\u043e\u0439 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439. \u041f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u0440\u0443\u0447\u043d\u0443\u044e.<\/p>\n<figure class=\"full-width\">\n<div><figcaption>Preview<\/figcaption><\/div>\n<\/figure>\n<pre><code class=\"kotlin\">@Preview @Composable fun PreviewConversation() {     ComposeGenAppTheme {         FalconInfoListView(SampleData.getRockets())     } } <\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0441\u043f\u0438\u0441\u043e\u043a, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u0437 <em>FalconInfo.<\/em><\/p>\n<pre><code>class SampleData {     companion object {         private const val mesageSize = 10;         private val conversationSample: List&lt;FalconInfo> = buildList&lt;FalconInfo>(mesageSize) {             for (i in 0 until mesageSize) {                 add(FalconInfo(name = \"Name $i\",                     rocket = \"Rocket $i\",                     details = \"Detail can be long, Detail can be long, Detail can be long, Detail can be long, Detail can be long, Detail can be long, \"))             }         }          fun getRockets(): List&lt;FalconInfo> {             return conversationSample         }     } } <\/code><\/pre>\n<h2>\u041d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u0438<\/h2>\n<p>Re<em>member<\/em> &#8212; \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 State, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <em>mutableIntStateOf<\/em>.  \u0417\u0430\u0442\u0435\u043c \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 selectedTabIndex \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043b\u044e\u0447\u0430 LaunchedEffect(key) \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u044f. Compose \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0436\u0438\u0432\u0435\u0442 \u043a\u0430\u043a \u0431\u044b \u0432 \u0432\u043e\u0437\u0434\u0443\u0445\u0435. \u041e\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0441\u0430\u043c\u0430 \u0441\u0435\u0431\u044f \u0438 \u0447\u0442\u043e\u0431\u044b \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0441\u044f selectedTabIndex \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <em>remember. <\/em><\/p>\n<pre><code class=\"kotlin\">                    var selectedTabIndex by remember {                         mutableIntStateOf(0)                     }                       LaunchedEffect(selectedTabIndex) {                         pagerState.animateScrollToPage(selectedTabIndex)                     } <\/code><\/pre>\n<h2>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0441\u0435\u0442\u0438. \u0412\u044b\u0432\u043e\u0434 \u0441\u043f\u0438\u0441\u043a\u0430<\/h2>\n<p>\u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 FalconInfo \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f http \u0437\u0430\u043f\u0440\u043e\u0441. \u042d\u0442\u043e \u043a\u043e\u0434 \u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430. \u0427\u0442\u043e\u0431\u044b \u043a\u0430\u043a \u0442\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0432\u0432\u0435\u043b <em>mutableStateOf <\/em>\u043d\u0430 \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441 \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442. \u0427\u0442\u043e \u043d\u0435 \u043e\u0441\u043e\u0431\u043e \u043f\u043e\u043c\u043e\u0433\u043b\u043e. \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u0441\u0435 \u0441\u0442\u0430\u043b\u043e \u0431\u0435\u0441\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044c\u043d\u043e \u0442\u0440\u0438\u0433\u0433\u0435\u0440\u0438\u0442\u0441\u044f \u0438 \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u043e\u0448\u0438\u0431\u043a\u0438.<\/p>\n<pre><code class=\"kotlin\">                    var status by remember { mutableStateOf(\"Loading\") }                     ...                     LaunchedEffect(true) {                         scope.launch {                             status = try {                                 rockets = Greeting().greeting()                                 \"Ok\"                             } catch (e: Exception) {                                 e.localizedMessage ?: \"error\"                             }                         }                     }                     GreetingView(text)                      <\/code><\/pre>\n<p>Http \u0437\u0430\u043f\u0440\u043e\u0441 \u0438 json \u043f\u0430\u0440\u0441\u0435\u0440 Ktor. \u0410 \u043a\u0430\u043a \u0436\u0435 Retrofit?<\/p>\n<pre><code class=\"kotlin\">  class SpaceX {      private val httpClient = HttpClient {         install(HttpCache)         install(ContentNegotiation) {             json(Json {                 prettyPrint = true                 isLenient = true                 ignoreUnknownKeys = true             })         }     }      @Throws(Exception::class)     suspend fun getRockets(): List&lt;FalconInfo> {         val rockets: Array&lt;FalconInfo> =             httpClient.get(\"https:\/\/api.spacexdata.com\/v4\/launches\").body()         return rockets.asList()     } } <\/code><\/pre>\n<p>\u0424\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. <em>Preview<\/em> \u0441 \u043c\u043e\u043a\u0430\u043c\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0435\u0433\u043e \u0436\u0435. \u041c\u0430\u0433\u0438\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u043e\u0432 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 <em>LazyColumn<\/em> \u0438 \u043d\u0430\u0434\u043e \u0435\u0433\u043e \u043a\u043e\u043f\u043d\u0443\u0442\u044c \u043d\u0430 \u043f\u0440\u0435\u0434\u043c\u0435\u0442 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438. \u041f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u0442\u0430\u0440\u0442\u0435 \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u0442\u043e\u0440\u043c\u0430\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u043d\u0430 \u0441\u0442\u0430\u0440\u043e\u043c \u0444\u043b\u0430\u0433\u043c\u0430\u043d\u0435. \u041f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u043a\u0440\u0443\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u0432\u0441\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043f\u043b\u0430\u0432\u043d\u044b\u043c. \u041d\u0430\u0434\u043e \u043e\u0442\u0434\u0430\u0442\u044c \u0434\u043e\u043b\u0436\u043d\u043e\u0435 \u0430\u0432\u0442\u043e\u0440\u0430\u043c. \u0421 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043a\u043e\u0434\u0430, \u0431\u0435\u0437 \u0445\u043e\u043b\u0434\u0435\u0440\u043e\u0432 \u0438 \u043f\u044d\u0439\u043b\u043e\u0430\u0434\u0435\u0440\u043e\u0432 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a. \u041d\u0430\u0434\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043a\u0430\u043a \u0435\u0433\u043e &#171;\u043f\u0440\u043e\u0433\u0440\u0435\u0442\u044c&#187; \u043f\u0440\u0438 \u0441\u0442\u0430\u0440\u0442\u0435 \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e.<\/p>\n<pre><code class=\"kotlin\">@Composable fun FalconInfoListView(falconInfos: List&lt;FalconInfo>) {     LazyColumn {         items(falconInfos) { falconInfos ->             FalconInfoCard(falconInfos)         }     } } <\/code><\/pre>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u043a\u0430\u0440\u0442\u043e\u0447\u043a\u0438. \u041d\u0438\u0436\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u0434 \u0433\u0434\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u0441\u043f\u0438\u0441\u043e\u043a. PreviewMessageCard \u044d\u0442\u043e \u043f\u0440\u0435\u0434\u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441\u043f\u0438\u0441\u043a\u0430. \u0418\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043e\u0442 \u0413\u0443\u0433\u043b\u0430 \u0432\u0437\u044f\u043b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0435\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430. \u0415\u0441\u043b\u0438 \u0442\u0435\u043a\u0441\u0442 \u0434\u043b\u0438\u043d\u043d\u0435\u0435 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438. \u041a\u0441\u0442\u0430\u0442\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043d\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0441\u043a\u0440\u043e\u043b\u0438\u0442\u044c \u0432\u0432\u0435\u0440\u0445 \u0438\u043b\u0438 \u0432\u043d\u0438\u0437, \u043a\u043e\u0433\u0434\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0435\u0432\u0438\u0434\u0438\u043c\u044b\u043c. recyclerview \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c?<\/p>\n<p>AsyncImage &#8212; \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438<code>coil<\/code><\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u0430\u0440\u0442\u043e\u0447\u043a\u0438<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"kotlin\">@Composable fun FalconInfoCard(falconInfo: FalconInfo) {     Row(modifier = Modifier.padding(all = 8.dp)) {          AsyncImage(             placeholder = rememberVectorPainter(Icons.Filled.Rocket),             model = falconInfo.links?.patch?.small,             contentDescription = null,             contentScale = ContentScale.FillWidth,             modifier = Modifier                 .size(40.dp)                 .clip(CircleShape)             \/\/.aspectRatio(0.8F)         )          Spacer(modifier = Modifier.width(8.dp))          var isExpanded by remember { mutableStateOf(false) }          val surfaceColor by animateColorAsState(             if (isExpanded) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.surface,             label = \"surf_color\",         )          Column(modifier = Modifier.clickable { isExpanded = !isExpanded })         {             falconInfo.name?.let {                 Text(                     text = it,                     color = MaterialTheme.colorScheme.secondary                 )             }              Spacer(modifier = Modifier.height(4.dp))              Surface(                 shape = MaterialTheme.shapes.medium,                 shadowElevation = 1.dp,                 \/\/ surfaceColor color will be changing gradually from primary to surface                 color = surfaceColor,                 \/\/ animateContentSize will change the Surface size gradually                 modifier = Modifier                     .animateContentSize()                     .padding(1.dp)             ) {                 falconInfo.details?.let {                     Text(                         text = it,                         maxLines = if (isExpanded) Int.MAX_VALUE else 1,                         style = MaterialTheme.typography.bodyMedium                     )                 }             }         }     } }  @Preview @Composable fun PreviewMessageCard() {     FalconInfoCard(         FalconInfo(             staticFireDateUtc = \"234234234\",             staticFireDateUnix = 1,             name = \"Rocket\", rocket = \"N1\",             details = \"Detail can be long, Detail can be long, Detail can be long, \"         )     )  }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<figure class=\"full-width\">\n<div><figcaption>\u041a\u0430\u0440\u0442\u043e\u0447\u043a\u0430<\/figcaption><\/div>\n<\/figure>\n<h2>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u044b<\/h2>\n<p>\u041f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432 Runtime. \u041f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043f\u043e\u043a\u0443\u0440\u0438\u0442\u044c \u043c\u0430\u043d\u0443\u0430\u043b\u044b<\/p>\n<details class=\"spoiler\">\n<summary> The coroutine scope left the composition<\/summary>\n<div class=\"spoiler__content\">\n<p><a href=\"https:\/\/developer.android.com\/jetpack\/compose\/side-effects\" rel=\"noopener noreferrer nofollow\">https:\/\/developer.android.com\/jetpack\/compose\/side-effects<\/a><\/p>\n<p><code>produceState<\/code><br \/> launches a coroutine scoped to the Composition that can push values into a<br \/> returned <code>State<\/code>. Use it to<br \/> convert non-Compose state into Compose state, for example bringing external<br \/> subscription-driven state such as <code>Flow<\/code>, <code>LiveData<\/code>, or <code>RxJava<\/code> into the<br \/> Composition<\/p>\n<\/div>\n<\/details>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0439 \u043e\u0431\u0435\u0440\u0442\u043a\u043e\u0439. \u0422\u0435\u043f\u0435\u0440\u044c \u0443\u0436\u0435 \u0432\u0441\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e. \u041d\u041e \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u043c\u0435\u0436\u0434\u0443 \u0442\u0430\u0431\u0430\u043c\u0438, \u043f\u0440\u043e\u0441\u043a\u0430\u043a\u0438\u0432\u0430\u0435\u0442 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430. \u0432 \u0432\u0435\u0440\u0441\u0438\u0438 \u0441 LaunchedEffect \u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043e\u043d\u0430 \u043d\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u043b\u0430. <em>initialValue = ResponseResult.Loading <\/em>&#8212; \u0441\u0442\u043e\u0438\u0442 \u043b\u0438 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439?<\/p>\n<pre><code class=\"kotlin\">    val resLoad =         produceState&lt;ResponseResult&lt;List&lt;FalconInfo>>>(initialValue = ResponseResult.Loading) {             value = try {                 ResponseResult.Success(SpaceX().getRockets())             } catch (e: Exception) {                 ResponseResult.Error(e.localizedMessage ?: \"error\")             }         } <\/code><\/pre>\n<p>\u041a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0442\u0438 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u0430\u0440\u0438\u044f. produceState \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c. install(HttpCache) \u0432 \u043f\u0430\u043a\u0435\u0442\u0435 io.ktor.client.plugins.cache \u0442\u0430\u043a \u0436\u0435 \u0438\u043c\u0435\u0435\u0442\u0441\u044f.<\/p>\n<pre><code>return produceState&lt;Result&lt;Image>>(initialValue = Result.Loading, url, imageRepository) { <\/code><\/pre>\n<h2>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c KtorFit+Room \u0438 Clean Architecture \u043e\u043f\u0438\u0441\u0430\u043d\u0430 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 <a href=\"https:\/\/habr.com\/ru\/articles\/765416\/\" rel=\"noopener noreferrer nofollow\">https:\/\/habr.com\/ru\/articles\/765416\/<\/a><\/p>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u0432 \u0432\u0435\u0442\u043a\u0435 \u043d\u0430 GitHub <a href=\"https:\/\/github.com\/app-z\/NoArchitecture-Kotlin-Compose\/tree\/architecture\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/app-z\/NoArchitecture-Kotlin-Compose\/tree\/architecture<\/a><\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0425\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043a\u0440\u043e\u0441\u0441-\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435. Compose \u044d\u0442\u043e \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u0432 \u0447\u0430\u0441\u0442\u0438 UI. \u041c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043a\u0430 \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442?<\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c xcode-kotlin \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c. \u041f\u043e\u0441\u043b\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-356082","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/356082","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=356082"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/356082\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=356082"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=356082"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=356082"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}