mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-22 17:39:52 +01:00
fix for SR-13069
This commit is contained in:
@@ -32,31 +32,46 @@ extension Modern.PokedexDemo {
|
||||
// MARK: View
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
ForEach(self.pokedexEntries.snapshot, id: \.self) { pokedexEntry in
|
||||
LazyView {
|
||||
Text(pokedexEntry.snapshot?.$name ?? "")
|
||||
ZStack {
|
||||
ScrollView {
|
||||
ForEach(self.pokedexEntries.snapshot.prefix(self.visibleItems), id: \.self) { pokedexEntry in
|
||||
LazyView {
|
||||
Text(pokedexEntry.snapshot?.$name ?? "")
|
||||
}
|
||||
.frame(height: 100)
|
||||
.frame(minWidth: 0, maxWidth: /*@START_MENU_TOKEN@*/.infinity/*@END_MENU_TOKEN@*/)
|
||||
}
|
||||
.frame(height: 100)
|
||||
Button(
|
||||
action: {
|
||||
self.visibleItems = min(
|
||||
self.visibleItems + 50,
|
||||
self.pokedexEntries.snapshot.count
|
||||
)
|
||||
},
|
||||
label: { Text("Load more") }
|
||||
)
|
||||
}
|
||||
if self.service.isLoading {
|
||||
Color(.sRGB, white: 0, opacity: 0.3)
|
||||
.overlay(
|
||||
Text("Fetching Pokedex…")
|
||||
.foregroundColor(.white),
|
||||
alignment: .center
|
||||
)
|
||||
.edgesIgnoringSafeArea(.bottom)
|
||||
}
|
||||
}
|
||||
.frame(minWidth: 0, maxWidth: /*@START_MENU_TOKEN@*/.infinity/*@END_MENU_TOKEN@*/)
|
||||
.overlay(
|
||||
InstructionsView(
|
||||
("Random", "Sets random coordinate"),
|
||||
("Tap", "Sets to tapped coordinate")
|
||||
)
|
||||
.padding(.leading, 10)
|
||||
.padding(.bottom, 40),
|
||||
alignment: .bottomLeading
|
||||
)
|
||||
.navigationBarTitle("Pokedex")
|
||||
}
|
||||
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private let service: Modern.PokedexDemo.Service = .init()
|
||||
@ObservedObject
|
||||
private var service: Modern.PokedexDemo.Service = .init()
|
||||
|
||||
@State
|
||||
private var visibleItems: Int = 50
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,15 +13,25 @@ extension Modern.PokedexDemo {
|
||||
|
||||
// MARK: - Modern.PokedexDemo.Service
|
||||
|
||||
final class Service {
|
||||
final class Service: ObservableObject {
|
||||
|
||||
// MARK: Internal
|
||||
|
||||
@Published
|
||||
var isLoading: Bool = true
|
||||
|
||||
@Published
|
||||
var lastError: (error: Modern.PokedexDemo.Service.Error, retry: () -> Void)?
|
||||
private(set) var isLoading: Bool = true {
|
||||
|
||||
willSet {
|
||||
|
||||
self.objectWillChange.send()
|
||||
}
|
||||
}
|
||||
|
||||
private(set) var lastError: (error: Modern.PokedexDemo.Service.Error, retry: () -> Void)? {
|
||||
|
||||
willSet {
|
||||
|
||||
self.objectWillChange.send()
|
||||
}
|
||||
}
|
||||
|
||||
init() {
|
||||
|
||||
@@ -49,7 +59,6 @@ extension Modern.PokedexDemo {
|
||||
.handleEvents(
|
||||
receiveSubscription: { [weak self] _ in
|
||||
|
||||
print("Fetching Pokedex Entries")
|
||||
guard let self = self else {
|
||||
|
||||
return
|
||||
@@ -61,7 +70,6 @@ extension Modern.PokedexDemo {
|
||||
.sink(
|
||||
receiveCompletion: { [weak self] completion in
|
||||
|
||||
print("Result (Fetching Pokedex Entries): \(completion)")
|
||||
guard let self = self else {
|
||||
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user