mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-11-14 17:47:52 +00:00
* ui: markdown messages show the empty lines that were typed * ui: snapshot references of messages with empty lines * ui: terminal layout spacing by one paragraph unit, names at text size * ui: terminal gap below reactions, same empty lines in both apps * ui: flat layout references with the paragraph unit * core, ui: text with empty lines as paragraphs, ios bubbles fit text * core, ui: move text with empty lines as paragraphs to a follow-up * ui: ios references with bubbles that fit their text * ui: other senders' names in the flat layout in the secondary colour * core, ui: text with empty lines as paragraphs * core, ui: single-star text italic, reports drawn without core prefix
112 lines
5.2 KiB
Swift
112 lines
5.2 KiB
Swift
//
|
|
// FramedCIVoiceView.swift
|
|
// SimpleX (iOS)
|
|
//
|
|
// Created by JRoberts on 22.11.2022.
|
|
// Copyright © 2022 SimpleX Chat. All rights reserved.
|
|
//
|
|
// Spec: spec/client/chat-view.md
|
|
|
|
import SwiftUI
|
|
|
|
import SwiftUI
|
|
import SimpleXChat
|
|
|
|
// Spec: spec/client/chat-view.md#FramedCIVoiceView
|
|
struct FramedCIVoiceView: View {
|
|
@EnvironmentObject var theme: AppTheme
|
|
@Environment(\.terminalLayout) private var terminal
|
|
@ObservedObject var chat: Chat
|
|
var chatItem: ChatItem
|
|
let recordingFile: CIFile?
|
|
let duration: Int
|
|
|
|
@State var audioPlayer: AudioPlayer? = nil
|
|
@State var playbackState: VoiceMessagePlaybackState = .noPlayback
|
|
@State var playbackTime: TimeInterval? = nil
|
|
|
|
@Binding var allowMenu: Bool
|
|
|
|
@State private var seek: (TimeInterval) -> Void = { _ in }
|
|
|
|
var body: some View {
|
|
HStack {
|
|
VoiceMessagePlayer(
|
|
chat: chat,
|
|
chatItem: chatItem,
|
|
recordingFile: recordingFile,
|
|
recordingTime: TimeInterval(duration),
|
|
showBackground: terminal,
|
|
seek: $seek,
|
|
audioPlayer: $audioPlayer,
|
|
playbackState: $playbackState,
|
|
playbackTime: $playbackTime,
|
|
allowMenu: $allowMenu,
|
|
sizeMultiplier: 1
|
|
)
|
|
VoiceMessagePlayerTime(
|
|
recordingTime: TimeInterval(duration),
|
|
playbackState: $playbackState,
|
|
playbackTime: $playbackTime
|
|
)
|
|
.foregroundColor(theme.colors.secondary)
|
|
.frame(width: 50, alignment: .leading)
|
|
if .playing == playbackState || (playbackTime ?? 0) > 0 || !allowMenu {
|
|
playbackSlider()
|
|
}
|
|
}
|
|
.padding(.top, terminal ? terminalCardTopGap(chatItem) : 6)
|
|
.padding(.leading, terminal ? chatItemTextPadding : 6)
|
|
.padding(.trailing, terminal ? 0 : 12)
|
|
.padding(.bottom, terminal ? 0 : chatItem.content.text.isEmpty ? 10 : 0)
|
|
}
|
|
|
|
private func playbackSlider() -> some View {
|
|
ComposeVoiceView.SliderBar(
|
|
length: TimeInterval(duration),
|
|
progress: $playbackTime,
|
|
seek: {
|
|
let time = max(0.0001, $0)
|
|
seek(time)
|
|
playbackTime = time
|
|
})
|
|
.onChange(of: .playing == playbackState || (playbackTime ?? 0) > 0) { show in
|
|
if !show {
|
|
allowMenu = true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct FramedCIVoiceView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
let im = ItemsModel.shared
|
|
let sentVoiceMessage: ChatItem = ChatItem(
|
|
chatDir: .directSnd,
|
|
meta: CIMeta.getSample(1, previewDate, "", .sndSent(sndProgress: .complete), itemEdited: true),
|
|
content: .sndMsgContent(msgContent: .voice(text: "Hello there", duration: 30)),
|
|
quotedItem: nil,
|
|
file: CIFile.getSample(fileStatus: .sndComplete)
|
|
)
|
|
let voiceMessageWithQuote: ChatItem = ChatItem(
|
|
chatDir: .directSnd,
|
|
meta: CIMeta.getSample(1, previewDate, "", .sndSent(sndProgress: .complete), itemEdited: true),
|
|
content: .sndMsgContent(msgContent: .voice(text: "", duration: 30)),
|
|
quotedItem: CIQuote.getSample(1, previewDate, "Hi", chatDir: .directRcv),
|
|
file: CIFile.getSample(fileStatus: .sndComplete)
|
|
)
|
|
Group {
|
|
ChatItemView(chat: Chat.sampleData, im: im, chatItem: sentVoiceMessage, scrollToItem: { _ in }, scrollToItemId: Binding.constant(nil)).modifier(ChatItemClipped(sentVoiceMessage, tailVisible: true))
|
|
let ci1 = previewDated(ChatItem.getVoiceMsgContentSample(text: "Hello there"))
|
|
ChatItemView(chat: Chat.sampleData, im: im, chatItem: ci1, scrollToItem: { _ in }, scrollToItemId: Binding.constant(nil)).modifier(ChatItemClipped(ci1, tailVisible: true))
|
|
let ci2 = previewDated(ChatItem.getVoiceMsgContentSample(text: "Hello there", fileStatus: .rcvTransfer(rcvProgress: 7, rcvTotal: 10)))
|
|
ChatItemView(chat: Chat.sampleData, im: im, chatItem: ci2, scrollToItem: { _ in }, scrollToItemId: Binding.constant(nil)).modifier(ChatItemClipped(ci2, tailVisible: true))
|
|
let ci3 = previewDated(ChatItem.getVoiceMsgContentSample(text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."))
|
|
ChatItemView(chat: Chat.sampleData, im: im, chatItem: ci3, scrollToItem: { _ in }, scrollToItemId: Binding.constant(nil)).modifier(ChatItemClipped(ci3, tailVisible: true))
|
|
ChatItemView(chat: Chat.sampleData, im: im, chatItem: voiceMessageWithQuote, scrollToItem: { _ in }, scrollToItemId: Binding.constant(nil)).modifier(ChatItemClipped(voiceMessageWithQuote, tailVisible: true))
|
|
}
|
|
.environment(\.revealed, false)
|
|
.previewLayout(.fixed(width: 360, height: 360))
|
|
}
|
|
}
|