-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
254 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
DuckDuckGo/Autofill/Onboarding/AutofillToolbarOnboardingPopover.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// AutofillToolbarOnboardingPopover.swift | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// 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 | ||
|
||
final class AutofillToolbarOnboardingPopover: NSPopover { | ||
let ctaCallback: (Bool) -> Void | ||
|
||
init(ctaCallback: @escaping (Bool) -> Void) { | ||
self.ctaCallback = ctaCallback | ||
|
||
super.init() | ||
|
||
self.animates = false | ||
self.behavior = .semitransient | ||
|
||
setupContentController() | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("\(Self.self): Bad initializer") | ||
} | ||
|
||
private func setupContentController() { | ||
let controller = AutofillToolbarOnboardingViewController() | ||
controller.ctaCallback = self.ctaCallback | ||
contentViewController = controller | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
DuckDuckGo/Autofill/Onboarding/AutofillToolbarOnboardingView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// | ||
// AutofillToolbarOnboardingView.swift | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// 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 | ||
import SwiftUIExtensions | ||
|
||
struct AutofillToolbarOnboardingView: View { | ||
@ObservedObject var viewModel: AutofillToolbarOnboardingViewModel | ||
|
||
enum Constants { | ||
static let verticalSpacing: CGFloat = 16 | ||
static let panelWidth: CGFloat = 310 | ||
static let panelHeight: CGFloat = 148 | ||
} | ||
|
||
var body: some View { | ||
VStack(spacing: Constants.verticalSpacing) { | ||
VStack(alignment: .leading, spacing: Constants.verticalSpacing) { | ||
Text(UserText.autofillOnboardingPopoverTitle) | ||
.font(.headline) | ||
Text(UserText.autofillOnboardingPopoverMessage) | ||
} | ||
|
||
HStack { | ||
createButton(title: UserText.autofillOnboardingPopoverCTAReject, | ||
style: StandardButtonStyle(), | ||
action: viewModel.rejectToolbarIcon) | ||
|
||
createButton(title: UserText.autofillOnboardingPopoverCTAAccept, | ||
style: DefaultActionButtonStyle(enabled: true), | ||
action: viewModel.acceptToolbarIcon) | ||
} | ||
} | ||
.padding() | ||
.frame(width: Constants.panelWidth, height: Constants.panelHeight) | ||
} | ||
|
||
private func createButton(title: String, style: some ButtonStyle, action: @escaping () -> Void) -> some View { | ||
Button(action: action) { | ||
Text(title) | ||
.font(.system(size: 13)) | ||
.fontWeight(.light) | ||
.frame(maxWidth: .infinity) | ||
.frame(height: 22) | ||
} | ||
.buttonStyle(style) | ||
.padding(0) | ||
} | ||
} | ||
|
||
#Preview { | ||
AutofillToolbarOnboardingView(viewModel: AutofillToolbarOnboardingViewModel()) | ||
} |
38 changes: 38 additions & 0 deletions
38
DuckDuckGo/Autofill/Onboarding/AutofillToolbarOnboardingViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// AutofillToolbarOnboardingViewController.swift | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// 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 | ||
|
||
final class AutofillToolbarOnboardingViewController: NSViewController { | ||
var ctaCallback: ((Bool) -> Void)? | ||
|
||
private let viewModel = AutofillToolbarOnboardingViewModel() | ||
private var hostingView: NSHostingView<AutofillToolbarOnboardingView>! | ||
|
||
override func loadView() { | ||
let onboardingView = AutofillToolbarOnboardingView(viewModel: viewModel) | ||
hostingView = NSHostingView(rootView: onboardingView) | ||
self.view = hostingView | ||
|
||
self.setupViewModelCallbacks() | ||
} | ||
|
||
private func setupViewModelCallbacks() { | ||
viewModel.ctaCallback = ctaCallback | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
DuckDuckGo/Autofill/Onboarding/AutofillToolbarOnboardingViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// AutofillToolbarOnboardingViewModel.swift | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// 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. | ||
// | ||
|
||
final class AutofillToolbarOnboardingViewModel: ObservableObject { | ||
var ctaCallback: ((Bool) -> Void)? | ||
|
||
internal init(ctaCallback: ((Bool) -> Void)? = nil) { | ||
self.ctaCallback = ctaCallback | ||
} | ||
|
||
func rejectToolbarIcon() { | ||
ctaCallback?(false) | ||
} | ||
|
||
func acceptToolbarIcon() { | ||
ctaCallback?(true) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.