{"id":45786,"date":"2021-11-24T14:43:21","date_gmt":"2021-11-24T05:43:21","guid":{"rendered":"https:\/\/www.charlezz.com\/?p=45786"},"modified":"2021-11-24T14:43:23","modified_gmt":"2021-11-24T05:43:23","slug":"migrating-to-jetpack-compose-viewcompositionstrategy","status":"publish","type":"post","link":"https:\/\/charlezz.com\/?p=45786","title":{"rendered":"Migrating to Jetpack Compose &#8211; ViewCompositionStrategy"},"content":{"rendered":"\n<p>\uae30\ubcf8\uc801\uc73c\ub85c \ucef4\ud3ec\uc988\ub294 ComposeView\uac00 \uc708\ub3c4\uc6b0\uc5d0\uc11c \ubd84\ub9ac\ub420 \ub54c\ub9c8\ub2e4 <a href=\"https:\/\/developer.android.com\/jetpack\/compose\/lifecycle\">\ucef4\ud3ec\uc9c0\uc158\uc744 \uc0ad\uc81c<\/a>\ud55c\ub2e4. \uc774\ub7f0 \ubd80\ubd84\uc740 ComposeView\uac00 \ud504\ub808\uadf8\uba3c\ud2b8\ub0b4\uc5d0\uc11c \uc0ac\uc6a9\ub420 \ub54c \uc5ec\ub7ec\uac00\uc9c0 \uc774\uc720\ub85c \ubc14\ub78c\uc9c1 \ud558\uc9c0\uc54a\ub2e4.<\/p>\n\n\n\n<ul><li>\ucef4\ud3ec\uc9c0\uc158\uc740 Compose UI \ubcf4\uae30 \ud0c0\uc785\uc774 \uc0c1\ud0dc\ub97c \uc800\uc7a5\ud558\uae30 \uc704\ud574, \ud504\ub798\uadf8\uba3c\ud2b8\uc758 View \uc0dd\uba85\uc8fc\uae30\ub97c \ub530\ub77c\uc57c \ud55c\ub2e4.<\/li><li>\ud2b8\ub79c\uc9c0\uc158 \ub610\ub294 \uc708\ub3c4\uc6b0 \ud2b8\ub79c\uc9c0\uc158\uc774 \ubc1c\uc0dd\ud560 \ub54c Compose UI \uc694\uc18c\ub97c \ud654\uba74\uc5d0 \uc720\uc9c0\ud55c\ub2e4\ub294 \uac83\uc740, \uc804\ud658\ud558\ub294 \ub3d9\uc548 ComposeView \uc790\uccb4\ub294 \uc708\ub3c4\uc6b0\uc5d0\uc11c \ubd84\ub9ac\ub41c \ud6c4\uc5d0\ub3c4 \uacc4\uc18d \ud45c\uc2dc\ub428\uc744 \uc758\ubbf8 \ud55c\ub2e4.<\/li><\/ul>\n\n\n\n<p>AbstractComposeView.disposeComposition \uba54\uc11c\ub4dc\ub97c \uc218\ub3d9\uc73c\ub85c \ud638\ucd9c\ud558\uc5ec \ucef4\ud3ec\uc9c0\uc158\uc744 \uc218\ub3d9\uc73c\ub85c \uc0ad\uc81c\ud560 \uc218 \uc788\ub2e4. \ub610\ub294 \ub354 \uc774\uc0c1 \ud544\uc694\ud558\uc9c0 \uc54a\uc744 \ub54c, \ucef4\ud3ec\uc9c0\uc158\uc744 \uc790\ub3d9\uc73c\ub85c \ud3d0\uae30\ud558\ub824\uba74 \ub2e4\ub978 \uc804\ub7b5\uc744 \uc124\uc815\ud558\uac70\ub098 setViewCompositionStrategy \uba54\uc11c\ub4dc\ub97c \ud638\ucd9c\ud558\uc5ec, \uc790\uc2e0\ub9cc\uc758 \uc804\ub7b5\uc744 \ub9cc\ub4e4 \uc218 \uc788\ub2e4.<\/p>\n\n\n\n<p>\uc81c\uacf5\ud558\ub294 DisposeOnViewTreeLifecycleDestroyed \uc804\ub7b5\uc744 \uc0ac\uc6a9\ud558\uc5ec \ud504\ub808\uadf8\uba3c\ud2b8 LifecycleOwner\uac00 \ud30c\uad34\ub420 \ub54c \ucef4\ud3ec\uc9c0\uc158\uc744 \uc0ad\uc81c\ud55c\ub2e4.<\/p>\n\n\n\n<p>PlantDetailFragment\uc5d0\ub294 enter \ubc0f exit \ud2b8\ub79c\uc9c0\uc158\uc774 \uc788\uace0(\uc790\uc138\ud55c \uc815\ubcf4\ub294 nav_garden.xml\uc744 \ud655\uc778) \ub098\uc911\uc5d0 Compose \ub0b4\ubd80\uc5d0\uc11c View \ud0c0\uc785\uc744 \uc0ac\uc6a9\ud560 \uac83\uc774\ubbc0\ub85c, ComposeView\uac00 DisposeOnViewTreeLifecycleDestroyed \uc804\ub7b5\uc744 \uc0ac\uc6a9\ud558\uace0 \uc788\ub294\uc9c0 \ud655\uc2e4\ud788 \ud574\uc57c \ud55c\ub2e4. \ubb50 \uc5b4\uca0c\ub358\uac04\uc5d0 \ud504\ub808\uadf8\uba3c\ud2b8\uc5d0\uc11c ComposeView\ub97c \uc0ac\uc6a9\ud560 \ub54c\ub294 \ud56d\uc0c1 \uc774 \uc804\ub7b5\uc744 \uc124\uc815\ud558\ub294 \uac83\uc774 \uc88b\ub2e4. (<a href=\"https:\/\/developer.android.com\/jetpack\/compose\/interop\/interop-apis#composition-strategy\">ComposeView\uc758 ViewCompositionStrategy<\/a>\ub97c \ucc38\uc870\ud558\uc790)<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">plantdetail\/PlantDetailFragment.kt<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>class PlantDetailFragment : Fragment() {\n\u00a0 \u00a0 ...\n\u00a0 \u00a0 override fun onCreateView(...): View? {\n\u00a0 \u00a0 \u00a0 \u00a0 val binding = DataBindingUtil.inflate&lt;FragmentPlantDetailBinding>(\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 inflater, R.layout.fragment_plant_detail, container, false\n\u00a0 \u00a0 \u00a0 \u00a0 ).apply {\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 ...\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 composeView.apply {\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <strong>\/\/ View\uc758 LifecycleOwner\uac00 \ud30c\uad34\ub420 \ub54c \ucef4\ud3ec\uc9c0\uc158\uc744 \ud3d0\uae30 \ud55c\ub2e4.<\/strong>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <strong>setViewCompositionStrategy(\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 )<\/strong>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 setContent {\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 MaterialTheme {\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 PlantDetailDescription()\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }\n\u00a0 \u00a0 \u00a0 \u00a0 }\n\u00a0 \u00a0 \u00a0 \u00a0 ...\n\u00a0 \u00a0 }\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\uae30\ubcf8\uc801\uc73c\ub85c \ucef4\ud3ec\uc988\ub294 ComposeView\uac00 \uc708\ub3c4\uc6b0\uc5d0\uc11c \ubd84\ub9ac\ub420 \ub54c\ub9c8\ub2e4 \ucef4\ud3ec\uc9c0\uc158\uc744 \uc0ad\uc81c\ud55c\ub2e4. \uc774\ub7f0 \ubd80\ubd84\uc740 ComposeView\uac00 \ud504\ub808\uadf8\uba3c\ud2b8\ub0b4\uc5d0\uc11c \uc0ac\uc6a9\ub420 \ub54c \uc5ec\ub7ec\uac00\uc9c0 \uc774\uc720\ub85c \ubc14\ub78c\uc9c1 \ud558\uc9c0\uc54a\ub2e4. \ucef4\ud3ec\uc9c0\uc158\uc740 Compose UI \ubcf4\uae30 \ud0c0\uc785\uc774 \uc0c1\ud0dc\ub97c \uc800\uc7a5\ud558\uae30 \uc704\ud574, \ud504\ub798\uadf8\uba3c\ud2b8\uc758 View \uc0dd\uba85\uc8fc\uae30\ub97c \ub530\ub77c\uc57c \ud55c\ub2e4. \ud2b8\ub79c\uc9c0\uc158 \ub610\ub294 \uc708\ub3c4\uc6b0 \ud2b8\ub79c\uc9c0\uc158\uc774 \ubc1c\uc0dd\ud560 \ub54c Compose UI \uc694\uc18c\ub97c \ud654\uba74\uc5d0 \uc720\uc9c0\ud55c\ub2e4\ub294 \uac83\uc740, \uc804\ud658\ud558\ub294 \ub3d9\uc548 ComposeView \uc790\uccb4\ub294 \uc708\ub3c4\uc6b0\uc5d0\uc11c \ubd84\ub9ac\ub41c \ud6c4\uc5d0\ub3c4 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"inline_featured_image":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[38],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/posts\/45786"}],"collection":[{"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/charlezz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=45786"}],"version-history":[{"count":1,"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/posts\/45786\/revisions"}],"predecessor-version":[{"id":45787,"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/posts\/45786\/revisions\/45787"}],"wp:attachment":[{"href":"https:\/\/charlezz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=45786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/charlezz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=45786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/charlezz.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=45786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}