Skip to content

Commit

Permalink
feat: Modal - Sheet Modifier 실습
Browse files Browse the repository at this point in the history
  • Loading branch information
sem-git committed Dec 4, 2024
1 parent 2edd3bd commit 377a6c6
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
12 changes: 12 additions & 0 deletions LeeSeminSU/LeeSeminSU.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
76FC2B852D00C49900F10EE1 /* FirstNavigationViewExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76FC2B842D00C49900F10EE1 /* FirstNavigationViewExample.swift */; };
76FC2B872D00C4A100F10EE1 /* SecondNavigationViewExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76FC2B862D00C4A100F10EE1 /* SecondNavigationViewExample.swift */; };
76FC2B8A2D00CA4200F10EE1 /* TabViewExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76FC2B892D00CA4200F10EE1 /* TabViewExample.swift */; };
76FC2B8D2D00CC6600F10EE1 /* SheetModifierExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76FC2B8C2D00CC6600F10EE1 /* SheetModifierExample.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -47,6 +48,7 @@
76FC2B842D00C49900F10EE1 /* FirstNavigationViewExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirstNavigationViewExample.swift; sourceTree = "<group>"; };
76FC2B862D00C4A100F10EE1 /* SecondNavigationViewExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecondNavigationViewExample.swift; sourceTree = "<group>"; };
76FC2B892D00CA4200F10EE1 /* TabViewExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabViewExample.swift; sourceTree = "<group>"; };
76FC2B8C2D00CC6600F10EE1 /* SheetModifierExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SheetModifierExample.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -134,6 +136,7 @@
76FC2B742D00B37D00F10EE1 /* Week4 */ = {
isa = PBXGroup;
children = (
76FC2B8B2D00CC4D00F10EE1 /* SheetModifier */,
76FC2B882D00CA2400F10EE1 /* TabView */,
76FC2B832D00C47B00F10EE1 /* Navigation */,
76FC2B772D00B7D000F10EE1 /* State */,
Expand Down Expand Up @@ -169,6 +172,14 @@
path = TabView;
sourceTree = "<group>";
};
76FC2B8B2D00CC4D00F10EE1 /* SheetModifier */ = {
isa = PBXGroup;
children = (
76FC2B8C2D00CC6600F10EE1 /* SheetModifierExample.swift */,
);
path = SheetModifier;
sourceTree = "<group>";
};
76FC2DD82CE06C37000B329B /* Week2 */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -267,6 +278,7 @@
76FC2B792D00B7E300F10EE1 /* BindingExample.swift in Sources */,
76DFF9302CD7B4F100C373C3 /* LeeSeminSUApp.swift in Sources */,
769FAB262CE1157A00785E3D /* SpacerPaddingExample.swift in Sources */,
76FC2B8D2D00CC6600F10EE1 /* SheetModifierExample.swift in Sources */,
76FC2B7D2D00C0C700F10EE1 /* EnvironmentObjectExample.swift in Sources */,
769FAB292CE115B700785E3D /* ModifierExample.swift in Sources */,
76FC2B872D00C4A100F10EE1 /* SecondNavigationViewExample.swift in Sources */,
Expand Down
4 changes: 3 additions & 1 deletion LeeSeminSU/LeeSeminSU/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ struct ContentView: View {
// Week4
// StateExample()
// BindingExample()
ObservedObjectExample()
// ObservedObjectExample()
// FirstNavigationViewExample()
SheetModifierExample()
}
}

Expand Down
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()
}

0 comments on commit 377a6c6

Please sign in to comment.