Skip to content

Commit d38082d

Browse files
committed
Messages sample
0 parents commit d38082d

File tree

13 files changed

+903
-0
lines changed

13 files changed

+903
-0
lines changed

Messages.xcodeproj/project.pbxproj

Lines changed: 438 additions & 0 deletions
Large diffs are not rendered by default.

Messages.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>SchemeUserState</key>
6+
<dict>
7+
<key>iOS.xcscheme_^#shared#^_</key>
8+
<dict>
9+
<key>orderHint</key>
10+
<integer>1</integer>
11+
</dict>
12+
<key>macOS.xcscheme_^#shared#^_</key>
13+
<dict>
14+
<key>orderHint</key>
15+
<integer>0</integer>
16+
</dict>
17+
</dict>
18+
</dict>
19+
</plist>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"colors" : [
3+
{
4+
"idiom" : "universal"
5+
}
6+
],
7+
"info" : {
8+
"author" : "xcode",
9+
"version" : 1
10+
}
11+
}
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "iphone",
5+
"scale" : "2x",
6+
"size" : "20x20"
7+
},
8+
{
9+
"idiom" : "iphone",
10+
"scale" : "3x",
11+
"size" : "20x20"
12+
},
13+
{
14+
"idiom" : "iphone",
15+
"scale" : "2x",
16+
"size" : "29x29"
17+
},
18+
{
19+
"idiom" : "iphone",
20+
"scale" : "3x",
21+
"size" : "29x29"
22+
},
23+
{
24+
"idiom" : "iphone",
25+
"scale" : "2x",
26+
"size" : "40x40"
27+
},
28+
{
29+
"idiom" : "iphone",
30+
"scale" : "3x",
31+
"size" : "40x40"
32+
},
33+
{
34+
"idiom" : "iphone",
35+
"scale" : "2x",
36+
"size" : "60x60"
37+
},
38+
{
39+
"idiom" : "iphone",
40+
"scale" : "3x",
41+
"size" : "60x60"
42+
},
43+
{
44+
"idiom" : "ipad",
45+
"scale" : "1x",
46+
"size" : "20x20"
47+
},
48+
{
49+
"idiom" : "ipad",
50+
"scale" : "2x",
51+
"size" : "20x20"
52+
},
53+
{
54+
"idiom" : "ipad",
55+
"scale" : "1x",
56+
"size" : "29x29"
57+
},
58+
{
59+
"idiom" : "ipad",
60+
"scale" : "2x",
61+
"size" : "29x29"
62+
},
63+
{
64+
"idiom" : "ipad",
65+
"scale" : "1x",
66+
"size" : "40x40"
67+
},
68+
{
69+
"idiom" : "ipad",
70+
"scale" : "2x",
71+
"size" : "40x40"
72+
},
73+
{
74+
"idiom" : "ipad",
75+
"scale" : "1x",
76+
"size" : "76x76"
77+
},
78+
{
79+
"idiom" : "ipad",
80+
"scale" : "2x",
81+
"size" : "76x76"
82+
},
83+
{
84+
"idiom" : "ipad",
85+
"scale" : "2x",
86+
"size" : "83.5x83.5"
87+
},
88+
{
89+
"idiom" : "ios-marketing",
90+
"scale" : "1x",
91+
"size" : "1024x1024"
92+
},
93+
{
94+
"idiom" : "mac",
95+
"scale" : "1x",
96+
"size" : "16x16"
97+
},
98+
{
99+
"idiom" : "mac",
100+
"scale" : "2x",
101+
"size" : "16x16"
102+
},
103+
{
104+
"idiom" : "mac",
105+
"scale" : "1x",
106+
"size" : "32x32"
107+
},
108+
{
109+
"idiom" : "mac",
110+
"scale" : "2x",
111+
"size" : "32x32"
112+
},
113+
{
114+
"idiom" : "mac",
115+
"scale" : "1x",
116+
"size" : "128x128"
117+
},
118+
{
119+
"idiom" : "mac",
120+
"scale" : "2x",
121+
"size" : "128x128"
122+
},
123+
{
124+
"idiom" : "mac",
125+
"scale" : "1x",
126+
"size" : "256x256"
127+
},
128+
{
129+
"idiom" : "mac",
130+
"scale" : "2x",
131+
"size" : "256x256"
132+
},
133+
{
134+
"idiom" : "mac",
135+
"scale" : "1x",
136+
"size" : "512x512"
137+
},
138+
{
139+
"idiom" : "mac",
140+
"scale" : "2x",
141+
"size" : "512x512"
142+
}
143+
],
144+
"info" : {
145+
"author" : "xcode",
146+
"version" : 1
147+
}
148+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"author" : "xcode",
4+
"version" : 1
5+
}
6+
}

Shared/ContentView.swift

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
//
2+
// ContentView.swift
3+
// Shared
4+
//
5+
// Created by Jordan Singer on 6/28/20.
6+
//
7+
8+
import SwiftUI
9+
10+
struct ContentView: View {
11+
@State var selection: Set<Int> = [0]
12+
13+
var body: some View {
14+
NavigationView {
15+
List(selection: self.$selection) {
16+
MessageCell(name: "Jordan Singer", message: "Hello, world").tag(0)
17+
MessageCell(name: "Craig Federighi", message: "About lil apps...")
18+
MessageCell(name: "Leo Gill", message: "iMessage")
19+
MessageCell(name: "June Cha", message: "iMessage")
20+
MessageCell(name: "Britney Cooper", message: "iMessage")
21+
MessageCell(name: "Andrew Kumar", message: "iMessage")
22+
MessageCell(name: "Andrew Kumar", message: "iMessage")
23+
}
24+
.listStyle(SidebarListStyle())
25+
.navigationTitle("Messages")
26+
27+
Text("No message selected")
28+
.frame(maxWidth: .infinity, maxHeight: .infinity)
29+
}
30+
.navigationTitle("Messages")
31+
.toolbar {
32+
ToolbarItem(placement: .navigation) {
33+
Button(action: {}) {
34+
Image(systemName: "square.and.pencil")
35+
}
36+
}
37+
38+
ToolbarItem(placement: .status) {
39+
Button(action: {}) {
40+
Image(systemName: "info.circle")
41+
}
42+
}
43+
}
44+
}
45+
}
46+
47+
struct MessageCell: View {
48+
@State var name: String
49+
@State var message: String
50+
51+
var body: some View {
52+
NavigationLink(destination: MessageView()) {
53+
HStack {
54+
Image(systemName: "person.crop.circle.fill")
55+
.font(.system(size: 40))
56+
57+
VStack(alignment: .leading, spacing: 2) {
58+
HStack(alignment: .center) {
59+
Text(name)
60+
.font(.headline)
61+
Spacer()
62+
Text("9:41 AM")
63+
.font(.callout)
64+
}
65+
66+
Text(message)
67+
.font(.callout)
68+
.lineLimit(1)
69+
}
70+
}
71+
.padding(.vertical, 12)
72+
}
73+
}
74+
}
75+
76+
struct MessageView: View {
77+
@State var message = ""
78+
@State var messages = [
79+
"Here’s to the crazy ones",
80+
"the misfits, the rebels, the troublemakers",
81+
"the round pegs in the square holes…",
82+
"the ones who see things differently — they’re not fond of rules…",
83+
"You can quote them, disagree with them, glorify or vilify them",
84+
"but the only thing you can’t do is ignore them because they change things…",
85+
"they push the human race forward",
86+
"and while some may see them as the crazy ones",
87+
"we see genius",
88+
"because the ones who are crazy enough to think that they can change the world",
89+
"are the ones who do."
90+
]
91+
92+
#if os(macOS)
93+
var backgroundColor = Color(NSColor.controlBackgroundColor)
94+
#else
95+
var backgroundColor = Color(UIColor.systemBackground)
96+
#endif
97+
98+
var body: some View {
99+
VStack(spacing: 0) {
100+
ScrollView {
101+
VStack(spacing: 12) {
102+
ForEach(0..<messages.count, id: \.self) { i in
103+
ChatBubbleView(message: messages[i], index: i)
104+
}
105+
}
106+
.padding()
107+
}
108+
109+
TextField("iMessage", text: $message, onCommit: { self.sendMessage() })
110+
.textFieldStyle(RoundedBorderTextFieldStyle())
111+
.padding()
112+
}
113+
.background(backgroundColor)
114+
.navigationTitle("Message")
115+
// .navigationBarTitleDisplayMode(.inline)
116+
}
117+
118+
func sendMessage() {
119+
self.messages.append(self.message)
120+
self.message = ""
121+
}
122+
}
123+
124+
struct ChatBubbleView: View {
125+
@State var message: String
126+
@State var index: Int
127+
128+
#if os(macOS)
129+
var outgoingBubbleColor = NSColor.systemBlue
130+
var incomingBubbleColor = NSColor.windowBackgroundColor
131+
var incomingLabelColor = NSColor.labelColor
132+
#else
133+
var outgoingBubbleColor = UIColor.systemBlue
134+
var incomingBubbleColor = UIColor.secondarySystemBackground
135+
var incomingLabelColor = UIColor.label
136+
#endif
137+
138+
var body: some View {
139+
HStack {
140+
if index % 2 != 0 {
141+
Spacer()
142+
}
143+
144+
Text(message)
145+
.foregroundColor(Color(index % 2 != 0 ? .white : incomingLabelColor))
146+
.multilineTextAlignment(.leading)
147+
.padding(.horizontal, 12)
148+
.padding(.vertical, 8)
149+
.background(Color(index % 2 != 0 ? outgoingBubbleColor : incomingBubbleColor))
150+
.cornerRadius(16)
151+
152+
if index % 2 == 0 {
153+
Spacer()
154+
}
155+
}
156+
}
157+
}
158+
159+
struct ContentView_Previews: PreviewProvider {
160+
static var previews: some View {
161+
ContentView()
162+
}
163+
}

Shared/MessagesApp.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// MessagesApp.swift
3+
// Shared
4+
//
5+
// Created by Jordan Singer on 6/28/20.
6+
//
7+
8+
import SwiftUI
9+
10+
@main
11+
struct MessagesApp: App {
12+
var body: some Scene {
13+
WindowGroup {
14+
ContentView()
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)