Skip to content

Commit

Permalink
Update WebView #minor
Browse files Browse the repository at this point in the history
  • Loading branch information
aromanov91 committed May 17, 2024
1 parent 758c76d commit 34e83f9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
6 changes: 3 additions & 3 deletions Sources/OversizeComponents/NoteEditor/NoteEditor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// NoteEditor.swift, created on 03.03.2024
//

import SwiftUI
import OversizeUI
import SwiftUI

@available(iOS 16.0, *)
public struct NoteEditor: View {
Expand Down Expand Up @@ -40,9 +40,9 @@ public struct NoteEditor: View {
}
}
}
#if os(iOS)
#if os(iOS)
.navigationBarTitleDisplayMode(.inline)
#endif
#endif
.onAppear {
isFocus = true
}
Expand Down
56 changes: 31 additions & 25 deletions Sources/OversizeComponents/WebView/WebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ import OversizeUI
import SwiftUI
import WebKit

#if os(iOS)
public struct WebView: View {
@State var tabBarVisibility: Visibility = .hidden
@Environment(\.openURL) var openURL
public struct WebView: View {
@State var tabBarVisibility: Visibility = .hidden
@Environment(\.openURL) var openURL

private let url: URL
private let url: URL

public init(url: URL) {
self.url = url
}
public init(url: URL) {
self.url = url
}

public var body: some View {
public var body: some View {
#if os(iOS)
if #available(iOS 16.0, *) {
webView
.toolbar(tabBarVisibility, for: .tabBar)
Expand All @@ -28,22 +28,28 @@ import WebKit
} else {
webView
}
}
#else
EmptyView()
#endif
}

var webView: some View {
VStack(spacing: .zero) {
ModalNavigationBar(title: "", largeTitle: false, leadingBar: {
BarButton(.back)
}, trailingBar: {
BarButton(.icon(.globe, action: {
openURL(url)
}))
})
var webView: some View {
VStack(spacing: .zero) {
ModalNavigationBar(title: "", largeTitle: false, leadingBar: {
BarButton(.back)
}, trailingBar: {
BarButton(.icon(.globe, action: {
openURL(url)
}))
})
#if os(iOS)
WebViewRepresentable(url: url)
}
#endif
}
}
}

#if os(iOS)
public struct WebViewRepresentable: UIViewRepresentable {
private let request: URLRequest

Expand All @@ -59,10 +65,10 @@ import WebKit
uiView.load(request)
}
}
#endif

struct WebView_Previews: PreviewProvider {
static var previews: some View {
WebView(url: URL(string: "https://www.apple.com")!)
}
struct WebView_Previews: PreviewProvider {
static var previews: some View {
WebView(url: URL(string: "https://www.apple.com")!)
}
#endif
}

0 comments on commit 34e83f9

Please sign in to comment.