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

[TIMOB-8373] iOS: TextFields and TextAreas should have a minimum height/width when they are SIZE and text is empty #1933

Merged
merged 3 commits into from
Apr 5, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 6 additions & 8 deletions iphone/Classes/TiUITextArea.m
Original file line number Diff line number Diff line change
Expand Up @@ -157,32 +157,30 @@ - (BOOL)textView:(UITextView *)tv shouldChangeTextInRange:(NSRange)range replace
#define TXT_OFFSET 20
-(CGFloat)contentWidthForWidth:(CGFloat)value
{
if (![self hasText]) {
return 0.0;
}
UITextView* ourView = (UITextView*)[self textWidgetView];
NSString* txt = ourView.text;
//sizeThatFits does not seem to work properly.
CGFloat txtWidth = [txt sizeWithFont:ourView.font constrainedToSize:CGSizeMake(value, 1E100) lineBreakMode:UILineBreakModeWordWrap].width;
if (value - txtWidth >= TXT_OFFSET) {
return (txtWidth + TXT_OFFSET);
}
return txtWidth;
return txtWidth + 2 * self.layer.borderWidth;
}

-(CGFloat)contentHeightForWidth:(CGFloat)value
{
if (![self hasText]) {
return 0.0;
}
CGFloat constrainedWidth = value - TXT_OFFSET;
if (constrainedWidth < 0) {
constrainedWidth = 0;
}
UITextView* ourView = (UITextView*)[self textWidgetView];
NSString* txt = ourView.text;
if (txt.length == 0) {
txt = @" ";
}
//sizeThatFits does not seem to work properly
return [txt sizeWithFont:ourView.font constrainedToSize:CGSizeMake(constrainedWidth, 1E100) lineBreakMode:UILineBreakModeWordWrap].height;
CGFloat txtHeight = [txt sizeWithFont:ourView.font constrainedToSize:CGSizeMake(constrainedWidth, 1E100) lineBreakMode:UILineBreakModeWordWrap].height;
return txtHeight + 2 * self.layer.borderWidth;
}

- (void)scrollViewDidScroll:(id)scrollView
Expand Down
6 changes: 0 additions & 6 deletions iphone/Classes/TiUITextField.m
Original file line number Diff line number Diff line change
Expand Up @@ -527,17 +527,11 @@ -(BOOL)textFieldShouldReturn:(UITextField *)tf

-(CGFloat)contentWidthForWidth:(CGFloat)value
{
if (![self hasText]) {
return 0.0;
}
return [[self textWidgetView] sizeThatFits:CGSizeMake(value, 0)].width;
}

-(CGFloat)contentHeightForWidth:(CGFloat)value
{
if (![self hasText]) {
return 0.0;
}
return [[self textWidgetView] sizeThatFits:CGSizeMake(value, 0)].height;
}

Expand Down
1 change: 1 addition & 0 deletions iphone/Classes/TiUITextWidgetProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ -(void)noteValueChange:(NSString *)newValue
{
if (![[self valueForKey:@"value"] isEqual:newValue])
{
[self contentsWillChange];
[self replaceValue:newValue forKey:@"value" notification:NO];
[self fireEvent:@"change" withObject:[NSDictionary dictionaryWithObject:newValue forKey:@"value"]];
}
Expand Down