proton icon indicating copy to clipboard operation
proton copied to clipboard

LayoutConstraints issue

Open writing-shed opened this issue 4 years ago • 3 comments

My app embeds an EditorView in a SwiftUI UIViewRepresentable struct which is the documented way to use UIKit views. The problem is that the text does not scroll when it reaches the bottom of the view. However, if I close the view and reopen it things wok as expected.

I have found that AutogrowingTextView.LayoutSubviews is only called once when the view opens, so isScrollEnabled is left set to false. Closing and reopening the view sorts this because there is sufficient text available.

The problem seems to be the layoutConstraints because the console contains the following immediately after EditorView.setup is called.

I can overcome the issue by setting isScrollEnabled after every keystroke.

2021-08-08 10:15:17.067778+0100 Easiwriter[3611:91422] [LayoutConstraints] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) ( "<NSAutoresizingMaskLayoutConstraint:0x60000243ae40 h=--& v=--& Proton.EditorView:0x7fb90d839800.height == 759.333 (active)>", "<NSLayoutConstraint:0x60000240ecb0 V:|-(0)-[Proton.RichTextView:0x7fb90d0b4800] (active, names: '|':Proton.EditorView:0x7fb90d839800 )>", "<NSLayoutConstraint:0x60000240eb70 Proton.RichTextView:0x7fb90d0b4800.bottom == Proton.EditorView:0x7fb90d839800.bottom (active)>", "<NSLayoutConstraint:0x600002409ae0 Proton.RichTextView:0x7fb90d0b4800.height >= 926 (active)>" )

Will attempt to recover by breaking constraint <NSLayoutConstraint:0x600002409ae0 Proton.RichTextView:0x7fb90d0b4800.height >= 926 (active)>

writing-shed avatar Aug 08 '21 09:08 writing-shed

@writing-shed, thanks for reporting the issue. I have not yet got a chance to look into using Proton with SwiftUI. However, I do plan to try it out and making Proton have more compatible API. However, that might not be soon enough as there are some other improvements that I am focussing on in Proton.

Having said that, to provide a bit more context on how scrolling works in AutogrowingTextView, and isScrollEnabled get enabled: this is managed via layoutSubviews in AutogrowingTextView. When the text reaches the point where it is overflowing the size available in the TextView, framework invokes layoutSubview, and that's where the logic is to enable scroll is implemented. It is possible that with SwiftUI, not all the framework events are getting invoked/ or may need additional workaround for it to work. When I do get the opportunity to try it out in SwiftUI, I'll review the code and see if the issue you have identified, helps resolve the problem.

rajdeep avatar Aug 10 '21 08:08 rajdeep

I have this same problem. Causing quite the headache. @rajdeep I'm getting fairly advanced in my SwiftUI usage. I would be happy to collaborate and try and get this as supported in SwiftUI as possible. Having used Proton for about a year now, I have some ideas. Please reach out if you'd be interested

bryan1anderson avatar Feb 15 '23 20:02 bryan1anderson

@bryan1anderson, it would be great to collaborate, and I would love to hear about your experience and suggestions. We can discuss the ideas related to SwiftUI here: https://github.com/rajdeep/proton/discussions/83

Regarding this issue, I have not been able to look much into SwiftUI support as yet. Having said that, I wanted to optimise the performance part of Proton before looking into the SwiftUI support. I have a branch where significant changes have been made, including to the autolayout constraints. Have a look at this branch: https://github.com/rajdeep/proton/tree/performance-update-2

rajdeep avatar Feb 15 '23 20:02 rajdeep