Skip to content

Commit 8427239

Browse files
committed
popover added
1 parent 4aa00f0 commit 8427239

File tree

8 files changed

+111
-14
lines changed

8 files changed

+111
-14
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
SwiftUI by Example is an Universal App for iOS and MacOS containing the following examples:
44

55
- Example 1: Buttons [doc.](https://developer.apple.com/documentation/swiftui/button)
6-
- ![Buttons](images/Example-1-Button.png)
76
- Example 2: ActionSheet [doc.](https://developer.apple.com/documentation/swiftui/actionsheet)
8-
- ![ActionSheet](images/Example-2-ActionSheet.png)
97
- Example 3: Open a Sheet with a new view and dismiss again
108
- Example 4: Use UIImagePickerController (via UIViewControllerRepresentable) to select or create a photo
11-
9+
- Exmaple 5: Alerts
10+
- Example 6: Popover
1211

Shared/ContentView.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ struct ContentView: View {
2323
NavigationLink(destination: Example4_ImagePicker()) {
2424
Text("Example 4: ImagePicker")
2525
}
26-
26+
NavigationLink(destination: Example5_Alert()) {
27+
Text("Example 5: Alert")
28+
}
29+
NavigationLink(destination: Example6_Popover()) {
30+
Text("Example 6: Popover")
31+
}
2732
}.navigationTitle("SwiftUI by Example")
2833

2934
}

Shared/Example3-Sheet.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,6 @@
77

88
import SwiftUI
99

10-
struct Example3_Sheet_Second: View {
11-
@Binding var showSheet: Bool
12-
13-
var body: some View {
14-
Button("Dismiss again", action: {
15-
showSheet = false
16-
})
17-
}
18-
}
19-
2010
struct Example3_Sheet: View {
2111
@State var showSheet = false
2212

@@ -30,6 +20,16 @@ struct Example3_Sheet: View {
3020
}
3121
}
3222

23+
struct Example3_Sheet_Second: View {
24+
@Binding var showSheet: Bool
25+
26+
var body: some View {
27+
Button("Dismiss again", action: {
28+
showSheet = false
29+
})
30+
}
31+
}
32+
3333
struct Example3_Sheet_Previews: PreviewProvider {
3434
static var previews: some View {
3535
Example3_Sheet()

Shared/Example5-Alert.swift

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//
2+
// Example5-Alert.swift
3+
// SwiftUI by Example
4+
//
5+
// Created by Bartholomäus Maciag on 22.08.20.
6+
//
7+
8+
import SwiftUI
9+
10+
struct Example5_Alert: View {
11+
@State private var showAlertOne = false
12+
@State private var showAlertTwo = false
13+
14+
var body: some View {
15+
VStack {
16+
Button(action: {
17+
showAlertOne = true
18+
}) {
19+
Text("Alert with one Button")
20+
}
21+
.alert(isPresented: $showAlertOne, content: {
22+
Alert(title: Text("Title text"), message: Text("Optional message text"), dismissButton: .cancel())
23+
})
24+
.padding()
25+
26+
Button(action: {
27+
showAlertTwo.toggle()
28+
}) {
29+
Text("Alert with two Buttons")
30+
}
31+
.alert(isPresented: $showAlertTwo, content: {
32+
Alert(title: Text("Title text"),
33+
message: Text("Optional message text"),
34+
primaryButton: .default(Text("Ok")),
35+
secondaryButton: .destructive(Text("delete"), action: {
36+
print("delete something...")
37+
}))
38+
})
39+
}
40+
}
41+
}
42+
43+
struct Example5_Alert_Previews: PreviewProvider {
44+
static var previews: some View {
45+
Example5_Alert()
46+
}
47+
}

Shared/Example6-Popover.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// Example6-Popover.swift
3+
// SwiftUI by Example
4+
//
5+
// Created by Bartholomäus Maciag on 22.08.20.
6+
//
7+
8+
import SwiftUI
9+
10+
struct Example6_Popover: View {
11+
@State private var showPopover = false
12+
@State private var text = ""
13+
14+
var body: some View {
15+
Button("Open Popover", action: {
16+
showPopover.toggle()
17+
}).popover(isPresented: $showPopover, content: {
18+
VStack {
19+
Text("Some content...")
20+
TextField("Some placeholder", text: $text)
21+
Button("Dismiss", action: {
22+
showPopover.toggle()
23+
})
24+
25+
}
26+
})
27+
}
28+
}
29+
30+
struct Example6_Popover_Previews: PreviewProvider {
31+
static var previews: some View {
32+
Example6_Popover()
33+
}
34+
}

SwiftUI by Example.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
4379406124F19C940043E359 /* Example5-Alert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4379406024F19C940043E359 /* Example5-Alert.swift */; };
11+
4379406224F19C940043E359 /* Example5-Alert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4379406024F19C940043E359 /* Example5-Alert.swift */; };
1012
437BD6DB24E5CCD600600789 /* SwiftUI_by_ExampleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 437BD6C824E5CCD500600789 /* SwiftUI_by_ExampleApp.swift */; };
1113
437BD6DC24E5CCD600600789 /* SwiftUI_by_ExampleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 437BD6C824E5CCD500600789 /* SwiftUI_by_ExampleApp.swift */; };
1214
437BD6DD24E5CCD600600789 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 437BD6C924E5CCD500600789 /* ContentView.swift */; };
@@ -21,9 +23,12 @@
2123
43C56B5B24E650510042F698 /* Example2-ActionSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43C56B5924E650510042F698 /* Example2-ActionSheet.swift */; };
2224
43C56B5D24E662160042F698 /* Example3-Sheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43C56B5C24E662160042F698 /* Example3-Sheet.swift */; };
2325
43C56B5E24E662160042F698 /* Example3-Sheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43C56B5C24E662160042F698 /* Example3-Sheet.swift */; };
26+
43D4630724F1A0BE009BE962 /* Example6-Popover.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43D4630624F1A0BD009BE962 /* Example6-Popover.swift */; };
27+
43D4630824F1A0BE009BE962 /* Example6-Popover.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43D4630624F1A0BD009BE962 /* Example6-Popover.swift */; };
2428
/* End PBXBuildFile section */
2529

2630
/* Begin PBXFileReference section */
31+
4379406024F19C940043E359 /* Example5-Alert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Example5-Alert.swift"; sourceTree = "<group>"; };
2732
437BD6C824E5CCD500600789 /* SwiftUI_by_ExampleApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftUI_by_ExampleApp.swift; sourceTree = "<group>"; };
2833
437BD6C924E5CCD500600789 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
2934
437BD6CA24E5CCD600600789 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@@ -36,6 +41,7 @@
3641
43BC487824EFB77E00BA2696 /* Example4-ImagePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Example4-ImagePicker.swift"; sourceTree = "<group>"; };
3742
43C56B5924E650510042F698 /* Example2-ActionSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Example2-ActionSheet.swift"; sourceTree = "<group>"; };
3843
43C56B5C24E662160042F698 /* Example3-Sheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Example3-Sheet.swift"; sourceTree = "<group>"; };
44+
43D4630624F1A0BD009BE962 /* Example6-Popover.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Example6-Popover.swift"; sourceTree = "<group>"; };
3945
/* End PBXFileReference section */
4046

4147
/* Begin PBXFrameworksBuildPhase section */
@@ -110,6 +116,8 @@
110116
43C56B5924E650510042F698 /* Example2-ActionSheet.swift */,
111117
43C56B5C24E662160042F698 /* Example3-Sheet.swift */,
112118
43BC487824EFB77E00BA2696 /* Example4-ImagePicker.swift */,
119+
4379406024F19C940043E359 /* Example5-Alert.swift */,
120+
43D4630624F1A0BD009BE962 /* Example6-Popover.swift */,
113121
);
114122
name = Examples;
115123
sourceTree = "<group>";
@@ -211,8 +219,10 @@
211219
isa = PBXSourcesBuildPhase;
212220
buildActionMask = 2147483647;
213221
files = (
222+
4379406124F19C940043E359 /* Example5-Alert.swift in Sources */,
214223
437BD6DD24E5CCD600600789 /* ContentView.swift in Sources */,
215224
43C56B5D24E662160042F698 /* Example3-Sheet.swift in Sources */,
225+
43D4630724F1A0BE009BE962 /* Example6-Popover.swift in Sources */,
216226
437BD6EA24E5CD7D00600789 /* Example1-Button.swift in Sources */,
217227
43BC487924EFB77E00BA2696 /* Example4-ImagePicker.swift in Sources */,
218228
437BD6DB24E5CCD600600789 /* SwiftUI_by_ExampleApp.swift in Sources */,
@@ -224,8 +234,10 @@
224234
isa = PBXSourcesBuildPhase;
225235
buildActionMask = 2147483647;
226236
files = (
237+
4379406224F19C940043E359 /* Example5-Alert.swift in Sources */,
227238
437BD6DE24E5CCD600600789 /* ContentView.swift in Sources */,
228239
43C56B5E24E662160042F698 /* Example3-Sheet.swift in Sources */,
240+
43D4630824F1A0BE009BE962 /* Example6-Popover.swift in Sources */,
229241
437BD6EB24E5CD7D00600789 /* Example1-Button.swift in Sources */,
230242
43BC487A24EFB77E00BA2696 /* Example4-ImagePicker.swift in Sources */,
231243
437BD6DC24E5CCD600600789 /* SwiftUI_by_ExampleApp.swift in Sources */,

images/Example-1-Button.png

-17.3 KB
Binary file not shown.

images/Example-2-ActionSheet.png

-40.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)