-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
LeeSeminSU/LeeSeminSU/Week4/SheetModifier/SheetModifierExample.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// SheetModifierExample.swift | ||
// LeeSeminSU | ||
// | ||
// Created by 이세민 on 12/5/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct SheetModifierExample: View { | ||
@State private var showModal = false // 모달을 보여줄지 말지를 결정하는 상태 변수 | ||
@State private var name = "" | ||
|
||
var body: some View { | ||
VStack { | ||
Text("나의 이름은") | ||
.font(.title) | ||
TextField("이름을 입력하세요.", text: $name) | ||
.textFieldStyle(RoundedBorderTextFieldStyle()) | ||
.padding() | ||
|
||
Button("모달 열기") { | ||
showModal.toggle() | ||
} | ||
.sheet(isPresented: $showModal) { | ||
ModalView(name: name) // 입력된 이름을 모달에 전달 | ||
} | ||
.padding() | ||
} | ||
.padding() | ||
} | ||
} | ||
|
||
struct ModalView: View { | ||
var name: String // 전달받은 이름 | ||
@Environment(\.dismiss) var dismiss // 모달을 닫을 때 사용 | ||
|
||
var body: some View { | ||
VStack { | ||
Text("안녕 \(name)?") | ||
.font(.title) | ||
Button("닫기") { | ||
dismiss() | ||
} | ||
.padding() | ||
} | ||
.padding() | ||
} | ||
} | ||
|
||
#Preview { | ||
SheetModifierExample() | ||
} |