From 7a2ce1dc70902104620dd9f834bf8d4ddfc91e1d 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 4d586ceda52..790ebc5cc32 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 ddfd59ad589..0ea33f045c2 100644 --- a/renderer/native/ios/renderer/component/textinput/HippyTextField.m +++ b/renderer/native/ios/renderer/component/textinput/HippyTextField.m @@ -355,13 +355,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 415ab01e44c..1d6c9c48521 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; @property (nonatomic, copy) HippyDirectEventBlock onChangeText; diff --git a/renderer/native/ios/renderer/component/textinput/HippyTextView.mm b/renderer/native/ios/renderer/component/textinput/HippyTextView.mm index ff13eb7228f..13ea95249cb 100644 --- a/renderer/native/ios/renderer/component/textinput/HippyTextView.mm +++ b/renderer/native/ios/renderer/component/textinput/HippyTextView.mm @@ -273,21 +273,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 { @@ -689,14 +691,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];