Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
2021 ComposeFest2021-Migration to Jetpack Compose
Search
Veronikapj
November 22, 2021
Programming
0
110
2021 ComposeFest2021-Migration to Jetpack Compose
2021 Devfest Korea Android
Jetpack Compose 코드랩 중 Migration to Jetpack Compose 설명 자료입니다.
Veronikapj
November 22, 2021
Tweet
Share
More Decks by Veronikapj
See All by Veronikapj
The Know-how of Seniors in the Age of AI
veronikapj
0
34
Gemini in Android Studio I/O extended 2024
veronikapj
0
320
How to use Macrobenchmark
veronikapj
0
280
앱 성능 영혼까지 끌어올리기
veronikapj
0
960
Software Productivity - Devfest Songdo 2023
veronikapj
0
960
파이어베이스로 서비스 품질 올리기
veronikapj
0
320
What's new in Android IO23 Daejeon
veronikapj
1
270
KC23_Coroutine_Testing
veronikapj
0
150
ComposeCamp2022 Pathway2
veronikapj
1
370
Other Decks in Programming
See All in Programming
Fibonacci Function Gallery - Part 2
philipschwarz
PRO
0
210
週次リリースを実現するための グローバルアプリ開発
tera_ny
1
1.2k
オニオンアーキテクチャを使って、 Unityと.NETでコードを共有する
soi013
0
370
サーバーゆる勉強会 DBMS の仕組み編
kj455
1
300
非ブラウザランタイムとWeb標準 / Non-Browser Runtimes and Web Standards
petamoriken
0
430
CQRS+ES の力を使って効果を感じる / Feel the effects of using the power of CQRS+ES
seike460
PRO
0
240
GitHub CopilotでTypeScriptの コード生成するワザップ
starfish719
26
6k
선언형 UI에서의 상태관리
l2hyunwoo
0
270
PHPカンファレンス 2024|共創を加速するための若手の技術挑戦
weddingpark
0
140
Stackless и stackful? Корутины и асинхронность в Go
lamodatech
0
1.3k
月刊 競技プログラミングをお仕事に役立てるには
terryu16
1
1.2k
PicoRubyと暮らす、シェアハウスハック
ryosk7
0
210
Featured
See All Featured
Documentation Writing (for coders)
carmenintech
67
4.5k
Navigating Team Friction
lara
183
15k
The World Runs on Bad Software
bkeepers
PRO
66
11k
Building Flexible Design Systems
yeseniaperezcruz
328
38k
How to Ace a Technical Interview
jacobian
276
23k
Reflections from 52 weeks, 52 projects
jeffersonlam
348
20k
Why Our Code Smells
bkeepers
PRO
335
57k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
The Cost Of JavaScript in 2023
addyosmani
46
7.2k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Scaling GitHub
holman
459
140k
The Language of Interfaces
destraynor
155
24k
Transcript
Migrating to Jetpack Compose ߓ GDG Korea Android, Coupang [Korea
Android]
Codelab উղ
https://github.com/gdgand/ComposeFest2021 Repo fork೧ࢲ, ѐੋ ࠳ےীࢲ ೯ೞҊ, ٘۽ ԙ թӝӝ! ܻ
Fork ߉ই֬ਵन ٜ࠙ ୭नചܳ ೠߣ ࠗఌ٘۰ਃ! Repo উղ week 4-2-Migrating to Jetpack Compose
https://github.com/gdgand/ComposeFest2021
߄۽ द!
Migration ҅ദ
7 ਵ۽ بੑ
8 Views Compose Views in Compose
Views Compose
<CoordinatorLayout ...> <AppBarLayout ...> <ConstraintLayout ...> <TextView ...> <TextView ...>
</ConstraintLayout> </CoordinatorLayout> 5. Hello, Compose! fragment_plant_detail.xml
<ComposeView android:id="@+id/compose_view" android:layout_width="match_parent" android:layout_height="match_parent"/> <CoordinatorLayout ...> <AppBarLayout ...> </CoordinatorLayout> 5.
Hello, Compose! fragment_plant_detail.xml
5. Hello, Compose! class PlantDetailFragment : Fragment() { .. .
override fun onCreateView(...): View? { val binding = DataBindingUtil.inflate<...> ( inflater, R.layout.fragment_plant_detail, container, fals e ).apply { .. . composeView.setContent { MaterialTheme { PlantDetailDescription( ) } } } .. . } } Compose World
6. Creating a Composable out of XML fragment_plant_detail.xml <TextView android:id="@+id/plant_detail_name"
. . . android:layout_marginStart="@dimen/margin_small" android:layout_marginEnd="@dimen/margin_small" android:gravity="center_horizontal" android:text="@{viewModel.plant.name}" android:textAppearance="?attr/textAppearanceHeadline5" . . . tools:text="Apple" />
6. Creating a Composable out of XML @Composable private fun
PlantName(name: String) { Text( text = name, style = MaterialTheme.typography.h5, modifier = Modifier .fillMaxWidth() .padding(horizontal = dimensionResource(R.dimen.margin_small)) .wrapContentWidth(Alignment.CenterHorizontally) ) } PlantDetailDescription.kt
6. Creating a Composable out of XML @Composable private fun
PlantName(name: String) { Text( text = name, style = MaterialTheme.typography.h5, modifier = Modifier .fillMaxWidth() .padding(horizontal = dimensionResource(R.dimen.margin_small)) .wrapContentWidth(Alignment.CenterHorizontally) ) } android:textAppearance="?attr/textAppearanceHeadline5" PlantDetailDescription.kt
6. Creating a Composable out of XML @Composable private fun
PlantName(name: String) { Text( text = name, style = MaterialTheme.typography.h5, modifier = Modifier .fillMaxWidth() .padding(horizontal = dimensionResource(R.dimen.margin_small)) .wrapContentWidth(Alignment.CenterHorizontally) ) } android:layout_width=“match_parent” PlantDetailDescription.kt
6. Creating a Composable out of XML @Composable private fun
PlantName(name: String) { Text( . . . modifier = Modifier .fillMaxWidth() .padding(horizontal = dimensionResource(R.dimen.margin_small)) .wrapContentWidth(Alignment.CenterHorizontally) ) } android:layout_marginStart="@dimen/margin_small" android:layout_marginEnd="@dimen/margin_small" android:gravity="center_horizontal" PlantDetailDescription.kt
ViewComposition Strategy
10.ViewCompositionStrategy Composable ࣻݺ ӝ
10.ViewCompositionStrategy Composable ࣻݺ ӝ ViewCompositionStrategy. DisposeOnDetachedFromWindow
10.ViewCompositionStrategy • Fragment Fragmentীࢲ ࢎਊػ Composition ࢚క(State)ܳ ೞ۰ݶ Fragment View
lifeCycle ਸ ٮۄঠ פ. • Transitions ജ ژח Window ജ ߊࢤೡ ٸ, Windowীࢲ ܻ࠙ػ റীب ComposeViewо ҅ࣘ द غ؊ۄب, ӝࠄ DisposeOnDetachedFromWindow ۚী ٮۄ ࢚క(State)о ઁؾפ. • RecyclerView ViewHolder ژח ࣻݺ ӝ ҙܻ CustomView Composable ViewCompositionStrategyܳ ٮ۽ ೧ঠ ೞח ாझ
10.ViewCompositionStrategy class PlantDetailFragment : Fragment() { .. . override fun
onCreateView(...): View? { val binding = DataBindingUtil.inflate<...> ( inflater, R.layout.fragment_plant_detail, container, fals e ).apply { .. . composeView.setContent { MaterialTheme { PlantDetailDescription( ) } } } .. . } } Compose World
class PlantDetailFragment : Fragment() { .. . ... } 10.ViewCompositionStrategy
composeView.apply { setViewCompositionStrategy( ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed ) setContent { MaterialTheme { PlantDetailDescription() } } }
ViewCompositionStrategy https://developer.android.com/reference/kotlin/androidx/ compose/ui/platform/ViewCompositionStrategy •DisposeOnDetachedFromWindow •DisposeOnLifecycleDestroyed •DisposeOnViewTreeLifecycleDestroyed
Views in Compose
9. Views in Compose code @Composable fun CustomView() { val
selectedItem = remember { mutableStateOf(0) } AndroidView( factory = { context -> CustomView(context).apply { // View setup } }, update = { view -> // View সؘ ۽ ୶о view.coordinator.selectedItem = selectedItem.value } ) }
@Composable fun <T : View?> AndroidView( factory: ((Context) -> T)?,
modifier: Modifier? = Modifier, update: ((T) -> Unit)? = NoOpUpdate ): Unit https://developer.android.com/reference/kotlin/androidx/compose/ui/viewinterop/package- summary#AndroidView(kotlin.Function1,androidx.compose.ui.Modifier,kotlin.Function1)
ViewModels in Compose
7. ViewModels and LiveData @Composable fun PlantDetailDescription(plantDetailViewModel: PlantDetailViewModel) { ...
}
7. ViewModels and LiveData @Composable fun MyExample( viewModel: ExampleViewModel =
viewModel() ) { /* ... */ } @Composable fun MyExample2( viewModel: ExampleViewModel = viewModel() ) { /* ... */ } LifeCycleOwnerо ইח زউ زੌೠ ੋझఢझܳ ߈ജ https://developer.android.com/jetpack/compose/libraries#viewmodel
Theme ഐജ
11. Interop theming MDC-Android Compose Theme Adapter
୶о উղ
12. Accessibility in Jetpack Compose 15. Advanced state and side
effects in Jetpack Compose ߣ ೯ࢎী ನೣغ ঋ ٮՏٮՏೠ Codelab
4ର 2ߣ૩ Әࠗఠ दೞࣁਃ