Created
September 26, 2024 11:28
-
-
Save CH3COOH/fbd983b571ead7db9cf913896b5a2c1c to your computer and use it in GitHub Desktop.
ContentView.swift
This file contains hidden or 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
import SafariServices | |
import SwiftUI | |
struct SafariView: UIViewControllerRepresentable { | |
let url: URL | |
func makeUIViewController(context: Context) -> SFSafariViewController { | |
return SFSafariViewController(url: url) | |
} | |
func updateUIViewController(_: SFSafariViewController, context: Context) {} | |
} | |
struct ContentView: View { | |
@State private var isShowingSafariView = false | |
let url = URL(string: "https://blog.ch3cooh.jp/")! | |
var body: some View { | |
VStack { | |
Button(action: { | |
isShowingSafariView = true | |
}) { | |
Text("ブラウザを開く") | |
} | |
.fullScreenCover(isPresented: $isShowingSafariView) { | |
SafariView(url: url) | |
} | |
} | |
} | |
} | |
#Preview { | |
ContentView() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment