@@ -10,6 +10,24 @@ import Foundation
10
10
import WebKit
11
11
import SafariServices
12
12
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
+
13
31
public class AdaWebHost : NSObject {
14
32
15
33
public enum AdaWebHostError : Error {
@@ -41,6 +59,9 @@ public class AdaWebHost: NSObject {
41
59
public var zdChatterAuthCallback : ( ( ( @escaping ( _ token: String ) -> Void ) ) -> Void ) ?
42
60
public var eventCallbacks : [ String : ( _ event: [ String : Any ] ) -> Void ] ?
43
61
62
+ ///Set modal navigation bar and status bar to grey by default
63
+ public var navigationBarOpaqueBackground = false
64
+
44
65
/// Here's where we do our business
45
66
private var webView : WKWebView ?
46
67
@@ -83,7 +104,8 @@ public class AdaWebHost: NSObject {
83
104
webViewLoadingErrorCallback: ( ( Error ) -> Void ) ? = nil ,
84
105
eventCallbacks: [ String : ( _ event: [ String : Any ] ) -> Void ] ? = nil ,
85
106
webViewTimeout: Double = 30.0 ,
86
- deviceToken: String = " "
107
+ deviceToken: String = " " ,
108
+ navigationBarOpaqueBackground: Bool = false
87
109
) {
88
110
self . handle = handle
89
111
self . cluster = cluster
@@ -104,6 +126,7 @@ public class AdaWebHost: NSObject {
104
126
self . webViewTimeout = webViewTimeout
105
127
self . hasError = false
106
128
self . deviceToken = deviceToken
129
+ self . navigationBarOpaqueBackground = navigationBarOpaqueBackground
107
130
108
131
self . reachability = Reachability ( ) !
109
132
super. init ( )
@@ -293,6 +316,20 @@ public class AdaWebHost: NSObject {
293
316
webView. translatesAutoresizingMaskIntoConstraints = true
294
317
let webNavController = AdaWebHostViewController . createNavController ( with: webView)
295
318
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
+ }
296
333
viewController. present ( webNavController, animated: true , completion: nil )
297
334
}
298
335
0 commit comments