From 94820d1952d5e301b6ea2741576b3046b5b382b5 Mon Sep 17 00:00:00 2001 From: Marc Bender <79178770+mbender74@users.noreply.github.com> Date: Fri, 22 Apr 2022 17:09:16 +0200 Subject: [PATCH] feat(ios): textarea contentHeight fix with new return property textareaHeight 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 --- apidoc/Titanium/UI/TextArea.yml | 5 +++++ iphone/Classes/TiUITextArea.m | 4 +++- iphone/Classes/TiUITextField.m | 4 ++-- iphone/Classes/TiUITextWidget.m | 2 +- iphone/Classes/TiUITextWidgetProxy.h | 2 +- iphone/Classes/TiUITextWidgetProxy.m | 13 +++++++++++-- 6 files changed, 23 insertions(+), 7 deletions(-) diff --git a/apidoc/Titanium/UI/TextArea.yml b/apidoc/Titanium/UI/TextArea.yml index 9f47e850f78..d587d4a1ba2 100644 --- a/apidoc/Titanium/UI/TextArea.yml +++ b/apidoc/Titanium/UI/TextArea.yml @@ -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. diff --git a/iphone/Classes/TiUITextArea.m b/iphone/Classes/TiUITextArea.m index 39ac15b04ad..4d02ae01a48 100644 --- a/iphone/Classes/TiUITextArea.m +++ b/iphone/Classes/TiUITextArea.m @@ -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 diff --git a/iphone/Classes/TiUITextField.m b/iphone/Classes/TiUITextField.m index c1ac4be0778..23b4c8de905 100644 --- a/iphone/Classes/TiUITextField.m +++ b/iphone/Classes/TiUITextField.m @@ -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 @@ -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; } diff --git a/iphone/Classes/TiUITextWidget.m b/iphone/Classes/TiUITextWidget.m index b911a7f5ffc..26562992bd7 100644 --- a/iphone/Classes/TiUITextWidget.m +++ b/iphone/Classes/TiUITextWidget.m @@ -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 diff --git a/iphone/Classes/TiUITextWidgetProxy.h b/iphone/Classes/TiUITextWidgetProxy.h index e99de0928a7..03ae9660188 100644 --- a/iphone/Classes/TiUITextWidgetProxy.h +++ b/iphone/Classes/TiUITextWidgetProxy.h @@ -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 diff --git a/iphone/Classes/TiUITextWidgetProxy.m b/iphone/Classes/TiUITextWidgetProxy.m index c0d0b44dc9e..97ef4342925 100644 --- a/iphone/Classes/TiUITextWidgetProxy.m +++ b/iphone/Classes/TiUITextWidgetProxy.m @@ -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.