ios: show progress after send with timeout correctly (#2887)

* ios: show progress after send with timeout correctly

* was wrong idea

* remove unused property

---------

Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
This commit is contained in:
Stanislav Dmitrenko 2023-08-10 23:38:11 +03:00 committed by GitHub
parent 97a1a00f17
commit 6ce00b45aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 11 deletions

View File

@ -44,7 +44,6 @@ struct ComposeState {
var contextItem: ComposeContextItem var contextItem: ComposeContextItem
var voiceMessageRecordingState: VoiceMessageRecordingState var voiceMessageRecordingState: VoiceMessageRecordingState
var inProgress = false var inProgress = false
var disabled = false
var useLinkPreviews: Bool = UserDefaults.standard.bool(forKey: DEFAULT_PRIVACY_LINK_PREVIEWS) var useLinkPreviews: Bool = UserDefaults.standard.bool(forKey: DEFAULT_PRIVACY_LINK_PREVIEWS)
init( init(
@ -655,10 +654,7 @@ struct ComposeView: View {
return sent return sent
func sending() async { func sending() async {
await MainActor.run { composeState.disabled = true } await MainActor.run { composeState.inProgress = true }
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
if composeState.disabled { composeState.inProgress = true }
}
} }
func updateMessage(_ ei: ChatItem, live: Bool) async -> ChatItem? { func updateMessage(_ ei: ChatItem, live: Bool) async -> ChatItem? {
@ -852,7 +848,6 @@ struct ComposeView: View {
private func clearState(live: Bool = false) { private func clearState(live: Bool = false) {
if live { if live {
composeState.disabled = false
composeState.inProgress = false composeState.inProgress = false
} else { } else {
composeState = ComposeState() composeState = ComposeState()

View File

@ -36,6 +36,7 @@ struct SendMessageView: View {
@State private var showCustomDisappearingMessageDialogue = false @State private var showCustomDisappearingMessageDialogue = false
@State private var showCustomTimePicker = false @State private var showCustomTimePicker = false
@State private var selectedDisappearingMessageTime: Int? = customDisappearingMessageTimeDefault.get() @State private var selectedDisappearingMessageTime: Int? = customDisappearingMessageTimeDefault.get()
@State private var progressByTimeout = false
var maxHeight: CGFloat = 360 var maxHeight: CGFloat = 360
var minHeight: CGFloat = 37 var minHeight: CGFloat = 37
@AppStorage(DEFAULT_LIVE_MESSAGE_ALERT_SHOWN) private var liveMessageAlertShown = false @AppStorage(DEFAULT_LIVE_MESSAGE_ALERT_SHOWN) private var liveMessageAlertShown = false
@ -81,7 +82,7 @@ struct SendMessageView: View {
} }
} }
if composeState.inProgress { if progressByTimeout {
ProgressView() ProgressView()
.scaleEffect(1.4) .scaleEffect(1.4)
.frame(width: 31, height: 31, alignment: .center) .frame(width: 31, height: 31, alignment: .center)
@ -102,6 +103,15 @@ struct SendMessageView: View {
.strokeBorder(.secondary, lineWidth: 0.3, antialiased: true) .strokeBorder(.secondary, lineWidth: 0.3, antialiased: true)
.frame(height: teHeight) .frame(height: teHeight)
} }
.onChange(of: composeState.inProgress) { inProgress in
if inProgress {
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
progressByTimeout = composeState.inProgress
}
} else {
progressByTimeout = false
}
}
.padding(.vertical, 8) .padding(.vertical, 8)
} }
@ -119,7 +129,7 @@ struct SendMessageView: View {
startVoiceMessageRecording: startVoiceMessageRecording, startVoiceMessageRecording: startVoiceMessageRecording,
finishVoiceMessageRecording: finishVoiceMessageRecording, finishVoiceMessageRecording: finishVoiceMessageRecording,
holdingVMR: $holdingVMR, holdingVMR: $holdingVMR,
disabled: composeState.disabled disabled: composeState.inProgress
) )
} else { } else {
voiceMessageNotAllowedButton() voiceMessageNotAllowedButton()
@ -165,7 +175,7 @@ struct SendMessageView: View {
} }
.disabled( .disabled(
!composeState.sendEnabled || !composeState.sendEnabled ||
composeState.disabled || composeState.inProgress ||
(!voiceMessageAllowed && composeState.voicePreview) || (!voiceMessageAllowed && composeState.voicePreview) ||
composeState.endLiveDisabled composeState.endLiveDisabled
) )
@ -293,7 +303,7 @@ struct SendMessageView: View {
Image(systemName: "mic") Image(systemName: "mic")
.foregroundColor(.secondary) .foregroundColor(.secondary)
} }
.disabled(composeState.disabled) .disabled(composeState.inProgress)
.frame(width: 29, height: 29) .frame(width: 29, height: 29)
.padding([.bottom, .trailing], 4) .padding([.bottom, .trailing], 4)
} }
@ -378,7 +388,7 @@ struct SendMessageView: View {
Image(systemName: "stop.fill") Image(systemName: "stop.fill")
.foregroundColor(.accentColor) .foregroundColor(.accentColor)
} }
.disabled(composeState.disabled) .disabled(composeState.inProgress)
.frame(width: 29, height: 29) .frame(width: 29, height: 29)
.padding([.bottom, .trailing], 4) .padding([.bottom, .trailing], 4)
} }