Skip to content

Commit

Permalink
Add Translate Toast and Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon-T committed Sep 4, 2024
1 parent e740285 commit ab61b03
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Foundation
import Onboarding
import Preferences
import UIKit
import SwiftUI

extension BrowserViewController: BraveTranslateScriptHandlerDelegate {
func updateTranslateURLBar(tab: Tab?, state: TranslateURLBarButton.TranslateState) {
Expand Down Expand Up @@ -103,7 +104,15 @@ extension BrowserViewController: BraveTranslateScriptHandlerDelegate {

func presentToast(_ languageInfo: BraveTranslateLanguageInfo) {
let popover = PopoverController(
content: TranslateToast(languageInfo: languageInfo),
content: TranslateToast(languageInfo: languageInfo, presentSettings: { [weak self] in
guard let self = self else { return }

let popup = PopupViewController(rootView: TranslateSettingsView(), isDismissable: true)
self.present(popup, animated: true)
}, revertTranslation: { [weak self] in
guard let self = self else { return }
print("Dismissing")
}),
autoLayoutConfiguration: .phoneWidth
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright 2024 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

import SwiftUI

struct TranslateSettingsView: View {

var body: some View {
NavigationStack {
List {
Section {
NavigationLink {

} label: {
LabeledContent("From", value: "Selected Language")
}

NavigationLink {

} label: {
LabeledContent("To", value: "Selected Language")
}
} footer: {
VStack {
Button {

} label: {
Text("Translate")
.font(.body.weight(.semibold))
.padding()
.frame(maxWidth: .infinity)
.foregroundStyle(Color(braveSystemName: .schemesOnPrimary))
.background(
ContainerRelativeShape()
.fill(Color(braveSystemName: .buttonBackground))
)
.containerShape(RoundedRectangle(cornerRadius: 8.0, style: .continuous))
}
.buttonStyle(.plain)

Button {

} label: {
Text("Show Original")
.font(.body.weight(.semibold))
.padding()
.frame(maxWidth: .infinity)
.foregroundStyle(Color(braveSystemName: .textSecondary))
.background(
ContainerRelativeShape()
.fill(Color(.clear))
)
.containerShape(RoundedRectangle(cornerRadius: 8.0, style: .continuous))
}
.buttonStyle(.plain)
}
.listRowInsets(.init())
.padding(.top)
}
.navigationBarTitle("Translate")
.navigationBarTitleDisplayMode(.inline)
}
}
}
}

#Preview {
TranslateSettingsView()
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ import BraveUI
import SwiftUI

struct TranslateToast: View {
@Environment(\.dismiss)
private var dismiss

var languageInfo: BraveTranslateLanguageInfo
var presentSettings: (() -> Void)?
var revertTranslation: (() -> Void)?

var currentLanguageName: String {
if let languageCode = languageInfo.currentLanguage.languageCode?.identifier,
Expand Down Expand Up @@ -61,7 +65,8 @@ struct TranslateToast: View {
Spacer()

Button {

dismiss()
presentSettings?()
} label: {
Image(braveSystemName: "leo.settings")
.foregroundStyle(Color(braveSystemName: .iconDefault))
Expand All @@ -73,7 +78,8 @@ struct TranslateToast: View {
.padding([.leading, .trailing])

Button {

dismiss()
revertTranslation?()
} label: {
Text("Undo")
.foregroundStyle(Color(braveSystemName: .textInteractive))
Expand Down

0 comments on commit ab61b03

Please sign in to comment.