From 987c6fd29868e18d9c881837a795d5d12588ca4e Mon Sep 17 00:00:00 2001 From: Soumyajit Behera Date: Thu, 23 Mar 2023 11:37:01 -0700 Subject: [PATCH] fix: make cursor center for different line height (#36586) Summary: Currently in multiline input the cursor touches the previous line. So this reduces its height sets its position so that I does not touch previous line. This PR will also fix the issue https://github.com/facebook/react-native/issues/28012 (Problem with TextInput lineHeight on iOS) This RP will fix the issue caused in [PR](https://github.com/facebook/react-native/pull/36484) Changelog: [iOS][Added] - Fixed cursor height on multiline text input Pull Request resolved: https://github.com/facebook/react-native/pull/36586 Test Plan: Tested for different cursor height https://user-images.githubusercontent.com/46092576/227004355-3886a0b5-7cdb-4fdc-a16b-3c4abb729737.mov https://user-images.githubusercontent.com/46092576/227004361-48099f81-9f52-460d-8ae8-d0ddb09dc47d.mov Reviewed By: javache Differential Revision: D44307457 Pulled By: genkikondo fbshipit-source-id: afeea5605ed8557cdeec1e62324c85665ce367d6 --- .../Libraries/Text/TextInput/Multiline/RCTUITextView.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.m b/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.m index 5d5d3085879..19d49c76760 100644 --- a/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.m +++ b/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.m @@ -298,7 +298,12 @@ static UIColor *defaultPlaceholderColor() return CGRectZero; } - return [super caretRectForPosition:position]; + CGRect rect = [super caretRectForPosition:position]; + UIFont *font = self.font; + float prevHeight = rect.size.height; + rect.size.height = font.pointSize - font.descender; + rect.origin.y += (prevHeight - rect.size.height); + return rect; } #pragma mark - Utility Methods