SwiftUI: 複数画面をモーダル表示しうる画面実装の注意点

p0dee
1 min readMay 30, 2020

単純な例として、ふたつのボタンが存在し、タップするとそれぞれに紐づいた画面がモーダルで表示されるケースを考える。

モーダル表示にはView.sheet(…)を用いるが、これを以下のように直列で記述するのは誤り。

前者の処理が、後者の処理に上書きされるため、このケースでは”Open Modal A”をタップしても何も起こらない、という結果になる。

各ボタンに対して.sheet(…)を実装することで、正しい挙動を得ることができる

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response