Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
安全にNavigateしよう
Search
ゆつぼ
April 21, 2023
Technology
0
530
安全にNavigateしよう
Shibuya.apk#41
ゆつぼ
April 21, 2023
Tweet
Share
More Decks by ゆつぼ
See All by ゆつぼ
Glance 3分クッキング
morayl
0
110
CredentialManager移行の落とし穴
morayl
0
1.3k
DAI語で行こう #as_tips / daigo_as_tips
morayl
1
510
Other Decks in Technology
See All in Technology
今年のデータ・ML系アップデートと気になるアプデのご紹介
nayuts
1
330
因果AIへの招待
sshimizu2006
0
970
Gemini でコードレビュー知見を見える化
zozotech
PRO
1
250
re:Invent2025 コンテナ系アップデート振り返り(+CloudWatchログのアップデート紹介)
masukawa
0
360
MapKitとオープンデータで実現する地図情報の拡張と可視化
zozotech
PRO
1
140
日本Rubyの会の構造と実行とあと何か / hokurikurk01
takahashim
4
1.1k
ガバメントクラウド利用システムのライフサイクルについて
techniczna
0
190
Lambdaの常識はどう変わる?!re:Invent 2025 before after
iwatatomoya
1
490
AWSセキュリティアップデートとAWSを育てる話
cmusudakeisuke
0
270
チーリンについて
hirotomotaguchi
6
1.9k
グレートファイアウォールを自宅に建てよう
ctes091x
0
150
CARTAのAI CoE が挑む「事業を進化させる AI エンジニアリング」 / carta ai coe evolution business ai engineering
carta_engineering
0
1.2k
Featured
See All Featured
How to Ace a Technical Interview
jacobian
280
24k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
36
6.2k
RailsConf 2023
tenderlove
30
1.3k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.6k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
7.9k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Faster Mobile Websites
deanohume
310
31k
Being A Developer After 40
akosma
91
590k
How STYLIGHT went responsive
nonsquared
100
6k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.6k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.7k
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