Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
AndroidのViewにおける ステートフルとステートレスと状態ホルダーの話/android...
Search
suzukiyoshitaka
October 18, 2023
Programming
360
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
AndroidのViewにおける ステートフルとステートレスと状態ホルダーの話/android-view-stateful-stateless-stateholder
下記勉強会イベントで発表した内容です。
https://wantedly.connpass.com/event/297601/
suzukiyoshitaka
October 18, 2023
Other Decks in Programming
See All in Programming
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
35
17k
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
2
150
JIS keyboard support in Omarchy
lef237
0
120
見えないものを探る要求要件定義に必要な基本的思考 / invisible-requirement-thinking
minodriven
15
8.5k
なぜCTOを降りてFDEを選んだのか?〜なぜプロダクト企業がFDEで顧客の現場に踏み込むのか〜
gonta
1
210
Domain-Driven Transformation
hschwentner
2
2.3k
パズルゲームの作り方 / how to make puzzle games
kaityo256
PRO
2
290
Compiling a real-world CLI tool to native with Static Hermes
tmikov2023
0
120
AmebaブログはKMPから卒業します
kmars0605
0
190
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
28
32k
APNsからLive Activityを開始する話
yumnumm
0
170
パスワード再設定メールのURLについて知っておこう
uyuki234
0
160
Featured
See All Featured
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.9k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
Speed Design
sergeychernyshev
33
2.2k
Making Projects Easy
brettharned
120
6.8k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
120
120k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
How to Think Like a Performance Engineer
csswizardry
28
2.9k
Producing Creativity
orderedlist
PRO
348
41k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
710
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
2
410
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
270
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
480
Transcript
We are the future. www.team-lab.com チームラボ株式会社 teamLab inc. AndroidのViewにおける ステートフルとステートレスと
状態ホルダーの話
We are the future. www.team-lab.com チームラボ株式会社 teamLab inc. 自己紹介 鈴木善陽(スズキ
ヨシタカ) チームラボ所属 Androidエンジニア4年目 Fitbit Charge 6 買いました
We are the future. www.team-lab.com チームラボ株式会社 teamLab inc. 1. 発端
2. ステートフルって? a. ステートフルの特徴 3. ステートレスって? a. ステートレスの特徴 4. どちらを選択するべき? 5. まとめ 目次
We are the future. www.team-lab.com チームラボ株式会社 teamLab inc. • UIの状態はViewModelで持つべきだと漠然と思っていた🤔
• Android Viewではあまり意識しなかったけど、Composeだと rememberやrememberSaveableといった概念が登場した ステートレスやステートフル、 状態ホルダーについて良く知りたくなった💡 発端
We are the future. www.team-lab.com チームラボ株式会社 teamLab inc. ステートフルって?
We are the future. www.team-lab.com チームラボ株式会社 teamLab inc. • ViewがUI状態を持っていること
ステートフルって?
We are the future. www.team-lab.com チームラボ株式会社 teamLab inc. ステートフルって? •
呼び出し側
We are the future. www.team-lab.com チームラボ株式会社 teamLab inc. • メリット
◦ 呼び出し側はViewの状態を考慮しなくて良い ▪ 値を渡したり、渡されなくて良いので、スッキリかける • デメリット ◦ テストしづらい ▪ Composable内でロジックがある場合、 ViewModelのUnitTestではカバーできない ◦ ビジネスロジックから制御できない ステートフルの特徴
We are the future. www.team-lab.com チームラボ株式会社 teamLab inc. ステートレスって?
We are the future. www.team-lab.com チームラボ株式会社 teamLab inc. • ViewがUI状態を持っていないこと
ステートレスって?
We are the future. www.team-lab.com チームラボ株式会社 teamLab inc. • 呼び出し側
ステートレスって?
We are the future. www.team-lab.com チームラボ株式会社 teamLab inc. • ViewModel
ステートレスって?
We are the future. www.team-lab.com チームラボ株式会社 teamLab inc. • メリット
◦ UIとロジックの関心が分離できる ◦ ビジネスロジックから制御ができる ◦ UIを再利用しやすい • デメリット ◦ コードが複雑になる ▪ ビジネスロジックから UIの間でデータのやりとりがコードに現れる ステートレスの特徴
We are the future. www.team-lab.com チームラボ株式会社 teamLab inc. どちらを選択すべき?
We are the future. www.team-lab.com チームラボ株式会社 teamLab inc. 公式資料を読んでみる どちらを選択すべき?
We are the future. www.team-lab.com チームラボ株式会社 teamLab inc. どちらを選択すべき? •
ビジネスロジックから制御する必要のない部分はステートフル ◦ 例:スクロール状態 ◦ 例:Expand、Collapseの動作 • ビジネスロジックから制御する必要がある部分はステートレス ◦ 例:TextFieldへ入力した値に対するバリデーション ◦ 例:Horizontal PagerとTab Rowで、APIの返却によって選択タブを制御 状況に応じてハイブリッドに組み合わせる
We are the future. www.team-lab.com チームラボ株式会社 teamLab inc. 参考:https://developer.android.com/topic/architecture/ui-layer/stateholders?hl=ja#choose-viewmodel どちらを選択すべき?
「最終的には、消費される場所に最も近い 状態ホルダーを使用して UI 状態を生成す る必要があります。」 by 公式
We are the future. www.team-lab.com チームラボ株式会社 teamLab inc. 実際にコードで見てみる どちらを選択すべき?
We are the future. www.team-lab.com チームラボ株式会社 teamLab inc. どちらを選択すべき?
We are the future. www.team-lab.com チームラボ株式会社 teamLab inc. 参考:https://developer.android.com/topic/architecture/ui-layer/stateholders?hl=ja#choose-viewmodel イベント
状態 状態ホルダーまで遠い どちらを選択すべき?
We are the future. www.team-lab.com チームラボ株式会社 teamLab inc. どちらを選択すべき?
We are the future. www.team-lab.com チームラボ株式会社 teamLab inc. 参考:https://developer.android.com/topic/architecture/ui-layer/stateholders?hl=ja#choose-viewmodel イベント
状態 状態ホルダーまで近い どちらを選択すべき?
We are the future. www.team-lab.com チームラボ株式会社 teamLab inc. どちらを選択すべき? •
今回のサンプルの場合だと... ◦ バリデーションなど、ビジネスロジックを通してから UI状態を決定したい →ステートレス ◦ ビジネスロジックを通す必要がない、 ただ入力状態を表示するだけで良い →ステートフル
We are the future. www.team-lab.com チームラボ株式会社 teamLab inc. まとめ できるだけ状態ホルダーまでの道のりは短くしつつ、
ステートレスとステートフルを使い分ける or 組み合わせる
We are the future. www.team-lab.com チームラボ株式会社 teamLab inc. EOF