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
安全にNavigateしよう
Search
ゆつぼ
April 21, 2023
Technology
570
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
150
CredentialManager移行の落とし穴
morayl
0
1.7k
DAI語で行こう #as_tips / daigo_as_tips
morayl
1
540
Other Decks in Technology
See All in Technology
顧客に向き合う開発組織へ。リアーキテクチャとフィーチャーチーム化で挑む組織改革
safie
0
1.9k
山手線を徒歩で一周してわかった、 位置情報アプリは「足」が最強のデバッガー
hinakko
0
150
AI時代、データエンジニアが一番おもろい
genshun9
0
580
品質と信頼性を地続きにする
grimoh
0
370
Reactの設計論
uhyo
24
13k
2026_devsumi_ozono.pdf
o3
3
500
技術的負債から考える、AI時代のエンジニアリング投資 — ビズリーチの技術的負債と向き合った経験から、変更し続けられるソフトウェアを考える/ technical-debt-con2026
visional_engineering_and_design
3
2.9k
aws-iot-platform-architecture-use-cases.pdf
ma2shita
0
110
登壇の自信を奪う3匹のオバケ / 3 Ghosts That Rob You of Your Confidence in Public Speaking
pauli
8
910
AIネイティブプロダクトで顧客価値を最大化するプロダクトエンジニアとFDEの協働
righttouch
PRO
0
310
What the customer really needed
kawaguti
PRO
1
160
OpenTelemetry eBPF Instrumentationの舞台裏 / Behind the Scenes of OpenTelemetry eBPF Instrumentation
ymotongpoo
4
1.3k
Featured
See All Featured
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
280
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
3
4.3k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
56
3.5k
Navigating Team Friction
lara
192
16k
A designer walks into a library…
pauljervisheath
211
25k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
380
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
540
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
690
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
10k
4 Signs Your Business is Dying
shpigford
187
23k
Amusing Abliteration
ianozsvald
1
300
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.1k
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