From 34e1f5ae024e05cd555e8aaf0e5a4a8d5ef3f4a1 Mon Sep 17 00:00:00 2001 From: wwwcg Date: Wed, 26 Jun 2024 19:40:44 +0800 Subject: [PATCH] fix(ios): responsable region issue of Textinput (#3932) * fix(ios): responsable region issue of Textinput * chore(ios): remove unused code in TextView --- .../component/textinput/HippyTextField.h | 2 -- .../component/textinput/HippyTextField.m | 7 ----- .../component/textinput/HippyTextView.h | 1 - .../component/textinput/HippyTextView.mm | 28 ++++++++----------- 4 files changed, 11 insertions(+), 27 deletions(-) diff --git a/renderer/native/ios/renderer/component/textinput/HippyTextField.h b/renderer/native/ios/renderer/component/textinput/HippyTextField.h index 2766e869aed..0b61e7c9f82 100644 --- a/renderer/native/ios/renderer/component/textinput/HippyTextField.h +++ b/renderer/native/ios/renderer/component/textinput/HippyTextField.h @@ -43,7 +43,6 @@ @interface HippyTextField : HippyBaseTextInput @property (nonatomic, copy) HippyDirectEventBlock onKeyPress; @property (nonatomic, assign) BOOL autoCorrect; -//@property (nonatomic, assign) UIEdgeInsets contentInset; @property (nonatomic, strong) UIColor *placeholderTextColor; @property (nonatomic, strong) NSString *placeholder; @property (nonatomic, strong) NSNumber *maxLength; @@ -62,7 +61,6 @@ @property (nonatomic, copy) HippyDirectEventBlock onKeyboardWillHide; @property (nonatomic, copy) NSString *value; -@property (nonatomic, strong) NSNumber *fontSize; @property (nonatomic, strong) NSString *defaultValue; @property (nonatomic, copy) NSString *text; @property (nonatomic, strong) UIColor *textColor; diff --git a/renderer/native/ios/renderer/component/textinput/HippyTextField.m b/renderer/native/ios/renderer/component/textinput/HippyTextField.m index ef69c22806f..10137be9b6d 100644 --- a/renderer/native/ios/renderer/component/textinput/HippyTextField.m +++ b/renderer/native/ios/renderer/component/textinput/HippyTextField.m @@ -359,13 +359,6 @@ - (void)setText:(NSString *)text { _text = text; } -- (void)setFontSize:(NSNumber *)fontSize { - _fontSize = fontSize; - if ([fontSize floatValue] > 0) { - [_textView setFont:[UIFont systemFontOfSize:[fontSize floatValue]]]; - } -} - - (void)setValue:(NSString *)value { [_textView setText:value]; } diff --git a/renderer/native/ios/renderer/component/textinput/HippyTextView.h b/renderer/native/ios/renderer/component/textinput/HippyTextView.h index 4eebb1e6f1b..2a48201b8e8 100644 --- a/renderer/native/ios/renderer/component/textinput/HippyTextView.h +++ b/renderer/native/ios/renderer/component/textinput/HippyTextView.h @@ -60,7 +60,6 @@ - (void)performTextUpdate; @property (nonatomic, copy) NSString *value; -@property (nonatomic, strong) NSNumber *fontSize; @property (nonatomic, strong) NSString *defaultValue; @property (nonatomic, strong) UIColor *textColor; diff --git a/renderer/native/ios/renderer/component/textinput/HippyTextView.mm b/renderer/native/ios/renderer/component/textinput/HippyTextView.mm index de672c4cc3b..eb13261d753 100644 --- a/renderer/native/ios/renderer/component/textinput/HippyTextView.mm +++ b/renderer/native/ios/renderer/component/textinput/HippyTextView.mm @@ -282,21 +282,23 @@ - (void)updateFrames { } - (void)updateContentSize { - CGSize size = (CGSize) { _scrollView.frame.size.width, INFINITY }; - size.height = [_textView sizeThatFits:size].height; - _scrollView.contentSize = size; - _textView.frame = (CGRect) { CGPointZero, size }; - - if (_viewDidCompleteInitialLayout && _onContentSizeChange && !CGSizeEqualToSize(_previousContentSize, size)) { - _previousContentSize = size; + CGSize contentSize = (CGSize) { CGRectGetMaxX(_scrollView.frame), INFINITY }; + contentSize.height = [_textView sizeThatFits:contentSize].height; + + if (_viewDidCompleteInitialLayout && _onContentSizeChange && !CGSizeEqualToSize(_previousContentSize, contentSize)) { + _previousContentSize = contentSize; _onContentSizeChange(@{ @"contentSize": @ { - @"height": @(size.height), - @"width": @(size.width), + @"height": @(contentSize.height), + @"width": @(contentSize.width), }, @"target": self.hippyTag, }); } + + CGSize viewSize = CGSizeMake(CGRectGetWidth(_scrollView.frame), MAX(contentSize.height, self.frame.size.height)); + _scrollView.contentSize = viewSize; + _textView.frame = (CGRect) { CGPointZero, viewSize }; } - (void)updatePlaceholder { @@ -743,14 +745,6 @@ - (void)setValue:(NSString *)value { [self setText:value]; } -- (void)setFontSize:(NSNumber *)fontSize { - _fontSize = fontSize; - - if ([fontSize floatValue] > 0) { - [self setFont:[UIFont systemFontOfSize:[fontSize floatValue]]]; - } -} - - (void)setDefaultValue:(NSString *)defaultValue { if (defaultValue) { [self setText:defaultValue];