Open chitgoks opened 2 years ago
The http request keeps on looping if i place this inside a TabView. What is the workaround for this? Please advise.
@chitgoks oh, i'm having the same problem. I think the root cause is adding task (or refreshable) to View. So, render view -> task call -> task finished -> render view -> .... and loops
public var body: some View {
AsyncResultView(
result: model.result,
reloadAction: { Task { await model.load() } },
content: content
)
.task {
await model.loadIfNeeded()
}
.refreshable {
await model.load()
}
}
public init(asyncOperation: AsyncOperation? = nil) {
if let asyncOperation {
asyncOperationBlock = asyncOperation
}
Task {
await load()
}
}
p/s: I'm happy if this package gets fixed, it's worth looking forward to
I actually got this to work. but seeing as im new to ios, my knowledge is limited.
I placed the AsyncView inside another container, say, a ZStack. Works good.
But i do not understand why.
I also tried as you said but it only solves the infinite loop problem. When i switch to another tab and come back again, api is called again and view will re-render and view's state not kept. Anyway congrats on solving your problem. ✌️✌️✌️
also us3d to have that problem. i guess inside your body is only the async view?
what i did was something like
if let obj then show ui else show asyncView block code
The http request keeps on looping if i place this inside a TabView. What is the workaround for this? Please advise.