Polish up URL formatting on details view.

This commit is contained in:
CypherPoet 2020-01-29 00:23:22 -06:00
parent c6ea070356
commit 8ba7a51628
7 changed files with 65 additions and 39 deletions

View File

@ -1,3 +0,0 @@
import UIKit
var str = "Hello, playground"

View File

@ -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)

View File

@ -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'/>

View File

@ -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)

View File

@ -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)
}
}

View File

@ -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())
}
}

View File

@ -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)
)
)
)
}