Skip to content

Commit

Permalink
feat(ios): textarea contentHeight fix with new return property textar…
Browse files Browse the repository at this point in the history
…eaHeight in "change" event (#13416)

* fix(ios): textarea contentHeight fix with new event for contentChange

* fix(ios): textarea contentHeight fix

* fix(ios): textarea contentHeight update for doc

* Update TextArea.yml

* fix(ios): textarea contentHeight fix with new return property textareaHeight in "change" event

Fixes #13413

* Update TextArea.yml

* Update TextArea.yml

* Update TextArea.yml

* Update TextArea.yml

* Update TiUITextWidgetProxy.m

event property changed to better "contentHeight"

* Update TextArea.yml

* Update TiUITextArea.m

removed unused variable
  • Loading branch information
mbender74 committed Apr 22, 2022
1 parent 5c01a8d commit 94820d1
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
5 changes: 5 additions & 0 deletions apidoc/Titanium/UI/TextArea.yml
Expand Up @@ -518,6 +518,11 @@ events:
- name: value
summary: New value of this text area.
type: String
- name: contentHeight
summary: Content height value of this text area
type: Number
platforms: [iphone, ipad, macos]
since: {iphone: "10.2.0", ipad: "10.2.0", macos: "10.2.0"}

- name: focus
summary: Fired when this text area gains focus.
Expand Down
4 changes: 3 additions & 1 deletion iphone/Classes/TiUITextArea.m
Expand Up @@ -337,7 +337,9 @@ - (void)textViewDidEndEditing:(UITextView *)tv

- (void)textViewDidChange:(UITextView *)tv
{
[(TiUITextAreaProxy *)[self proxy] noteValueChange:[(UITextView *)textWidgetView text]];
NSNumber *textareaHeight = [NSNumber numberWithFloat:tv.contentSize.height];

[(TiUITextAreaProxy *)[self proxy] noteValueChange:[(UITextView *)textWidgetView text]:textareaHeight];
}

- (void)textViewDidChangeSelection:(UITextView *)tv
Expand Down
4 changes: 2 additions & 2 deletions iphone/Classes/TiUITextField.m
Expand Up @@ -553,7 +553,7 @@ - (void)textFieldDidChange:(NSNotification *)notification
if ([ourProxy suppressFocusEvents]) {
return;
}
[ourProxy noteValueChange:[(UITextField *)textWidgetView text]];
[ourProxy noteValueChange:[(UITextField *)textWidgetView text]:nil];
}

- (BOOL)textFieldShouldEndEditing:(UITextField *)tf
Expand All @@ -564,7 +564,7 @@ - (BOOL)textFieldShouldEndEditing:(UITextField *)tf
- (BOOL)textFieldShouldClear:(UITextField *)tf
{
// we notify proxy so he can serialize in the model
[(TiUITextFieldProxy *)self.proxy noteValueChange:@""];
[(TiUITextFieldProxy *)self.proxy noteValueChange:@"":nil];
return YES;
}

Expand Down
2 changes: 1 addition & 1 deletion iphone/Classes/TiUITextWidget.m
Expand Up @@ -58,7 +58,7 @@ - (void)setValue_:(id)value
string = [string substringToIndex:maxLength];
}
[(id)[self textWidgetView] setText:string];
[(TiUITextWidgetProxy *)[self proxy] noteValueChange:string];
[(TiUITextWidgetProxy *)[self proxy] noteValueChange:string:nil];
}

- (void)setMaxLength_:(id)value
Expand Down
2 changes: 1 addition & 1 deletion iphone/Classes/TiUITextWidgetProxy.h
Expand Up @@ -26,7 +26,7 @@
}

//Internal values
- (void)noteValueChange:(NSString *)newValue;
- (void)noteValueChange:(NSString *)newValue:(NSNumber *)contentHeight;

@property (nonatomic, readwrite, assign) BOOL suppressFocusEvents;
// workaround bridge layer issue clashing with focused:(id)unused method
Expand Down
13 changes: 11 additions & 2 deletions iphone/Classes/TiUITextWidgetProxy.m
Expand Up @@ -118,13 +118,22 @@ - (BOOL)focused:(id)unused
return result;
}

- (void)noteValueChange:(NSString *)newValue
- (void)noteValueChange:(NSString *)newValue:(NSNumber *)contentHeight
{
NSString *oldValue = [TiUtils stringValue:[self valueForKey:@"value"]];
if (![oldValue isEqual:newValue]) {
[self replaceValue:newValue forKey:@"value" notification:NO];

NSMutableDictionary *event = [NSMutableDictionary dictionary];
if (contentHeight != nil) {
[event setValue:contentHeight forKey:@"contentHeight"];
}
[event setValue:newValue forKey:@"value"];
if ([self _hasListeners:@"change"]) {
[self fireEvent:@"change" withObject:event];
}

[self contentsWillChange];
[self fireEvent:@"change" withObject:[NSDictionary dictionaryWithObject:newValue forKey:@"value"]];
TiThreadPerformOnMainThread(
^{
//Make sure the text widget is in view when editing.
Expand Down

0 comments on commit 94820d1

Please sign in to comment.