generated from element-hq/.github
-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switched to discrete timeline items that directly expose view builders.
- Loading branch information
1 parent
8d4f6f3
commit d413a67
Showing
11 changed files
with
175 additions
and
106 deletions.
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
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
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
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
84 changes: 84 additions & 0 deletions
84
ElementX/Sources/Services/Timeline/TimelineItems/RoomTimelineItem.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,84 @@ | ||
// | ||
// TextRoomTimelineItem.swift | ||
// ElementX | ||
// | ||
// Created by Stefan Ceriu on 04.03.2022. | ||
// Copyright © 2022 Element. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
private var dateFormatter: DateFormatter = { | ||
let dateFormatter = DateFormatter() | ||
dateFormatter.dateStyle = .none | ||
dateFormatter.timeStyle = .short | ||
return dateFormatter | ||
}() | ||
|
||
enum RoomTimelineItem: Identifiable, Equatable { | ||
case text(id: String, senderDisplayName: String, text: String, originServerTs: Date, shouldShowSenderDetails: Bool) | ||
case sectionTitle(id: String, text: String) | ||
|
||
var id: String { | ||
switch self { | ||
case .text(let id, _, _, _, _): | ||
return id | ||
case .sectionTitle(let id, _): | ||
return id | ||
} | ||
} | ||
} | ||
|
||
extension RoomTimelineItem: View { | ||
var body: some View { | ||
switch self { | ||
case .text(let id, let senderDisplayName, let text, let originServerTs, let shouldShowSenderDetails): | ||
VStack(alignment: .leading) { | ||
if shouldShowSenderDetails { | ||
HStack { | ||
Text(senderDisplayName) | ||
.font(.footnote) | ||
.bold() | ||
Spacer() | ||
Text(dateFormatter.string(from: originServerTs)) | ||
.font(.footnote) | ||
} | ||
Divider() | ||
Spacer() | ||
} | ||
Text(text) | ||
} | ||
.listRowSeparator(.hidden) | ||
.id(id) | ||
case .sectionTitle(let id, let text): | ||
LabelledDivider(label: text) | ||
.id(id) | ||
} | ||
} | ||
} | ||
|
||
struct LabelledDivider: View { | ||
|
||
let label: String | ||
let color: Color | ||
|
||
init(label: String, color: Color = .gray) { | ||
self.label = label | ||
self.color = color | ||
} | ||
|
||
var body: some View { | ||
HStack { | ||
line | ||
Text(label) | ||
.foregroundColor(color) | ||
.fixedSize() | ||
line | ||
} | ||
} | ||
|
||
var line: some View { | ||
VStack { Divider().background(color) } | ||
} | ||
} |
Oops, something went wrong.