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

[ORKTextField] Coherent placeholder handling #445

Conversation

rsanchezsaez
Copy link
Contributor

This PR makes the handing of the placeholder in ORKTextField more similar to what UITextField does.

It comprises of two changes:

  • Remove extra spacing between unit number and placeholder text. This makes the space between the unit and the placeholder to be consistent between editing and non editing modes.
  • Do not hide placeholder when the editing text is empty (same as with UITextField).

Also reuses form item cells in ORKStepViewController so cells are not created twice when calculating their height.


Before:

simulator screen shot 9 sep 2015 02 46 13
simulator screen shot 9 sep 2015 02 59 19
simulator screen shot 9 sep 2015 02 46 20


After:

simulator screen shot 9 sep 2015 03 05 42
simulator screen shot 9 sep 2015 03 05 47
simulator screen shot 9 sep 2015 03 05 53

@umerkhan-apple
Copy link
Member

Did we want to extend this same functionality to the multiline textfields? For example, check out the Message form item under Mini Form in ORKTest.

@rsanchezsaez
Copy link
Contributor Author

@umerkhan-apple: I'll look into this in the following days.

@umerkhan-apple
Copy link
Member

@rsanchezsaez So did you get a chance to look at multiline textfields? Do we want to extend this functionality to them, or should we just leave it to single line textfields?

@rsanchezsaez
Copy link
Contributor Author

Hey Umer,

Sorry, I missed the GitHub notification earlier.

I agree that the placeholder on text views (multiline text fields) should behave like the text field one. I'm looking into this.

@rsanchezsaez
Copy link
Contributor Author

@umerkhan-apple: Done, I have implemented the same placeholder behavior for ORKAnswerTextView.

@umerkhan-apple
Copy link
Member

@rsanchezsaez Awesome, I will test the changes shortly.

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(updateAppearance)
name:UIContentSizeCategoryDidChangeNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textViewTextDidChange:)
Copy link
Member

Choose a reason for hiding this comment

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

Move selector argument onto a new line just to stay consistent.

@rsanchezsaez
Copy link
Contributor Author

Adding the placeholder to the ORKAnswerTextView was tricky.

First, I tried using a plain UILabel but getting the positioning to be coherent with the typed in text was not easy.

So I settled to adding a non-interactive UITextView as a child of ORKAnswerTextView. For this to layout correctly on form steps, I needed to both set the frame manually (on layout subviews) and add constraints. I find this very weird because normally you either set the frame or use constraints, but never both. Removing one or the other makes it to stop being laid out correctly. If you have a suggestion for cleanest implementation, I'm all ears.


[self updateAppearance];
}

- (void)layoutSubviews {
[super layoutSubviews];
// Setting the frame directly causes a layout error on a form step (it looks like an iOS bug, as setting the frame should produce the same effect as settings the bounds and the center)
Copy link
Member

Choose a reason for hiding this comment

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

Typo: settings -> setting

@umerkhan-apple
Copy link
Member

@rsanchezsaez I agree that this is a bit of a tricky implementation. I will look into finding a cleaner approach if possible.

Currently, the framework is crashing if I change orientation from Portrait to Landscape inside ORKTest running Mini Form task.

Console log

2015-10-20 11:16:55.377 ORKTest[614:106204] -[NSIndexPath setExpectedLayoutWidth:]: unrecognized selector sent to instance 0x175dfda0

Tested on iPhone 5 and iPhone 6S.

@rsanchezsaez
Copy link
Contributor Author

I've fixed the crash, that was an unrelated silly mistake on my end.

Let me know if you come up with an alternate solution for the text view placeholder.

@YuanZhu-apple
Copy link
Member

screen shot 2015-10-21 at 2 54 21 pm

Not form your code, I just noticed the textview is misaligned in formStep.
Can you fix it in this PR? Thanks!

@@ -185,7 +184,7 @@ - (void)ork_setSuffix:(NSString *)suffix withColor:(UIColor *)color {
if (suffix.length == 0) {
return;
}
_suffixLabel = [self ork_createTextLabelWithTextColor:color ?: [UIColor grayColor]];
_suffixLabel = [self ork_createTextLabelWithTextColor:(color ?: [UIColor ork_midGrayTintColor])];
Copy link
Member

Choose a reason for hiding this comment

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

Intention of this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This color is sometimes used for the unit suffix label when editing an empty ORKTextFieldView with no placeholder. You can see this if you revert this change, tap on the first text field of the first step on Mini Form, tap on the second field, and then tap on the first field again (the unit suffix label turns darker).

ork_midGrayTintColor is used as the color in all other placeholders and unit suffix instances, so I figured it should be used here too.

But maybe we should also review the actual color-chosing logic, because it's weird that this color only gets used the second time you tap on the field but not the first one.

@rsanchezsaez
Copy link
Contributor Author

I'll later look into the alignment of the text view.

@umerkhan-apple
Copy link
Member

@rsanchezsaez After internal discussion, we have come to the following conclusion:

  • When there is a unit specified on the text field, keep the behavior as it is in current RK.
  • When there is no unit specified (basically, when it is functioning like a basic uitextfield) then show the placeholder until editing begins to stay consistent with iOS's uitextfield (your PR's implementation).

@rsanchezsaez
Copy link
Contributor Author

Ok. But why do that for first the case? Don't you think keeping the placeholder until some text is typed is more coherent and consistent?

@umerkhan-apple
Copy link
Member

The main reason for that conclusion was that having two placeholders seemed untidy and slightly confusing for the user.

@rsanchezsaez
Copy link
Contributor Author

But, in my opinion, the user perception is that, when editing an empty unit-suffixed text field, the unit label becomes part of the placeholder text and then, when they start typing, the "long placeholder" transforms to show only the unit suffix. I think this worked well after reducing the placeholder <> unit separation (see the before/after screenshots above). Don't you think?

If you remain unconvinced let me know and I'll update it to the behavior you requested. :)

@YuanZhu-apple
Copy link
Member

@rsanchezsaez I think the original set a more clear distinction between placeholder and unit string, see the margin between them when the textfield is inactive.

And when the textfield become active, showing both of them makes the field a little noisy.

[Original]
screen shot 2015-10-21 at 3 30 19 pm
screen shot 2015-10-21 at 3 24 48 pm

[This PR]
screen shot 2015-10-21 at 3 32 20 pm
screen shot 2015-10-21 at 3 15 17 pm

…ing extra unneeded padding between the placeholder and the unit
…eholder

# Conflicts:
#	ResearchKit/Common/ORKTextFieldView.m
To reproduce, tap on an empty field with unit label and no placeholder (first form item of first step in ORKTest's Miniform).
…ldView

This creates a non-interactive 'UITextView' for displaying the placeholder at the exact same position as the 'ORKAnswerTextView' text.

It improves encapsulation, the 'ORKAnswerTextView' class handles the placeholder internally.

Also: some minor naming convention improvenets in 'ORKTextFieldView'.
…ld empty without triggering answer validity checking

This fixes a regression. It restores the behavior in which you are allowed to edit a different text field in a form if you leave the current text field blank. E.g., on ORKTest's 'Mini Form', tapping on the first cell text field and then tapping on second cell text field without having written anything should not trigger the alert.
@rsanchezsaez rsanchezsaez force-pushed the rsanchezsaez-HomogenousORKTextFieldView branch from 99047fe to 2289abf Compare January 4, 2016 23:32
@rsanchezsaez
Copy link
Contributor Author

I have updated this PR against the latest master, with the requested behavior:

  • When there is a suffix unit specified on the text field, keep the behavior as it was.
  • When there is no suffix unit specified, show the placeholder until the user writes text, to stay consistent with iOS's UITextField.

I also fixed a regression in which the user was being prevented leaving a form text field blank (a validation alert was being shown, you can try in ORKTest's Mini Form by editing the first field and trying to move to the second without typing anything).

Let me know if you want additional changes. I think the animation glitch and the suffix color mismatch fixes are worthwhile improvements as well.

The text frame sometimes animated from left to right (e.g., in ORKTest's MiniForm, tap 4th text field, type any number and tap any other text field).
Also remove needless period on latest placeholder text.
@rsanchezsaez
Copy link
Contributor Author

Also, the TextView misalign shown in the above comment screenshot no longer seems to be an issue. Maybe iOS 9.2 fixed it? I don't see any RK code change related to that. Please let me know if this is still a problem.

@YuanZhu-apple
Copy link
Member

R=ME:) @umerkhan-apple Can you take a look as well?

@YuanZhu-apple
Copy link
Member

@umerkhan-apple Get a chance to try this?

@rsanchezsaez rsanchezsaez changed the title Coherent 'ORKTextField' placeholder handling [ORKTextField] Coherent placeholder handling Jan 16, 2016
@rsanchezsaez
Copy link
Contributor Author

@umerkhan-apple Ping? ;-)

YuanZhu-apple added a commit that referenced this pull request Mar 16, 2016
…extFieldView

[ORKTextField] Coherent placeholder handling
@YuanZhu-apple YuanZhu-apple merged commit 9f5caad into ResearchKit:master Mar 16, 2016
@rsanchezsaez rsanchezsaez deleted the rsanchezsaez-HomogenousORKTextFieldView branch March 17, 2016 15:48
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

Successfully merging this pull request may close these issues.

None yet

3 participants