fix for SR-13069

This commit is contained in:
John Estropia
2020-08-19 11:01:12 +09:00
parent d75029f54b
commit 5e536556da
4 changed files with 59 additions and 36 deletions

View File

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

View File

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

View File

@@ -76,10 +76,10 @@ extension FieldContainer {
*/
public init<Coder: FieldCoderType>(
wrappedValue initial: @autoclosure @escaping () -> V,
_ keyPath: KeyPathString,
_ keyPath: KeyPathString = { fatalError("'keyPath' argument required (SR-13069 workaround)") }(),
versionHashModifier: @autoclosure @escaping () -> String? = nil,
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
coder fieldCoderType: Coder.Type,
coder fieldCoderType: Coder.Type = { fatalError("'coder' argument required (SR-13069 workaround)") }(),
customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = []
@@ -150,10 +150,10 @@ extension FieldContainer {
*/
public init(
wrappedValue initial: @autoclosure @escaping () -> V,
_ keyPath: KeyPathString,
_ keyPath: KeyPathString = { fatalError("'keyPath' argument required (SR-13069 workaround)") }(),
versionHashModifier: @autoclosure @escaping () -> String? = nil,
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
coder: (encode: (V) -> Data?, decode: (Data?) -> V),
coder: (encode: (V) -> Data?, decode: (Data?) -> V) = { fatalError("'coder' argument required (SR-13069 workaround)") }(),
customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = []
@@ -478,10 +478,10 @@ extension FieldContainer.Coded where V: FieldOptionalType {
*/
public init<Coder: FieldCoderType>(
wrappedValue initial: @autoclosure @escaping () -> V = nil,
_ keyPath: KeyPathString,
_ keyPath: KeyPathString = { fatalError("'keyPath' argument required (SR-13069 workaround)") }(),
versionHashModifier: @autoclosure @escaping () -> String? = nil,
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
coder: Coder.Type,
coder: Coder.Type = { fatalError("'coder' argument required (SR-13069 workaround)") }(),
customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = []
@@ -552,10 +552,10 @@ extension FieldContainer.Coded where V: FieldOptionalType {
*/
public init(
wrappedValue initial: @autoclosure @escaping () -> V = nil,
_ keyPath: KeyPathString,
_ keyPath: KeyPathString = { fatalError("'keyPath' argument required (SR-13069 workaround)") }(),
versionHashModifier: @autoclosure @escaping () -> String? = nil,
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
coder: (encode: (V) -> Data?, decode: (Data?) -> V),
coder: (encode: (V) -> Data?, decode: (Data?) -> V) = { fatalError("'coder' argument required (SR-13069 workaround)") }(),
customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
customSetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>, _ newValue: V) -> Void)? = nil,
affectedByKeyPaths: @autoclosure @escaping () -> Set<KeyPathString> = []
@@ -625,7 +625,7 @@ extension FieldContainer.Coded where V: DefaultNSSecureCodable {
*/
public init(
wrappedValue initial: @autoclosure @escaping () -> V,
_ keyPath: KeyPathString,
_ keyPath: KeyPathString = { fatalError("'keyPath' argument required (SR-13069 workaround)") }(),
versionHashModifier: @autoclosure @escaping () -> String? = nil,
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
@@ -696,7 +696,7 @@ extension FieldContainer.Coded where V: FieldOptionalType, V.Wrapped: DefaultNSS
*/
public init(
wrappedValue initial: @autoclosure @escaping () -> V = nil,
_ keyPath: KeyPathString,
_ keyPath: KeyPathString = { fatalError("'keyPath' argument required (SR-13069 workaround)") }(),
versionHashModifier: @autoclosure @escaping () -> String? = nil,
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,

View File

@@ -69,7 +69,7 @@ extension FieldContainer {
*/
public init(
wrappedValue initial: @autoclosure @escaping () -> V,
_ keyPath: KeyPathString,
_ keyPath: KeyPathString = { fatalError("'keyPath' argument required (SR-13069 workaround)") }(),
versionHashModifier: @autoclosure @escaping () -> String? = nil,
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,
@@ -370,7 +370,7 @@ extension FieldContainer.Stored where V: FieldOptionalType {
*/
public init(
wrappedValue initial: @autoclosure @escaping () -> V = nil,
_ keyPath: KeyPathString,
_ keyPath: KeyPathString = { fatalError("'keyPath' argument required (SR-13069 workaround)") }(),
versionHashModifier: @autoclosure @escaping () -> String? = nil,
previousVersionKeyPath: @autoclosure @escaping () -> String? = nil,
customGetter: ((_ object: ObjectProxy<O>, _ field: ObjectProxy<O>.FieldProxy<V>) -> V)? = nil,