Skip to content
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

LayoutConstraints issue #126

Open
writing-shed opened this issue Aug 8, 2021 · 3 comments
Open

LayoutConstraints issue #126

writing-shed opened this issue Aug 8, 2021 · 3 comments

Comments

@writing-shed
Copy link

writing-shed commented Aug 8, 2021

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)>

@rajdeep
Copy link
Owner

rajdeep commented Aug 10, 2021

@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.

@bryan1anderson
Copy link
Contributor

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

@rajdeep
Copy link
Owner

rajdeep commented Feb 15, 2023

@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: #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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants