คอมโพเนนต์รายการสถานที่ขั้นสูง
คอมโพเนนต์รายการสถานที่ขั้นสูงช่วยให้คุณกำหนดและแสดงรายการสถานที่ได้ คุณสามารถแสดงสถานที่ได้สูงสุด 20 แห่งจากชุดข้อมูลประจำตัวเดียวกันที่คอมโพเนนต์รายละเอียดสถานที่รองรับ (รหัสสถานที่ ชื่อทรัพยากรสถานที่ หรือพิกัดละติจูด/ลองจิจูด)
คุณเลือกแสดงรายการในแนวนอนหรือแนวตั้งได้ การวางแนวเริ่มต้นคือแนวตั้ง ข้อมูลและตัวเลือกการกำหนดค่าเดียวกันกับที่แสดงในบัตรข้อมูลสถานที่แบบย่อและแบบเต็มจะพร้อมใช้งานสำหรับแต่ละรายการ
ใช้พารามิเตอร์orientation, placeIdentifiers และ configuration ของ AdvancedPlaceListView เพื่อสร้างรายการ ดูรายละเอียดเพิ่มเติมได้ที่ตัวอย่าง
การเรียกเก็บเงิน
ระบบจะเรียกเก็บเงินจากคุณสำหรับการขอรายการแต่ละครั้ง และการเปลี่ยนแปลงรายการถือเป็นเหตุการณ์ใหม่ที่เรียกเก็บเงินได้
ตัวอย่าง
ตัวอย่างนี้สร้างรายการโดยอิงตามตัวระบุสถานที่ พารามิเตอร์ configuration ระบุว่าแต่ละรายการจะแสดงที่อยู่ คะแนน และประเภท พร้อมกับข้อกำหนดอื่นๆ เกี่ยวกับภาพ ระบบจะสร้างการดำเนินการหลักเพื่อให้ผู้ใช้เพิ่มหรือนำรายการแต่ละรายการออกจากรายการโปรดได้ การดำเนินการที่มุมจะปิดใช้สำหรับแต่ละรายการ
Swift
struct AdvancedPlaceListDemoView: View { private let configuration = AdvancedPlaceListConfiguration( content: [.address(), .rating(), .type()], preferTruncation: true, theme: PlacesMaterialTheme(), attributionPosition: .bottom, mediaSize = .medium, selectable: true ) @State private var placeIdentifiers = [.placeID("ChIJj61dQgK6j4AR4GeTYWZsKWw")] @State private var favoritePlaces: Set<String> = [] var body: some View { AdvancedPlaceListView( orientation: .horizontal, // default is vertical placeIdentifiers: placeIdentifiers, configuration: configuration ) .onLoad { results in for result in results { switch result { case .success(let place) print("place: \(place)") case .failure(let error) print("error: \(error)") } } } .onPlaceSelected { place, index in print("place: \(place)") print("index: \(index)") } .mainActions { place in var actions: [MainPlaceActionElement] = [] let placeID = place.placeID! if self.favoritePlaces.contains(placeID) { actions.append( .action( MainPlaceAction( image: Image(systemName: "heart.fill"), label: "Unfavorite" ) { _ in self.toggleFavorite(placeID) } ) ) } else { actions.append( .action( MainPlaceAction( image: Image(systemName: "heart"), label: "Favorite" ) { _ in self.toggleFavorite(placeID) } ) ) } actions.append(.actionId(.openMap(style: .primary))) return actions } // Ensures that there are no corner actions. .cornerActions { _ in return [] } } func toggleFavorite(_ placeID: String) { if favoritePlaces.contains(placeID) { favoritePlaces.remove(placeID) } else { favoritePlaces.insert(placeID) } } }