Working fine in iOS not in Android
GaneshRajuGalla opened this issue · comments
I'm encountering a peculiar issue where I've implemented an API and successfully populated a list with it. Everything runs smoothly without errors on iOS. However, on Android, it doesn't display anything, and I'm having difficulty understanding what might be missing.
if am using local data it was working only remote data not showing in android
i am posting code where I am facing
// ContentView
struct ContentView: View {
@StateObject var viewModel = ViewModel()
var body: some View {
NavigationStack {
List(viewModel.repos, id: \.id) { repo in
NavigationLink(value: repo) {
listRow(repo: repo)
}
}
.navigationDestination(for: Repo.self, destination: { repo in
RepoDetailView(owner: repo.owner)
})
.navigationTitle("Repos")
.task {
await viewModel.fetchRepose()
}
}
}
}
Please do let me know what I am missing
Can you share what the transpiled code look like for android?
or you can use this playground to transpile the code
@akashkahalkar thankyou for respose
Here it is my transpiled code
package skip.collab
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.Saver
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import skip.foundation.*
import skip.lib.*
import skip.model.*
import skip.ui.*
internal class ContentView: View {
internal var viewModel: ViewModel
get() = _viewModel.wrappedValue
set(newValue) {
_viewModel.wrappedValue = newValue
}
internal var _viewModel: skip.ui.State<ViewModel>
override fun body(): View {
return ComposeView { composectx: ComposeContext ->
NavigationStack {
ComposeView { composectx: ComposeContext ->
List(viewModel.repos, id = { it.id }) { repo ->
ComposeView { composectx: ComposeContext ->
NavigationLink(value = repo) {
ComposeView { composectx: ComposeContext ->
listRow(repo = repo).Compose(composectx)
ComposeResult.ok
}
}.Compose(composectx)
ComposeResult.ok
}
}
.navigationDestination(for_ = Repo::class, destination = { repo ->
ComposeView { composectx: ComposeContext ->
RepoDetailView(owner = repo.owner).Compose(composectx)
ComposeResult.ok
}
})
.navigationTitle("Repos")
.task { MainActor.run { viewModel.fetchRepose() } }.Compose(composectx)
ComposeResult.ok
}
}.Compose(composectx)
}
}
@Composable
@Suppress("UNCHECKED_CAST")
override fun ComposeContent(composectx: ComposeContext) {
val initialviewModel = _viewModel.wrappedValue
var composeviewModel by rememberSaveable(stateSaver = composectx.stateSaver as Saver<ViewModel, Any>) { mutableStateOf(initialviewModel) }
_viewModel.sync(composeviewModel, { composeviewModel = it })
body().Compose(composectx)
}
private fun listRow(repo: Repo): View {
return Label(title = {
ComposeView { composectx: ComposeContext ->
Text(repo.repoName ?: "").Compose(composectx)
ComposeResult.ok
}
}, icon = {
ComposeView { composectx: ComposeContext ->
AsyncImage(url = URL(string = repo.owner?.avatarURL ?: ""), content = { image ->
ComposeView { composectx: ComposeContext ->
image
.resizable()
.frame(width = 32.0, height = 32.0).Compose(composectx)
ComposeResult.ok
}
}, placeholder = {
ComposeView { composectx: ComposeContext ->
// ProgressView()
ComposeResult.ok
}
}).Compose(composectx)
ComposeResult.ok
}
})
}
constructor(viewModel: ViewModel = ViewModel()) {
this._viewModel = skip.ui.State(viewModel)
}
}
Same issue here, Android does not display the remote data :(
Please Let me know if you found any solution for it
The SwiftUI List
looks OK to me. Have you tested with locally mocked data? I.e., is it a question of the list not showing anything, or is it possible that the data is not being fetched and updated correctly on the Android side? Is ViewModel.repos
a @Published
property? Using OSLog.Logger in the app and watching the output with adb logcat
can help track the lifecycle of the requests.
I'll close this for now since we think the List should be working, but feel free to re-open it if you have more information about the issue.