mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Introduce sending and sent state for timeline messages (#319)
* Updated md files * Changelog * Update CONTRIBUTING.md Co-authored-by: Stefan Ceriu <stefanc@matrix.org> * PR fixes * Sending state in the timeline * Changelog * Formating * Project file * Make MessageTimelineItemDeliveryStatus Equatable * Renamed seconds ago to elepsed time * Moved show/hide logic into TimelineDeliveryStatusView * Hide view when unknown status * Added delivery status for other items * Cleanup Co-authored-by: Stefan Ceriu <stefanc@matrix.org>
This commit is contained in:
committed by
GitHub
parent
276daf0355
commit
77a0d5a58f
+67
@@ -0,0 +1,67 @@
|
||||
//
|
||||
// Copyright 2022 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
struct TimelineDeliveryStatusView: View {
|
||||
let deliveryStatus: MessageTimelineItemDeliveryStatus
|
||||
|
||||
@State var showDeliveryStatus: Bool
|
||||
|
||||
private var systemImageName: String {
|
||||
switch deliveryStatus {
|
||||
case .sending, .unknown:
|
||||
return "circle"
|
||||
case .sent:
|
||||
return "checkmark.circle"
|
||||
}
|
||||
}
|
||||
|
||||
init(deliveryStatus: MessageTimelineItemDeliveryStatus) {
|
||||
self.deliveryStatus = deliveryStatus
|
||||
|
||||
switch deliveryStatus {
|
||||
case .sending:
|
||||
showDeliveryStatus = true
|
||||
case let .sent(elapsedTime: elapsedTime):
|
||||
showDeliveryStatus = elapsedTime < 3
|
||||
case .unknown:
|
||||
showDeliveryStatus = false
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
if showDeliveryStatus {
|
||||
Image(systemName: systemImageName)
|
||||
.task {
|
||||
if case .sent = deliveryStatus {
|
||||
try? await Task.sleep(nanoseconds: 1_000_000_000)
|
||||
withAnimation {
|
||||
showDeliveryStatus = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct TimelineDeliveryStatusView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
VStack {
|
||||
TimelineDeliveryStatusView(deliveryStatus: .sending)
|
||||
TimelineDeliveryStatusView(deliveryStatus: .sent(elapsedTime: Date().timeIntervalSince1970))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user