Skip to content

Commit 28e9291

Browse files
authored
[iOS] - Uplift Leo QA Iteration 4 - 1.64.x (#22812)
* [iOS] - Retry Leo Purchases & Add Logging (#22791) * Add Logging View for Leo Purchases. * Add logs everywhere which can be accessed via Console.app * Retry purchase receipt syncing up to 10 times if purchase transaction was verified. * Revert manual refreshing logic as it doesn't help. * Fix performance of rendering chat messages. Signed-off-by: Brandon T <[email protected]> * [iOS] - Fix layout of WrappingHStack when text becomes multi-line (#22608) * Fix layout of WrappingHStack when text becomes multi-line. * Also fix spacing between items in the wrapping HStack on iOS 15 when line becomes multi-line. Signed-off-by: Brandon T <[email protected]> * Fix compilation.Throw error when payment processing fails. Signed-off-by: Brandon T <[email protected]> --------- Signed-off-by: Brandon T <[email protected]>
1 parent 909da15 commit 28e9291

18 files changed

+652
-457
lines changed

ios/brave-ios/Sources/AIChat/Components/AIChatView.swift

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ public struct AIChatView: View {
1616
@ObservedObject
1717
var model: AIChatViewModel
1818

19+
@ObservedObject
20+
var speechRecognizer: SpeechRecognizer
21+
1922
@Environment(\.dismiss)
2023
private var dismiss
2124

@@ -42,8 +45,13 @@ public struct AIChatView: View {
4245

4346
var openURL: ((URL) -> Void)
4447

45-
public init(model: AIChatViewModel, openURL: @escaping (URL) -> Void) {
48+
public init(
49+
model: AIChatViewModel,
50+
speechRecognizer: SpeechRecognizer,
51+
openURL: @escaping (URL) -> Void
52+
) {
4653
self.model = model
54+
self.speechRecognizer = speechRecognizer
4755
self.openURL = openURL
4856
}
4957

@@ -236,7 +244,7 @@ public struct AIChatView: View {
236244
}
237245

238246
if model.isAgreementAccepted || (!hasSeenIntro.value && !model.isAgreementAccepted) {
239-
AIChatPromptInputView { prompt in
247+
AIChatPromptInputView(speechRecognizer: speechRecognizer) { prompt in
240248
hasSeenIntro.value = true
241249
model.submitQuery(prompt)
242250
hideKeyboard()
@@ -253,7 +261,7 @@ public struct AIChatView: View {
253261
AIChatPaywallView(
254262
premiumUpgrageSuccessful: { _ in
255263
Task { @MainActor in
256-
await model.refreshPremiumStatusOrderCredentials()
264+
await model.refreshPremiumStatus()
257265
}
258266
})
259267
}
@@ -265,7 +273,7 @@ public struct AIChatView: View {
265273
}
266274
.onAppear {
267275
Task { @MainActor in
268-
await model.refreshPremiumStatusOrderCredentials()
276+
await model.refreshPremiumStatus()
269277
}
270278

271279
if let query = model.querySubmited {
@@ -412,19 +420,14 @@ public struct AIChatView: View {
412420
},
413421
dismissAction: {
414422
Task { @MainActor in
415-
// This is needed to try to mitigate a bug in SkusSDK
416-
// See: https://github.com/brave/brave-browser/issues/36824
417-
// Also see the comment on the function
418-
if model.premiumStatus == .active || model.premiumStatus == .activeDisconnected {
419-
await model.refreshPremiumStatusOrderCredentials()
420-
}
421-
}
423+
await model.refreshPremiumStatus()
422424

423-
if let basicModel = model.models.first(where: { $0.access == .basic }) {
424-
model.changeModel(modelKey: basicModel.key)
425-
model.retryLastRequest()
426-
} else {
427-
Logger.module.error("No basic models available")
425+
if let basicModel = model.models.first(where: { $0.access == .basic }) {
426+
model.changeModel(modelKey: basicModel.key)
427+
model.retryLastRequest()
428+
} else {
429+
Logger.module.error("No basic models available")
430+
}
428431
}
429432
}
430433
)
@@ -441,6 +444,7 @@ public struct AIChatView: View {
441444

442445
private var feedbackView: some View {
443446
AIChatFeedbackView(
447+
speechRecognizer: speechRecognizer,
444448
premiumStatus: model.premiumStatus,
445449
shouldShowPremiumAd: shouldShowFeedbackPremiumAd.value,
446450
onSubmit: { category, feedback in
@@ -537,6 +541,7 @@ struct AIChatView_Preview: PreviewProvider {
537541
.background(Color(braveSystemName: .containerBackground))
538542

539543
AIChatFeedbackView(
544+
speechRecognizer: SpeechRecognizer(),
540545
premiumStatus: .inactive,
541546
shouldShowPremiumAd: true,
542547
onSubmit: {
@@ -572,7 +577,7 @@ struct AIChatView_Preview: PreviewProvider {
572577
)
573578
.padding()
574579

575-
AIChatPromptInputView {
580+
AIChatPromptInputView(speechRecognizer: SpeechRecognizer()) {
576581
print("Prompt Submitted: \($0)")
577582
}
578583
}

ios/brave-ios/Sources/AIChat/Components/Feedback/AIChatFeedbackView.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ private struct AIChatDropdownView: View {
185185
}
186186

187187
private struct AIChatFeedbackInputView: View {
188-
private var speechRecognizer = SpeechRecognizer()
188+
private var speechRecognizer: SpeechRecognizer
189189

190190
@State
191191
private var isVoiceEntryPresented = false
@@ -196,7 +196,8 @@ private struct AIChatFeedbackInputView: View {
196196
@Binding
197197
var text: String
198198

199-
init(text: Binding<String>) {
199+
init(speechRecognizer: SpeechRecognizer, text: Binding<String>) {
200+
self.speechRecognizer = speechRecognizer
200201
_text = text
201202
}
202203

@@ -337,6 +338,7 @@ struct AIChatFeedbackView: View {
337338
@State
338339
private var feedbackText: String = ""
339340

341+
var speechRecognizer: SpeechRecognizer
340342
var premiumStatus: AiChat.PremiumStatus
341343

342344
var shouldShowPremiumAd: Bool
@@ -360,7 +362,7 @@ struct AIChatFeedbackView: View {
360362
.frame(maxWidth: .infinity, alignment: .leading)
361363
.padding([.horizontal, .top])
362364

363-
AIChatFeedbackInputView(text: $feedbackText)
365+
AIChatFeedbackInputView(speechRecognizer: speechRecognizer, text: $feedbackText)
364366
.padding([.horizontal, .bottom])
365367

366368
if premiumStatus != .active && premiumStatus != .activeDisconnected && shouldShowPremiumAd {
@@ -397,6 +399,7 @@ struct AIChatFeedbackView: View {
397399
struct AIChatFeedbackView_Previews: PreviewProvider {
398400
static var previews: some View {
399401
AIChatFeedbackView(
402+
speechRecognizer: SpeechRecognizer(),
400403
premiumStatus: .inactive,
401404
shouldShowPremiumAd: true,
402405
onSubmit: {

ios/brave-ios/Sources/AIChat/Components/Input/AIChatPromptInputView.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import SpeechRecognition
99
import SwiftUI
1010

1111
struct AIChatPromptInputView: View {
12-
private var speechRecognizer = SpeechRecognizer()
12+
private var speechRecognizer: SpeechRecognizer
1313

1414
@State
1515
private var isVoiceEntryPresented = false
@@ -22,7 +22,8 @@ struct AIChatPromptInputView: View {
2222

2323
var onSubmit: (String) -> Void
2424

25-
init(onSubmit: @escaping (String) -> Void) {
25+
init(speechRecognizer: SpeechRecognizer, onSubmit: @escaping (String) -> Void) {
26+
self.speechRecognizer = speechRecognizer
2627
self.onSubmit = onSubmit
2728
}
2829

@@ -109,7 +110,7 @@ struct AIChatPromptInputView: View {
109110
#if DEBUG
110111
struct AIChatPromptInputView_Preview: PreviewProvider {
111112
static var previews: some View {
112-
AIChatPromptInputView {
113+
AIChatPromptInputView(speechRecognizer: SpeechRecognizer()) {
113114
print("Prompt Submitted: \($0)")
114115
}
115116
.previewLayout(.sizeThatFits)

0 commit comments

Comments
 (0)