mirror of
https://github.com/ivanvorobei/SwiftUI.git
synced 2026-04-27 02:58:43 +02:00
Add Async image loading
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
See LICENSE folder for this sample’s licensing information.
|
||||
|
||||
Abstract:
|
||||
A view that clips an image to a circle and adds a stroke and shadow.
|
||||
*/
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct CircleImage: View {
|
||||
var image: Image
|
||||
|
||||
var body: some View {
|
||||
image
|
||||
.clipShape(Circle())
|
||||
.overlay(Circle().stroke(Color.white, lineWidth: 4))
|
||||
.shadow(radius: 10)
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
struct CircleImage_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
CircleImage(image: Image("turtlerock"))
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
See LICENSE folder for this sample’s licensing information.
|
||||
|
||||
Abstract:
|
||||
A single row to be displayed in a list of landmarks.
|
||||
*/
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct LandmarkRow: View {
|
||||
var landmark: Landmark
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
landmark.image(forSize: 50)
|
||||
Text(verbatim: landmark.name)
|
||||
Spacer()
|
||||
|
||||
if landmark.isFavorite {
|
||||
Image(systemName: "star.fill")
|
||||
.imageScale(.medium)
|
||||
.foregroundColor(.yellow)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
struct LandmarkRow_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
Group {
|
||||
LandmarkRow(landmark: landmarkData[0])
|
||||
LandmarkRow(landmark: landmarkData[1])
|
||||
}
|
||||
.previewLayout(.fixed(width: 300, height: 70))
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
See LICENSE folder for this sample’s licensing information.
|
||||
|
||||
Abstract:
|
||||
A view that hosts an `MKMapView`.
|
||||
*/
|
||||
|
||||
import SwiftUI
|
||||
import MapKit
|
||||
|
||||
struct MapView: UIViewRepresentable {
|
||||
var coordinate: CLLocationCoordinate2D
|
||||
|
||||
func makeUIView(context: Context) -> MKMapView {
|
||||
MKMapView(frame: .zero)
|
||||
}
|
||||
|
||||
func updateUIView(_ view: MKMapView, context: Context) {
|
||||
let span = MKCoordinateSpan(latitudeDelta: 0.02, longitudeDelta: 0.02)
|
||||
let region = MKCoordinateRegion(center: coordinate, span: span)
|
||||
view.setRegion(region, animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
struct MapView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
MapView(coordinate: landmarkData[0].locationCoordinate)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user