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
100
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
31
Gemini in Android Studio I/O extended 2024
veronikapj
0
300
How to use Macrobenchmark
veronikapj
0
260
앱 성능 영혼까지 끌어올리기
veronikapj
0
920
Software Productivity - Devfest Songdo 2023
veronikapj
0
920
파이어베이스로 서비스 품질 올리기
veronikapj
0
310
What's new in Android IO23 Daejeon
veronikapj
1
270
KC23_Coroutine_Testing
veronikapj
0
150
ComposeCamp2022 Pathway2
veronikapj
1
360
Other Decks in Programming
See All in Programming
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.2k
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
120
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
340
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
230
エンジニアとして関わる要件と仕様(公開用)
murabayashi
0
300
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
2
120
watsonx.ai Dojo #4 生成AIを使ったアプリ開発、応用編
oniak3ibm
PRO
1
140
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
1
300
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
900
Ethereum_.pdf
nekomatu
0
460
Featured
See All Featured
Happy Clients
brianwarren
98
6.7k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
Making the Leap to Tech Lead
cromwellryan
133
8.9k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
28
2k
Side Projects
sachag
452
42k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.2k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
Designing the Hi-DPI Web
ddemaree
280
34k
Site-Speed That Sticks
csswizardry
0
28
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ߣ૩ Әࠗఠ दೞࣁਃ