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
560
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
安全にNavigateしよう
Shibuya.apk#41
ゆつぼ
April 21, 2023
More Decks by ゆつぼ
See All by ゆつぼ
Glance 3分クッキング
morayl
0
140
CredentialManager移行の落とし穴
morayl
0
1.6k
DAI語で行こう #as_tips / daigo_as_tips
morayl
1
530
Other Decks in Technology
See All in Technology
AIをフル活用してオンコール機能のプロトタイプを2日で作った話 / Building an AI-Powered On-Call Prototype in Just Two Days
nari_ex
0
170
RAGの精度向上とエージェント活用
kintotechdev
2
130
LiDAR SLAMの実装とセンサ融合 ~Lie群からContinuous-Time LIOまで~
naokiakai
1
940
デジタル・デザイン構想 by Sayaka Ishizuka
y150saya
0
190
MySQL & MySQL HeatWave Report - June 2026
freshdaz
0
300
“ID沼入口” - 基本とセキュリティから始める、考え続けるためのID管理技術勉強会 告知&イントロ
ritou
0
380
From Prompt Engineering to Loop Engineering
shibuiwilliam
1
330
CVE-2026-20833_脆弱性対応とAES 化について
jukishiya
0
350
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
11k
AI駆動開発におけるQAエンジニアの役割事例 〜AI駆動開発の現場から〜
kobayashiyorimitsu
0
290
Claude Code 珍プレー好プレー
shinyasaita
0
130
打造你的 AI 工作流:Agent Skill + MCP 實戰工作坊
appleboy
0
500
Featured
See All Featured
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
330
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
72
40k
From π to Pie charts
rasagy
0
230
Designing Powerful Visuals for Engaging Learning
tmiket
1
440
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.5k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
460
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.8k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
620
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
10k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
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