-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add rx.attributedText to UITextView and UITextField #1249
Conversation
Generated by 🚫 Danger |
RxCocoa/iOS/UITextView+Rx.swift
Outdated
// when IME input method is used. | ||
if textView.attributedText != attributedText { | ||
print(textView.attributedText) | ||
print(attributedText) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these are accidental print
s.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed in las commit
RxCocoa/iOS/UITextView+Rx.swift
Outdated
.observeOn(MainScheduler.asyncInstance) | ||
.map { _ in | ||
guard let textStorage = textView?.textStorage else { return nil } | ||
return textStorage.attributedSubstring(from: NSRange(location: 0, length: textStorage.string.utf8.count)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what is the length here. Why do you think it's textStorage.string.utf8.count
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In last commit is changed to NSRange(location: 0, length: textStorage.length)
the full range
RxCocoa/iOS/UITextField+Rx.swift
Outdated
/// Bindable sink for `attributedText` property. | ||
public var attributedText: UIBindingObserver<Base, NSAttributedString?> { | ||
return UIBindingObserver(UIElement: self.base) { textField, attributedText in | ||
textField.attributedText = attributedText |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to find way to make sure this isn't updated in case attributed text is the same and test this.
if textField.attributedText != attributedText {
textField.attributedText = attributedText
}
We had issues with IME.
// This check is important because setting text value always clears control state
// including marked text selection which is imporant for proper input
// when IME input method is used.
XCTAssertTrue(textField.settedText) | ||
} | ||
|
||
func testLabel_attributedTextObserver() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is copied code from UILabel
, but nothing is updated, it doesn't test UITextField
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in last commit
} | ||
} | ||
|
||
final class UITextFieldSubclass : UITextField { | ||
var set: Bool = false | ||
|
||
var settedText = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think maybe didSetText
would be more descriptive.
var set: Bool = false | ||
|
||
var settedText = false | ||
var settedAttributedText = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same like for UITextField
. This should probably be didSetText
and didSetAttributedText
.
I think now is correct.
|
Yeah, we can do this in a separate PR. |
XCTAssertTrue(textField.isSettedText) | ||
} | ||
|
||
func testLabel_attributedTextObserver() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test title says testLabel
. It should probably be just test
because there is no label that we are testing inside this test.
textField.text = "Text1" | ||
textField.set = false | ||
textField.isSettedText = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think isSettedText
is formulated correctly. Maybe use didSetText
.
var textFieldAttributedString: NSAttributedString { | ||
let tf = UITextField() | ||
tf.attributedText = NSAttributedString(string: self) | ||
return tf.attributedText! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this code. UITextField
is being created and then discarded immediately.
Is there something wrong with just using NSAttributedText(string: "Hello!")
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The NSAttributedText(string: "Hello!")
style can't have style info. When we set this to a Textfield or Textview, they overwrite its internal NSAttributedString properties in the case only text, then, if we get the control's attributedStyle
is not equal to the setted. So this function returns and NSAttributedText
with all properties with effect in these controls being it comparable with getted style from control.
override var text: String? { | ||
get { | ||
return super.text | ||
} | ||
set { | ||
set = true | ||
isSettedText = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has the same grammar issue.
var textViewAttributedString: NSAttributedString { | ||
let tf = UITextView() | ||
tf.attributedText = NSAttributedString(string: self) | ||
return tf.attributedText! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same problem with redundant extension.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same explanation than TextField case
|
||
final class UITextViewSubclass2 : UITextView { | ||
var isSettedText = false | ||
var isSettedAttributedText = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has the same grammar issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. I think some of the previous comments weren't addressed, and there are some new ones.
RxCocoa/iOS/UITextField+Rx.swift
Outdated
/// Bindable sink for `attributedText` property. | ||
public var attributedText: UIBindingObserver<Base, NSAttributedString?> { | ||
return UIBindingObserver(UIElement: self.base) { textField, attributedText in | ||
if textField.attributedText != attributedText { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. Why do we need this check?
9147175
to
bd3e2d5
Compare
9dfb3e6
to
d2ccc22
Compare
d2ccc22
to
981b98a
Compare
Requested in issue #1246