Skip to content

Commit 5f29808

Browse files
committed
add header bg neutral grey
1 parent 1479ad8 commit 5f29808

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

EmbedFramework/AdaWebHost.swift

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,24 @@ import Foundation
1010
import WebKit
1111
import SafariServices
1212

13+
extension UIColor {
14+
convenience init(red: Int, green: Int, blue: Int) {
15+
assert(red >= 0 && red <= 255, "Invalid red component")
16+
assert(green >= 0 && green <= 255, "Invalid green component")
17+
assert(blue >= 0 && blue <= 255, "Invalid blue component")
18+
19+
self.init(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: 1.0)
20+
}
21+
22+
convenience init(rgb: Int) {
23+
self.init(
24+
red: (rgb >> 16) & 0xFF,
25+
green: (rgb >> 8) & 0xFF,
26+
blue: rgb & 0xFF
27+
)
28+
}
29+
}
30+
1331
public class AdaWebHost: NSObject {
1432

1533
public enum AdaWebHostError: Error {
@@ -41,6 +59,9 @@ public class AdaWebHost: NSObject {
4159
public var zdChatterAuthCallback: (((@escaping (_ token: String) -> Void)) -> Void)?
4260
public var eventCallbacks: [String: (_ event: [String: Any]) -> Void]?
4361

62+
///Set modal navigation bar and status bar to grey by default
63+
public var navigationBarOpaqueBackground = false
64+
4465
/// Here's where we do our business
4566
private var webView: WKWebView?
4667

@@ -83,7 +104,8 @@ public class AdaWebHost: NSObject {
83104
webViewLoadingErrorCallback: ((Error) -> Void)? = nil,
84105
eventCallbacks: [String: (_ event: [String: Any]) -> Void]? = nil,
85106
webViewTimeout: Double = 30.0,
86-
deviceToken: String = ""
107+
deviceToken: String = "",
108+
navigationBarOpaqueBackground: Bool = false
87109
) {
88110
self.handle = handle
89111
self.cluster = cluster
@@ -104,6 +126,7 @@ public class AdaWebHost: NSObject {
104126
self.webViewTimeout = webViewTimeout
105127
self.hasError = false
106128
self.deviceToken = deviceToken
129+
self.navigationBarOpaqueBackground = navigationBarOpaqueBackground
107130

108131
self.reachability = Reachability()!
109132
super.init()
@@ -293,6 +316,20 @@ public class AdaWebHost: NSObject {
293316
webView.translatesAutoresizingMaskIntoConstraints = true
294317
let webNavController = AdaWebHostViewController.createNavController(with: webView)
295318
webNavController.modalPresentationStyle = .overFullScreen
319+
if self.navigationBarOpaqueBackground {
320+
321+
webNavController.modalPresentationStyle = .fullScreen
322+
webNavController.navigationBar.backgroundColor = UIColor(rgb: 0xF3F3F3)
323+
if #available(iOS 13.0, *) {
324+
let navBarAppearance = UINavigationBarAppearance()
325+
navBarAppearance.configureWithOpaqueBackground()
326+
navBarAppearance.titleTextAttributes = [.foregroundColor: UIColor.white]
327+
navBarAppearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]
328+
navBarAppearance.backgroundColor = UIColor(rgb: 0xF3F3F3)
329+
webNavController.navigationBar.standardAppearance = navBarAppearance
330+
webNavController.navigationBar.scrollEdgeAppearance = navBarAppearance
331+
}
332+
}
296333
viewController.present(webNavController, animated: true, completion: nil)
297334
}
298335

ExampleApp/ViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import UIKit
1010
import AdaEmbedFramework
1111

1212
class ViewController: UIViewController {
13-
lazy var adaFramework = AdaWebHost(handle: "nic", appScheme: "adaexampleapp", webViewLoadingErrorCallback: LoadingErrorCallback, webViewTimeout: 30.0)
13+
lazy var adaFramework = AdaWebHost(handle: "nic", appScheme: "adaexampleapp", webViewLoadingErrorCallback: LoadingErrorCallback, webViewTimeout: 30.0, navigationBarOpaqueBackground: true)
1414

1515
@IBOutlet var firstNameField: UITextField!
1616
@IBOutlet var lastNameField: UITextField!

0 commit comments

Comments
 (0)