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
安全にNavigateしよう
Search
ゆつぼ
April 21, 2023
Technology
0
510
安全にNavigateしよう
Shibuya.apk#41
ゆつぼ
April 21, 2023
Tweet
Share
More Decks by ゆつぼ
See All by ゆつぼ
Glance 3分クッキング
morayl
0
97
CredentialManager移行の落とし穴
morayl
0
910
DAI語で行こう #as_tips / daigo_as_tips
morayl
1
470
Other Decks in Technology
See All in Technology
標準技術と独自システムで作る「つらくない」SaaS アカウント管理 / Effortless SaaS Account Management with Standard Technologies & Custom Systems
yuyatakeyama
3
1.2k
A2Aのクライアントを自作する
rynsuke
1
170
Yamla: Rustでつくるリアルタイム性を追求した機械学習基盤 / Yamla: A Rust-Based Machine Learning Platform Pursuing Real-Time Capabilities
lycorptech_jp
PRO
2
110
セキュリティの民主化は何故必要なのか_AWS WAF 運用の 10 の苦悩から学ぶ
yoh
1
110
OpenHands🤲にContributeしてみた
kotauchisunsun
1
430
BigQuery Remote FunctionでLooker Studioをインタラクティブ化
cuebic9bic
3
270
Welcome to the LLM Club
koic
0
170
_第3回__AIxIoTビジネス共創ラボ紹介資料_20250617.pdf
iotcomjpadmin
0
150
mrubyと micro-ROSが繋ぐロボットの世界
kishima
2
220
地図も、未来も、オープンに。 〜OSGeo.JPとFOSS4Gのご紹介〜
wata909
0
110
Snowflake Summit 2025 データエンジニアリング関連新機能紹介 / Snowflake Summit 2025 What's New about Data Engineering
tiltmax3
0
310
生成AIでwebアプリケーションを作ってみた
tajimon
2
150
Featured
See All Featured
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
Making the Leap to Tech Lead
cromwellryan
134
9.3k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
44
2.4k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
15
1.5k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.8k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.7k
The Power of CSS Pseudo Elements
geoffreycrofte
77
5.8k
Adopting Sorbet at Scale
ufuk
77
9.4k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
790
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
34
5.9k
KATA
mclloyd
29
14k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
233
17k
Transcript
安全にNavigateしよう ゆつぼ@morayl1
自己紹介 • ゆつぼ(@morayl1) • 個人:Footprint(https://github.com/morayl/Footprint) • 仕事:2年間に及ぶ大規模Androidアプリのリニューアルを終えた • うつぼとうなぎが好き
Navigationライブラリ使ってますか? • Navigationをより安全にするinterfaceを作った話 • Fragmentの中でnavigateしている場合 • Composeの時代なので流行りの話ではない
nav_graph.xml
Navigateする方法①:idを使う • nav_graphに定義していないidを指定できてしまう • 間違えてもビルドは通る • SafeArgsが活きない • idとArgsの組み合わせを誤ると、実行時に落ちる
Navigateする方法②:Directionsを使う • 遷移アクションを間違えづらい(Directionsに生えているものしか出来ない) • Directionsを間違える可能性は残る(遷移先を選ぶときに気付ける) • Fragmentの名前が長くなると、Directionsも長くなる • SafeArgsは活きる
Directionsの仕組み nav_graphの<fragment>のidに対応したDirectionsクラスが自動生成される <fragment>内のアクションはcompanion objectに生成されている
いまいちな点まとめ • id・argsを間違える可能性 • 間違えてもビルドは通る • Directionsを間違える可能性は残る(遷移先を選ぶときに気付ける) • Fragmentの名前が長くなると、Directionsも長くなる
Navigatable Github
Navigatable Github Tには、FragmentDirections.Comanionを指定
実装側(Fragment) • navigateラムダ内でアクションが補完表示される • nav_graphに定義していない遷移が出来ない • Directionsを使っているので引数も誤らない • Directionsを空で書くのは1度だけ •
遷移時にxxDirectionsが不要なので短い!読みやすい!(個人の感想)
Navigatable
try/catch • リストなどで同時押しされて遷移する場合(FragmentA→FragmentB)、一回目のク リック処理でBに遷移した後二回目の処理時にBに遷移しようとする • が、すでにBに遷移しているため、B→Bの遷移が定義されていないと IllegalArgumentExceptionが発生する • Exceptionを用いずに、 findNavController().currentDestination?.getAction(directions.actionId)
でnullチェックすることでも回避できる A B B
まとめ Navigatableを使うと、安全・簡潔にnavigate出来ます! Navigatable.kt