This file contains hidden or 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
| GeometryReader { geometry in | |
| ScrollView { | |
| ForEach(self.messages) { message in | |
| MessageView(message: message) | |
| .padding(.horizontal, 8) | |
| .padding(EdgeInsets( | |
| top: 0, | |
| leading: message.sender == .me ? geometry.size.width * 0.5 : 0 , | |
| bottom: 0, | |
| trailing: message.sender == .me ? 0 : geometry.size.width * 0.5)) |
This file contains hidden or 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
| GeometryReader { geometry in | |
| ForEach(self.messages) { message in | |
| MessageView(message: message) | |
| .padding(.horizontal, 8) | |
| .padding(EdgeInsets( | |
| top: 0, | |
| leading: message.sender == .me ? geometry.size.width * 0.5 : 0 , | |
| bottom: 0, | |
| trailing: message.sender == .me ? 0 : geometry.size.width * 0.5)) | |
| } |
This file contains hidden or 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
| .padding(EdgeInsets( | |
| top: 0, | |
| leading: message.sender == .me ? 64 : 0 , | |
| bottom: 0, | |
| trailing: message.sender == .me ? 0 : 64)) |
This file contains hidden or 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
| struct MessageListView: View { | |
| let messages: [Message] | |
| var body: some View { | |
| ForEach(self.messages) { message in | |
| MessageView(message: message) | |
| .padding(.horizontal, 8) | |
| } | |
| } | |
| } |
This file contains hidden or 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
| struct MessageView: View { | |
| let message: Message | |
| var body: some View { | |
| HStack { | |
| if message.sender == .me { | |
| Spacer() | |
| } | |
| Text(message.content) | |
| .multilineTextAlignment(.leading) | |
| .fixedSize(horizontal: false, vertical: true) |
This file contains hidden or 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
| struct MessageView: View { | |
| let message: Message | |
| var body: some View { | |
| Text(message.content) | |
| .multilineTextAlignment(.leading) | |
| .fixedSize(horizontal: false, vertical: true) | |
| .padding(.horizontal, 12) | |
| .padding(.vertical, 4) | |
| .background(message.sender == .me ? Color.blue : Color.gray) | |
| .foregroundColor(message.sender == .me ? Color.white : Color.black) |
This file contains hidden or 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
| struct Message: Hashable, Identifiable { | |
| enum Sender: Hashable { | |
| case me | |
| case other(named: String) | |
| } | |
| let id: Int | |
| let sender: Sender | |
| let content: String | |
| } |
This file contains hidden or 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
| struct HighScoreView: View { | |
| @EnvironmentObject var highScore: HighScore | |
| var body: some View { | |
| Text(highScore.value) | |
| } | |
| } |
This file contains hidden or 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
| struct UserInputView: View { | |
| @ObservedObject var user: User | |
| var body: some View { | |
| VStack { | |
| Text(user.name) | |
| Text(user.surname) | |
| } | |
| } | |
| } |
This file contains hidden or 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
| struct UsernameInputView: View { | |
| @Binding var username: String | |
| var body: some View { | |
| TextField(username, text: $username) | |
| } | |
| } |
NewerOlder