List views jittering in SwiftUI

情到浓时终转凉″ 提交于 2019-12-24 10:35:09

问题


I have a master detail view that navigates a series of sequential lists using totally vanilla SwiftUI and I'm noticing two things.

  1. The list rows width jitters when you access one via navigation link?
  2. The .navigationBarTitle isn't visible until the new view is completely on screen?

Seems like neither of these things are suppose to happen? Wonder if anyone has any ideas (video and code attached).

Video of the issues: https://www.dropbox.com/s/5jq3e8chay6hsy5/jitter.mov?dl=0

UserList.swift:

import SwiftUI

struct UserList: View {
    var body: some View {
        NavigationView {
            List(userData) { this in
                NavigationLink(destination: CityList(user: this, cities: this.cities)) {
                    UserRow(user: this)
                }

            }
            .navigationBarTitle(Text("Users"))
        }
    }
}

UserRow.swift:

import SwiftUI

struct UserRow: View {
    var user: UserModel
    var body: some View {
        VStack(alignment: .leading) {
            Text(user.firstName + " " + user.lastName)
                .font(.headline)
        }
    }
}

CityList.swift:

import SwiftUI

struct CityList: View {
    var user: UserModel
    var cities: [CityModel]

    var body: some View {
        List (cities) { this in
            NavigationLink(destination: TownList(city: this, towns: this.towns)) {
               CityRow(city: this)

            }.navigationBarTitle(Text(self.user.firstName + self.user.lastName))
        }
    }
}

CityRow.swift:

import SwiftUI

struct CityRow: View {
    var city: CityModel

    var body: some View {
        VStack(alignment: .leading) {
            Text(city.name)
                .font(.headline)
        }
    }
}

回答1:


Well third time's the charm, that's how they say.

The jittering is only on simulator, i had the same problem. Then i installed the app on a phone and it worked perfectly fine. Just ignore it on the simulator..

And the problem with the title is -as far as i know- also just a bug on the simulator, i don't have these issues on a phone.



来源:https://stackoverflow.com/questions/58652742/list-views-jittering-in-swiftui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!