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

Recalculate typing attributes on alignment update #1228

Merged
merged 2 commits into from
Oct 23, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Aztec/Classes/TextKit/TextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,12 @@ open class TextView: UITextView {
}
}

override open var textAlignment: NSTextAlignment {
didSet {
recalculateTypingAttributes()
Copy link
Contributor

@SergioEstevao SergioEstevao Oct 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sugest we had a check like this:

if oldValue != textAlignment {
  recalculateTypingAttributes()
}

Just to avoid unnecessary re-renders

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch @SergioEstevao ! I made the update and it works great.

I was curious how large of a difference this would make, so I did some logging and I was surprised that the alignment prop actually isn't getting passed in as often as I expected. For example, I expected that changing the formatting of text (bold, italic, etc.) in an aligned paragraph would resend the alignment attribute to the native view, but it didn't. This is still definitely a good change because there were certainly some unnecessary calls to recalculateTypingAttributes() with my original implementation. I was just surprised that it wasn't an even more important fix.

}
}


/// This property returns the Attributes associated to the Extra Line Fragment.
///
Expand Down