Multiline Text
in a NavigationLink
inside of a List
does not seem to work.
Here is the code:
struct ContentView : View {
var body: some View {
List(1...5) { _ in
NavigationLink(destination: EmptyView()) {
Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")
.lineLimit(nil)
}
}
}
}
Removing the NavigationLink
, the Text
behaves as expected.
Is there a way to fix this, or is this a bug?
UPDATE
It seems Beta 5 has solved this bug!
Workaround for Beta 4 and previous versions:
It seems NavigationLink is "broken". But you can use DynamicNavigationDestinationLink instead. I know it's too verbose, but if you need a way out, here you have it. At least until NavigationLink works better.
struct ContentView: View {
var body: some View {
NavigationView {
TopView().navigationBarTitle(Text("Top View"))
}
}
}
struct TopView: View {
let detailView = DynamicNavigationDestinationLink(id: \String.self) { data in
DetailView(passedData: data)
}
var body: some View {
List(1...5) { i in
Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")
.lineLimit(nil)
.tapAction { self.detailView.presentedData?.value = "Detail for Row #\(i)" }
}
}
}
struct DetailView: View {
let passedData: String
var body: some View {
Text(passedData)
}
}
In the current XCode 13.1 Beta I still have an issue with this when the Text view is inside a container view. I could solve this giving the row (the container) a minimum height:
Text("blabla").lineLimit(2).frame(minHeight: 50)