Upgrade to Pro — share decks privately, control downloads, hide ads and more …

モーダルの遷移を理解する

 モーダルの遷移を理解する

iOSDC Japan 2023
2023年9月1日

Yuki Yasoshima

August 29, 2023
Tweet

More Decks by Yuki Yasoshima

Other Decks in Programming

Transcript

  1. Ϟʔμϧͷछྨ w 4IFFU w 'VMM4DSFFO$PWFS w "MFSU w 1PQPWFS w

    $PO fi SNBUJPO%JBMPHʢ"DUJPO4IFFUʣ w .FOV1JDLFS
  2. Ϟʔμϧୈ֊૚ 5BC /BWJHBUJPO 7JFX 5FYU *NBHF -JTU ։͘ 8JOEPX Ϟʔμϧͷ֊૚

    4IFFUͷ৔߹ ϧʔτͷ6*֊૚ 5BC /BWJHBUJPO 7JFX 5FYU *NBHF -JTU
  3. Ϟʔμϧୈ֊૚ 5BC /BWJHBUJPO 7JFX 5FYU *NBHF -JTU 8JOEPX 5BC /BWJHBUJPO

    7JFX 5FYU *NBHF -JTU Ϟʔμϧͷ֊૚ 4IFFUͷ৔߹ ❌։͚ͳ͍ ϧʔτͷ6*֊૚
  4. Ϟʔμϧୈ֊૚ Ϟʔμϧୈ֊૚ 5BC /BWJHBUJPO 7JFX 5FYU *NBHF -JTU ։͘ 8JOEPX

    5BC /BWJHBUJPO 7JFX 5FYU *NBHF -JTU Ϟʔμϧͷ֊૚ 4IFFUͷ৔߹ ϧʔτͷ6*֊૚
  5. ϞʔμϧͷભҠͷίʔυ JT1SFTFOUFE struct ContentView: View { @State var isPresented: Bool

    = false var body: some View { Button(“Show") { isPresented = true } .sheet(isPresented: $isPresented) { ... } } } όΠϯυͨ͠஋Λมߋ͢ΔͱભҠ #PPMͷ஋ΛόΠϯυ͢Δ
  6. ϞʔμϧͷભҠͷίʔυ JUFN struct ContentView: View { @State var item: Item?

    = nil var body: some View { Button("Show Sheet") { item = .foo } .sheet(item: $item) { ... } } } όΠϯυͨ͠஋Ληοτ͢ΔͱભҠ ೚ҙͷ0QUJPOBMͷ஋ΛόΠϯυ͢Δ
  7. ։͖ํ ด͡ํ ্ͷ֊૚ දࣔઌͷ7JFX 4IFFU όΠϯυ όΠϯυ εϫΠϓ ։͚Δ ͍Βͳ͍

    'VMM4DSFFO$PWFS όΠϯυ όΠϯυ ։͚Δ ͍Βͳ͍ 1PQPWFS όΠϯυ όΠϯυ ֎Λλοϓ ։͚Δ ͍Δ "MFSU όΠϯυ όΠϯυ Ϙλϯબ୒ ։͚ͳ͍ ͍Βͳ͍ $PO fi SNBUJPO %JBMPH όΠϯυ όΠϯυ Ϙλϯબ୒ ։͚ͳ͍ ͍Δ .FOV λοϓ Ϙλϯબ୒ ֎Λλοϓ ։͚ͳ͍  Ϟʔμϧͷछྨ
  8. var body: some View { Button("Show") { isFirstPresented = true

    isSecondPresented = true isThirdPresented = true } .sheet(isPresented: $isFirstPresented) { Text("1") .sheet(isPresented: $isSecondPresented) { Text("2") .sheet(isPresented: $isThirdPresented) { Text("3") } ... ֊૚Ҏ্ಉ࣌ʹ։͚ͳ͍ ❌ͭ໨͸։͔ͳ͍
  9. J04Ҏલ͸ෳ਺֊૚ಉ࣌ʹด͡Εͳ͍ var body: some View { Button("Show") { ... }

    .sheet(isPresented: $isFirstPresented) { Text("1") .sheet(isPresented: $isSecondPresented) { Button("Close") { isFirstPresented = false } ... J04͸0, ❌J04͸શ෦ด͡ͳ͍
  10. var body: some View { ... .sheet(isPresented: $isSheetPresented) { Button("Switch

    to FullScreen") { isSheetPresented = false isFullPresented = true } } .fullScreenCover( isPresented: $isFullPresented) { Text("Full Screen") } } Ϟʔμϧͷ੾Γସ͑ 'VMM4DSFFO͕4IFFUͰදࣔ͞ΕΔ ❌4IFFUͰදࣔ͞ΕΔ
  11. var body: some View { ... .sheet(isPresented: $isSheetPresented) { Button("Show

    Alert") { isSheetPresented = false isAlertPresented = true } } .alert("Alert", isPresented: $isAlertPresented) { ... } } Ϟʔμϧͷ੾Γସ͑ "MFSU͕දࣔ͞Εͳ͍ ❌දࣔ͞Εͳ͍
  12. var body: some View { Button("Freeze") { isFirstPresented = true

    isSecondPresented = true Task { try await Task.sleep(for: .milliseconds(100)) isFirstPresented = false } } .sheet(isPresented: $isFirstPresented) { ... .sheet(isPresented: $isSecondPresented) { ... } ભҠதʹด͡Α͏ͱ͢ΔͱϑϦʔζ ❌ϑϦʔζ͢Δ
  13. var body: some View { Button("Crash") { item = .one

    Task { try await Task.sleep(for: .milliseconds(100)) item = .two try await Task.sleep(for: .milliseconds(100)) item = .three } } .sheet(item: $item, content: { item in ... }) } Ϟʔμϧ੾Γସ͑தʹ͞Βʹ੾Γସ͑ΔͱΫϥογϡ ❌Ϋϥογϡ͢Δ
  14. enum Modal { case sheet(Item) case alert(...) ... } σʔλιʔε

    .PEBM 7JFX 1PQPWFS OJM "MFSU OJM 4IFFU OJM Ϟʔμϧͷঢ়ଶΛͭͷ஋Ͱද͢ ม׵ 1PQPWFS OJM OJM
  15. enum Modal { case sheet(Item) case alert(...) ... } σʔλιʔε

    .PEBM TIFFU GPP 7JFX 1PQPWFS OJM "MFSU OJM 4IFFU GPP Ϟʔμϧͷঢ়ଶΛͭͷ஋Ͱද͢ ม׵ 1PQPWFS OJM
  16. enum Modal { case sheet(Item) case alert(...) ... } σʔλιʔε

    .PEBM BMFSU CBS 7JFX 1PQPWFS OJM "MFSU CBS 4IFFU OJM Ϟʔμϧͷঢ়ଶΛͭͷ஋Ͱද͢ ม׵ 1PQPWFS OJM