Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] reduce cursor size for multiline(TextInput) #36484

Closed
wants to merge 6 commits into from
Closed

[iOS] reduce cursor size for multiline(TextInput) #36484

wants to merge 6 commits into from

Conversation

soumyajit4419
Copy link
Contributor

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 #28012 (Problem with TextInput lineHeight on iOS)

Changelog

[IOS] [ADDED] - Fixed cursor height on multiline text input

Test Plan

UI Before the change
Screenshot 2023-03-15 at 10 16 07 PM

UI After the change
Screenshot 2023-03-14 at 1 57 27 AM

@facebook-github-bot
Copy link
Contributor

Hi @soumyajit4419!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@analysis-bot
Copy link

analysis-bot commented Mar 15, 2023

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 8,519,193 +0
android hermes armeabi-v7a 7,834,776 +0
android hermes x86 8,999,081 +0
android hermes x86_64 8,854,121 +0
android jsc arm64-v8a 9,141,838 +0
android jsc armeabi-v7a 8,333,472 +0
android jsc x86 9,196,418 +0
android jsc x86_64 9,454,245 +0

Base commit: 221aacd
Branch: main

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 15, 2023
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot
Copy link
Contributor

@dmytrorykun has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@javache
Copy link
Member

javache commented Mar 16, 2023

The height manipulation and Y offset seem like arbitrary numbers. Is there any source for why these numbers are correct/the most appropriates solution here?

Copy link
Member

@javache javache left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caret sizing should be based on the font metrics, 0.75x or offsetting by 4 is not safe for all fonts.

return [super caretRectForPosition:position];
CGRect originalRect = [super caretRectForPosition:position];
originalRect.size.height *= 0.75;
return CGRectMake(originalRect.origin.x, originalRect.origin.y + 4 , originalRect.size.width, originalRect.size.height);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assumes that originalRect's height < 4, so we can offset it by this much, which is not safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay .
Got it.

@soumyajit4419
Copy link
Contributor Author

soumyajit4419 commented Mar 19, 2023

@javache I have updated my PR based on the comments
Can you say if this approach is correct?

@facebook-github-bot
Copy link
Contributor

@javache has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@situchan
Copy link

This PR shouldn't be merged at all. It causes bigger issue.

It doesn't completely fix cursor issue on iOS multiline TextInput.
After reducing cursor height, it aligns to top, while text aligns to bottom:
Also, selected range cursor doesn't match.

Before:

before.mp4

After:

after.mp4

The ideal solution should be to align center both cursor and text, same as Text component.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Mar 22, 2023
@facebook-github-bot
Copy link
Contributor

@javache merged this pull request in e188585.

@situchan
Copy link

@javache can you please check my concern here?

@javache
Copy link
Member

javache commented Mar 22, 2023

@situchan Thanks for the report, can you share a code-sample for it?

I'll revert this change for now. @soumyajit4419: can you revisit this PR and include @situchan's test case?

@facebook-github-bot
Copy link
Contributor

This pull request has been reverted by 8313f23.

@situchan
Copy link

@javache this code should be enough for test. Just return in root App.js

    <View style={{flex: 1, paddingTop: 200}}>
        <View style={{marginHorizontal: 50}}>
            <Text>Text</Text>
            <Text style={{
                height: 110, borderWidth: 1, lineHeight: 50, fontSize: 16,
            }}
            >
                sdj fdsjflj slafjal ksdj afklakjfkajdskfj; asjfjs;dfs klfjalsjf j;ksd fkjalkj sfjlks j
            </Text>
        </View>
        <View style={{marginHorizontal: 50, marginTop: 50}}>
            <Text>TextInput</Text>
            <TextInput
                multiline
                placeholder="sdj fdsjflj slafjal ksdj afklakjfkajdskfj; asjfjs;dfs klfjalsjf j;ksd fkjalkj sfjlks j"
                style={{
                    height: 110, borderWidth: 1, lineHeight: 50, fontSize: 16,
                }}
            />
        </View>
    </View>

@soumyajit4419
Copy link
Contributor Author

soumyajit4419 commented Mar 22, 2023

@javache
I have created a PR fixing the issue of caret position with different lineHeight.
PR

@situchan I have tested it for different line height and the caret remains in the center.

facebook-github-bot pushed a commit that referenced this pull request Mar 23, 2023
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 #28012 (Problem with TextInput lineHeight on iOS)
This RP will fix the issue caused in
[PR](#36484)

Changelog:
[iOS][Added] - Fixed cursor height on multiline text input

Pull Request resolved: #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
@situchan
Copy link

situchan commented Mar 24, 2023

@soumyajit4419 do you think the issue was fixed completely?

Still has issues:

  • suggestion highlight rectangle is still aligned to the top
  • selection rectangle still takes full height
  • text and caret should be center aligned like Text view, not bottom
bug.mp4

jeongshin pushed a commit to jeongshin/react-native that referenced this pull request May 7, 2023
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 facebook#28012 (Problem with TextInput lineHeight on iOS)
## Changelog

[IOS] [ADDED] - Fixed cursor height on multiline text input
<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

Pull Request resolved: facebook#36484

Test Plan:
UI Before the change
<img width="379" alt="Screenshot 2023-03-15 at 10 16 07 PM" src="https://user-images.githubusercontent.com/46092576/225380938-23b9b8a4-4b8a-45e1-bbf1-4af8ac8d9183.png">

UI After the change
<img width="509" alt="Screenshot 2023-03-14 at 1 57 27 AM" src="https://user-images.githubusercontent.com/46092576/225380930-77ca853c-fae5-4bfa-82cf-03b2e22bf8da.png">

Reviewed By: dmytrorykun

Differential Revision: D44130814

Pulled By: javache

fbshipit-source-id: 09d53ecee6812e9a875dc5364bd91b76cc2bc1f5
jeongshin pushed a commit to jeongshin/react-native that referenced this pull request May 7, 2023
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 facebook#28012 (Problem with TextInput lineHeight on iOS)
This RP will fix the issue caused in
[PR](facebook#36484)

Changelog:
[iOS][Added] - Fixed cursor height on multiline text input

Pull Request resolved: facebook#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
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
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 facebook#28012 (Problem with TextInput lineHeight on iOS)
## Changelog

[IOS] [ADDED] - Fixed cursor height on multiline text input
<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

Pull Request resolved: facebook#36484

Test Plan:
UI Before the change
<img width="379" alt="Screenshot 2023-03-15 at 10 16 07 PM" src="https://user-images.githubusercontent.com/46092576/225380938-23b9b8a4-4b8a-45e1-bbf1-4af8ac8d9183.png">

UI After the change
<img width="509" alt="Screenshot 2023-03-14 at 1 57 27 AM" src="https://user-images.githubusercontent.com/46092576/225380930-77ca853c-fae5-4bfa-82cf-03b2e22bf8da.png">

Reviewed By: dmytrorykun

Differential Revision: D44130814

Pulled By: javache

fbshipit-source-id: 09d53ecee6812e9a875dc5364bd91b76cc2bc1f5
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
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 facebook#28012 (Problem with TextInput lineHeight on iOS)
This RP will fix the issue caused in
[PR](facebook#36484)

Changelog:
[iOS][Added] - Fixed cursor height on multiline text input

Pull Request resolved: facebook#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Reverted
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants