From 7273be84d88247175fadd1d9234921ee3bb95b23 Mon Sep 17 00:00:00 2001 From: Fernando Bunn Date: Wed, 11 Dec 2024 11:55:10 -0300 Subject: [PATCH] Ship review feedback - Color + Orientation (#3715) Task/Issue URL: https://app.asana.com/0/1204167627774280/1208947094200047/f **Description**: Remove landscape mode for iPhone Change the background color for the AI Chat webview --- DuckDuckGo/MainViewController.swift | 3 +- ...ndedPageSheetContainerViewController.swift | 26 +++++++------ LocalPackages/AIChat/Package.swift | 10 +++-- .../AIChat/AIChatWebViewController.swift | 2 +- .../Resources/Assets.xcassets/Contents.json | 6 +++ .../Contents.json | 38 +++++++++++++++++++ .../Sources/AIChat/UIColor+Extension.swift | 26 +++++++++++++ 7 files changed, 95 insertions(+), 16 deletions(-) create mode 100644 LocalPackages/AIChat/Sources/AIChat/Resources/Assets.xcassets/Contents.json create mode 100644 LocalPackages/AIChat/Sources/AIChat/Resources/Assets.xcassets/webViewBackgroundColor.colorset/Contents.json create mode 100644 LocalPackages/AIChat/Sources/AIChat/UIColor+Extension.swift diff --git a/DuckDuckGo/MainViewController.swift b/DuckDuckGo/MainViewController.swift index d142c865e7..db55cc9565 100644 --- a/DuckDuckGo/MainViewController.swift +++ b/DuckDuckGo/MainViewController.swift @@ -1719,7 +1719,8 @@ class MainViewController: UIViewController { let roundedPageSheet = RoundedPageSheetContainerViewController( contentViewController: aiChatViewController, logoImage: logoImage, - title: title) + title: title, + allowedOrientation: .portrait) present(roundedPageSheet, animated: true, completion: nil) } diff --git a/DuckDuckGo/RoundedPageContainer/RoundedPageSheetContainerViewController.swift b/DuckDuckGo/RoundedPageContainer/RoundedPageSheetContainerViewController.swift index 880f474802..a9cb54dc7e 100644 --- a/DuckDuckGo/RoundedPageContainer/RoundedPageSheetContainerViewController.swift +++ b/DuckDuckGo/RoundedPageContainer/RoundedPageSheetContainerViewController.swift @@ -23,6 +23,7 @@ final class RoundedPageSheetContainerViewController: UIViewController { let contentViewController: UIViewController private let logoImage: UIImage? private let titleText: String + private let allowedOrientation: UIInterfaceOrientationMask private lazy var titleBarView: TitleBarView = { let titleBarView = TitleBarView(logoImage: logoImage, title: titleText) { [weak self] in @@ -31,13 +32,13 @@ final class RoundedPageSheetContainerViewController: UIViewController { return titleBarView }() - init(contentViewController: UIViewController, logoImage: UIImage?, title: String) { + init(contentViewController: UIViewController, logoImage: UIImage?, title: String, allowedOrientation: UIInterfaceOrientationMask = .all) { self.contentViewController = contentViewController self.logoImage = logoImage self.titleText = title + self.allowedOrientation = allowedOrientation super.init(nibName: nil, bundle: nil) modalPresentationStyle = .custom - transitioningDelegate = self } @@ -45,6 +46,18 @@ final class RoundedPageSheetContainerViewController: UIViewController { fatalError("init(coder:) has not been implemented") } + override var shouldAutorotate: Bool { + return false + } + + override var supportedInterfaceOrientations: UIInterfaceOrientationMask { + return allowedOrientation + } + + override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation { + return UIInterfaceOrientation.portrait + } + override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .black @@ -53,15 +66,6 @@ final class RoundedPageSheetContainerViewController: UIViewController { setupContentViewController() } - override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { - super.viewWillTransition(to: size, with: coordinator) - - coordinator.animate(alongsideTransition: { _ in - // Update layout or constraints here - }, completion: nil) - } - - private func setupTitleBar() { view.addSubview(titleBarView) titleBarView.translatesAutoresizingMaskIntoConstraints = false diff --git a/LocalPackages/AIChat/Package.swift b/LocalPackages/AIChat/Package.swift index 70d6f9499d..478b4b4705 100644 --- a/LocalPackages/AIChat/Package.swift +++ b/LocalPackages/AIChat/Package.swift @@ -1,6 +1,5 @@ // swift-tools-version: 6.0 // The swift-tools-version declares the minimum version of Swift required to build this package. - import PackageDescription let package = Package( @@ -11,10 +10,15 @@ let package = Package( products: [ .library( name: "AIChat", - targets: ["AIChat"]), + targets: ["AIChat"] + ), ], targets: [ .target( - name: "AIChat"), + name: "AIChat", + resources: [ + .process("Resources/Assets.xcassets") + ] + ), ] ) diff --git a/LocalPackages/AIChat/Sources/AIChat/AIChatWebViewController.swift b/LocalPackages/AIChat/Sources/AIChat/AIChatWebViewController.swift index ec0d1d5d2d..2c2e47fa20 100644 --- a/LocalPackages/AIChat/Sources/AIChat/AIChatWebViewController.swift +++ b/LocalPackages/AIChat/Sources/AIChat/AIChatWebViewController.swift @@ -30,7 +30,7 @@ final class AIChatWebViewController: UIViewController { private lazy var webView: WKWebView = { let webView = WKWebView(frame: .zero, configuration: chatModel.webViewConfiguration) webView.isOpaque = false /// Required to make the background color visible - webView.backgroundColor = .systemBackground + webView.backgroundColor = .webViewBackgroundColor webView.navigationDelegate = self webView.translatesAutoresizingMaskIntoConstraints = false return webView diff --git a/LocalPackages/AIChat/Sources/AIChat/Resources/Assets.xcassets/Contents.json b/LocalPackages/AIChat/Sources/AIChat/Resources/Assets.xcassets/Contents.json new file mode 100644 index 0000000000..73c00596a7 --- /dev/null +++ b/LocalPackages/AIChat/Sources/AIChat/Resources/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/LocalPackages/AIChat/Sources/AIChat/Resources/Assets.xcassets/webViewBackgroundColor.colorset/Contents.json b/LocalPackages/AIChat/Sources/AIChat/Resources/Assets.xcassets/webViewBackgroundColor.colorset/Contents.json new file mode 100644 index 0000000000..ed36c62a6f --- /dev/null +++ b/LocalPackages/AIChat/Sources/AIChat/Resources/Assets.xcassets/webViewBackgroundColor.colorset/Contents.json @@ -0,0 +1,38 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "1.000", + "green" : "1.000", + "red" : "1.000" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0.086", + "green" : "0.086", + "red" : "0.086" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/LocalPackages/AIChat/Sources/AIChat/UIColor+Extension.swift b/LocalPackages/AIChat/Sources/AIChat/UIColor+Extension.swift new file mode 100644 index 0000000000..f78e43ecca --- /dev/null +++ b/LocalPackages/AIChat/Sources/AIChat/UIColor+Extension.swift @@ -0,0 +1,26 @@ +// +// UIColor+Extension.swift +// DuckDuckGo +// +// 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 UIKit + +extension UIColor { + static var webViewBackgroundColor: UIColor { + return UIColor(named: "webViewBackgroundColor", in: Bundle.module, compatibleWith: nil) ?? UIColor.clear + } +}