From 6eb014eab3c6a0211faeb30b441b6b7b303c67da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E5=B0=9A=E6=98=86?= Date: Fri, 8 Jul 2022 14:34:37 +0800 Subject: [PATCH] fix: textView's placeholder position error bug . --- doric-demo/src/InputDemo.ts | 1 + doric-iOS/Pod/Classes/Shader/DoricInputNode.m | 46 ++++++++++--------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/doric-demo/src/InputDemo.ts b/doric-demo/src/InputDemo.ts index d0c935a7..48991ed0 100644 --- a/doric-demo/src/InputDemo.ts +++ b/doric-demo/src/InputDemo.ts @@ -9,6 +9,7 @@ import { Color, input, text, + log, } from "doric"; import { preferenceView } from "./components/PreferenceView"; import { title } from "./utils"; diff --git a/doric-iOS/Pod/Classes/Shader/DoricInputNode.m b/doric-iOS/Pod/Classes/Shader/DoricInputNode.m index cf199955..b4013fc6 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricInputNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricInputNode.m @@ -70,27 +70,6 @@ - (void)setText:(NSString *)text { - (void)layoutSubviews { [super layoutSubviews]; - self.placeholderLabel.hidden = self.text.length > 0; - if (!self.placeholderLabel.hidden) { - CGFloat lineFragmentPadding = self.textContainer.lineFragmentPadding; - UIEdgeInsets textContainerInset = self.textContainerInset; - self.placeholderLabel.x = lineFragmentPadding + textContainerInset.left; - - CGFloat desiredWidth = self.width - lineFragmentPadding * 2 - textContainerInset.left - textContainerInset.right; - CGSize fitSize = [self.placeholderLabel sizeThatFits:CGSizeMake(desiredWidth, 0)]; - - if (fitSize.width < desiredWidth) { - self.placeholderLabel.width = desiredWidth; - } - self.placeholderLabel.height = fitSize.height; - if ((self.gravity & DoricGravityTop) == DoricGravityTop) { - self.placeholderLabel.y = textContainerInset.top; - } else if ((self.gravity & DoricGravityBottom) == DoricGravityBottom) { - self.placeholderLabel.y = self.height - textContainerInset.bottom - fitSize.height; - } else { - self.placeholderLabel.centerY = (self.height - textContainerInset.top - textContainerInset.bottom) / 2; - } - } if (self.contentSize.height < self.height) { if ((self.gravity & DoricGravityTop) == DoricGravityTop) { self.contentInset = UIEdgeInsetsMake( @@ -112,6 +91,31 @@ - (void)layoutSubviews { self.contentInset.right); } } + + self.placeholderLabel.hidden = self.text.length > 0; + if (!self.placeholderLabel.hidden) { + CGFloat lineFragmentPadding = self.textContainer.lineFragmentPadding; + UIEdgeInsets textContainerInset = self.textContainerInset; + self.placeholderLabel.x = lineFragmentPadding + textContainerInset.left; + + CGFloat desiredWidth = self.width - lineFragmentPadding * 2 - textContainerInset.left - textContainerInset.right; + CGSize fitSize = [self.placeholderLabel sizeThatFits:CGSizeMake(desiredWidth, 0)]; + + if (fitSize.width < desiredWidth) { + self.placeholderLabel.width = desiredWidth; + } + self.placeholderLabel.height = fitSize.height; + if ((self.gravity & DoricGravityTop) == DoricGravityTop) { + self.placeholderLabel.y = textContainerInset.top; + } else if ((self.gravity & DoricGravityBottom) == DoricGravityBottom) { + self.placeholderLabel.y = self.height - textContainerInset.bottom - fitSize.height ; + } else { + self.placeholderLabel.centerY = (self.height - textContainerInset.top - textContainerInset.bottom) / 2 ; + } + if (self.contentInset.top > 0) { + self.placeholderLabel.y = self.placeholderLabel.y - self.contentInset.top; + } + } } - (CGSize)sizeThatFits:(CGSize)size {