New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't render multiline text in CocoaList #215
Comments
I'll check out this bug! SwiftUI unfortunately exposes very little in terms of layout priorities or sizing preferences when writing [UI/NS]ViewRepresentable(s), so fixing this may be impossible to do in a generic fashion. But I will try nonetheless! :) |
Closing this issue for now as I'm not able to reproduce it, could be a SwiftUI hosting controller bug. Could you upload a full sample project if it still persists? Feel free to reopen with the sample project. |
Sorry. I didn't check the reply and forgot about it. This is the demo code. import SwiftUI
import SwiftUIX
fileprivate struct Item: Identifiable {
var id: UUID = UUID()
var text: String {
String(repeating: "A very very long text. ", count: 10)
}
}
struct TestView: View {
@State var index = 1
@State fileprivate var items = [Item]()
var body: some View {
List(items) {
item in
Text(String(repeating: "\(item.text) ", count: 3))
.fixedSize(horizontal: false, vertical: true)
}
.onAppear {
for _ in 0 ..< 2 {
items.append(Item())
}
}
}
}
struct TestView2: View {
@State var index = 1
@State fileprivate var items = [Item]()
var body: some View {
CocoaList(items) { item in
Text(String(repeating: "\(item.text) ", count: 3))
.fixedSize(horizontal: false, vertical: true)
}
.onAppear {
for _ in 0 ..< 2 {
items.append(Item())
}
}
}
}
struct TestView_Previews: PreviewProvider {
static var previews: some View {
ZStack {
TestView()
}.ignoresSafeArea(.all, edges: .bottom)
ZStack {
TestView2()
}.ignoresSafeArea(.all, edges: .bottom)
}
}
|
And, my xCode version is 12.5, complied target is iOS14.0, complied on macOS 11.3.1. |
@vmanot I try to change target to iOS 14.5, same as before |
@Innei The fixedSize approach is wrong in my opinion. @vmanot try this code, it's shorter and better to understand the issue:
If I had to guess the problem stems from there:
I have no idea how to fix this. |
@Innei a possible workaround would be to get the available space with a geometry reader and tell the Text his maximum frame size:
I hope that @vmanot can find a proper fix, but in the meantime this issue should be re-opened |
@MarcoCount thanks, I'll take a look into this.
Multiple layout passes are hard to balance with the performance costs, and unfortunately SwiftUI doesn't give me access to a whole host of methods that are used internally for calculating sizes in a more performant manner. Ideally, I wouldn't even be using |
Yes, I perfectly understand. |
Closing as I'm officially marking this out of scope for |
Hi, guys. I want to render a very very long text in CocoaList. But it only render one line and text is clipped with
...
. I find a solution, that add.fixedSize(horizontal: false, vertical: true)
onText
, it's working on SwiftUI nativeList
. But not work onCocoaList
.Just like this.
On top of view is
CocoaList
, bottom of view isList
.There is my test code.
The text was updated successfully, but these errors were encountered: