Polish up URL formatting on details view.
This commit is contained in:
parent
c6ea070356
commit
8ba7a51628
|
@ -1,3 +0,0 @@
|
|||
import UIKit
|
||||
|
||||
var str = "Hello, playground"
|
|
@ -0,0 +1,46 @@
|
|||
//: [Previous](@previous)
|
||||
|
||||
import UIKit
|
||||
|
||||
|
||||
//let urlString = #"https:\/\/www.google.ee\/maps\/place\/39°15'46.2\"S+177°51'52.1\"E\/"#
|
||||
//let urlString = #"https://www.google.com/maps/place/30°24'08.0"N+130°58'30.0"E/"#
|
||||
//let urlString = #"https:\/\/en.wikipedia.org\/wiki\/ELA-1"#
|
||||
let urlString = #"https:\/\/twitter.com\/rocketlab"#
|
||||
|
||||
|
||||
print(urlString)
|
||||
print(urlString.replacingOccurrences(of: #"\"#, with: ""))
|
||||
|
||||
urlString
|
||||
urlString.removingPercentEncoding
|
||||
|
||||
|
||||
let url = URL(
|
||||
string: urlString
|
||||
.replacingOccurrences(of: #"\"#, with: "")
|
||||
.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
|
||||
)
|
||||
|
||||
//
|
||||
//print(url?.absoluteURL)
|
||||
//print(url?.absoluteURL.path)
|
||||
//print(url!.host)
|
||||
//print(url!.host!.replacingOccurrences(of: "www.", with: ""))
|
||||
//print(url!.host!.replacingOccurrences(of: "www.", with: "").replacingOccurrences(of: ".com", with: ""))
|
||||
|
||||
|
||||
/// Strips the leading "sub domain" and trailing "top-level domain"
|
||||
/// parts (including the ".") from a URL `host` string
|
||||
|
||||
print(url!.host!.split(separator: ".").count <= 2)
|
||||
|
||||
print(
|
||||
url!.host!
|
||||
.replacingOccurrences(of: "^(\\w*\\.){1}", with: "", options: .regularExpression)
|
||||
.replacingOccurrences(of: "\\.(.*)", with: "", options: .regularExpression)
|
||||
.capitalized
|
||||
)
|
||||
|
||||
|
||||
//: [Next](@next)
|
|
@ -1,4 +1,2 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<playground version='5.0' target-platform='ios' executeOnSourceChanges='false'>
|
||||
<timeline fileName='timeline.xctimeline'/>
|
||||
</playground>
|
||||
<playground version='6.0' target-platform='ios'/>
|
|
@ -27,6 +27,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
|||
// Create the SwiftUI view that provides the window contents.
|
||||
let entryView = PadsListContainerView()
|
||||
.environmentObject(store)
|
||||
.accentColor(.pink)
|
||||
|
||||
window.rootViewController = UIHostingController(rootView: entryView)
|
||||
|
||||
|
|
|
@ -105,21 +105,24 @@ extension PadDetailsView.ViewModel {
|
|||
// MARK: - Private Helpers
|
||||
private extension PadDetailsView.ViewModel {
|
||||
|
||||
/// Strips the leading "sub domain" and trailing "top-level domain"
|
||||
/// parts (including the ".") from a URL `host` string
|
||||
func strippedHostName(from hostNameString: String) -> String {
|
||||
hostNameString
|
||||
.replacingOccurrences(of: "www.", with: "")
|
||||
var hostNameString = hostNameString
|
||||
|
||||
// Strip the leading sub domain part if it exists
|
||||
if hostNameString.split(separator: ".").count > 2 {
|
||||
hostNameString = hostNameString
|
||||
.replacingOccurrences(of: "^(\\w*\\.){1}", with: "", options: .regularExpression)
|
||||
}
|
||||
|
||||
// Strip the trailing top-level domain part
|
||||
return hostNameString
|
||||
.replacingOccurrences(of: "\\.(.*)", with: "", options: .regularExpression)
|
||||
.capitalized
|
||||
}
|
||||
|
||||
|
||||
func setupSubscribers() {
|
||||
|
||||
// snapshotImagePublisher
|
||||
// .receive(on: DispatchQueue.main)
|
||||
// .sink(
|
||||
// receiveValue: { self.mapSnapshotImage = $0 }
|
||||
// )
|
||||
// .store(in: &subscriptions)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,6 +38,8 @@ extension PadDetailsView: View {
|
|||
}
|
||||
}
|
||||
.padding(.horizontal)
|
||||
|
||||
Spacer()
|
||||
}
|
||||
.onAppear {
|
||||
self.viewModel.takeMapSnapshot(
|
||||
|
@ -82,6 +84,7 @@ extension PadDetailsView {
|
|||
.padding(.top)
|
||||
}
|
||||
|
||||
|
||||
private var linksSection: some View {
|
||||
Section(
|
||||
header: Text("Links").font(.headline)
|
||||
|
@ -123,5 +126,6 @@ struct PadDetailsView_Previews: PreviewProvider {
|
|||
)
|
||||
)
|
||||
}
|
||||
.navigationViewStyle(StackNavigationViewStyle())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,17 +52,7 @@ private extension PadsListContainerView {
|
|||
store.send(PadsSideEffect.fetchPads)
|
||||
}
|
||||
|
||||
|
||||
// func makeSnapshotter(for pad: Pad) -> MKMapSnapshotter {
|
||||
// let snapshotOptions = pad.baseSnapshotOptions
|
||||
//
|
||||
// snapshotOptions.size = CGSize(width: 200, height: 200)
|
||||
//
|
||||
//
|
||||
// return MKMapSnapshotter(options: snapshotOptions)
|
||||
// }
|
||||
|
||||
|
||||
|
||||
func makeSnapshotOptions(for pad: Pad) -> MKMapSnapshotter.Options {
|
||||
let snapshotOptions = pad.baseSnapshotOptions
|
||||
|
||||
|
@ -70,26 +60,13 @@ private extension PadsListContainerView {
|
|||
}
|
||||
|
||||
|
||||
// func makeSnapshotService(for pad: Pad) -> MKMapSnapshotter {
|
||||
// let service = MapSnapshottingService.shared
|
||||
// let snapshotOptions = pad.baseSnapshotOptions
|
||||
//
|
||||
// snapshotOptions.size = CGSize(width: 300, height: 300)
|
||||
//
|
||||
//
|
||||
// return MKMapSnapshotter(options: snapshotOptions)
|
||||
// }
|
||||
//
|
||||
|
||||
func buildDestination(forPad pad: Pad) -> some View {
|
||||
PadDetailsView(
|
||||
viewModel: .init(
|
||||
pad: pad,
|
||||
snapshotService: MapSnapshottingService(
|
||||
// snapshotter: makeSnapshotter(for: pad)
|
||||
snapshotOptions: makeSnapshotOptions(for: pad)
|
||||
)
|
||||
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue