-
Notifications
You must be signed in to change notification settings - Fork 20
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
Add support for numberOfLines and maximumNumberOfLines props on iOS and Android #37
Add support for numberOfLines and maximumNumberOfLines props on iOS and Android #37
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Szymon20000 Sorry, but this PR needs to target a different branch, probably best to target https://github.com/Expensify/react-native/tree/Expensify-0.71.0-alpha1 for now. Thanks
Not a problem. Will change that tomorrow morning. |
Totally, no reason to wait |
bd04a64
to
a19651f
Compare
Done |
This pr needs some polishing like clang-format but would like to first get some feedback on it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for the long delay in reviewing this @Szymon20000. Can you please update it to target the Expensify-0.71.2-alpha.0
branch?
Sure, I will do it tomorrow morning together with renaming the prop as on 0.71 it's changed to "rows". |
a19651f
to
4d3177c
Compare
Tested it after rebase and rename and it seems to works fine. |
@Szymon20000 Can you address the CI failures in the upstream PR plz? |
@roryabraham I tested it on Android and it looks like numberOfLines/rows doesn't work there properly. |
Will do my best to fix CI failing tests later today. |
I imagine we would love to get this fixed on Android as well cc @roryabraham |
ios changes update types, configs fix NativeTextComponent Props fix fabric issue with newlines Apply suggestions from code review Co-authored-by: Janic Duplessis <janicduplessis@gmail.com> add example to rntester
a6cf789
to
4bd87ab
Compare
Coming from Expensify/App#17368: |
I believe the issue was already fixed by me and @roryabraham cherry-picked it. Probably the RN fork with the fix is not yet used in the app. |
@Szymon20000 that's great! Can you please link that PR in our forked repo? |
I think that's the one dd492a1 |
Just for clarity, we've since decided to drop our fork, use the upstream repo instead, and focus on getting PRs merged upstream. |
So we should be waiting on facebook#38021 and facebook#35703 |
Upstream PR
facebook#35703
Summary
We want to be able to set height of TextArea/TextInput/EditText components on all platforms in the same way. Was is currently missing on iOS is expressing the height of a component in lines and this pr is supposed to fix it. Additionally in some cases we want to set maximum number of lines a "TextArea" like component can have. Because of Different screen sizes and accessibility settings it's sometimes hard to compute how many lines a current content takes so the purpose of
maximumNumberOfLines
prop is to simplify that process.iOS How it was implemented?
On Android the native "TextArea" like component (EditText) exposes
setLines
method that sets height of the component in lines. However, I wasn't able to find anything similar on iOS. What is a common method for both platforms is setting maximum height in lines. On iOS we can set.maximumNumberOfLines
property onTextContainer
and similarly on Android we can callsetMaxLines()
method to limit number of lines. So AddingmaximumNumberOfLines
is not a problem.I realised that when we add enough number of newLines in order to implement
numberOfLines
prop usingmaximumNumberOfLines
functionality and did exactly that. Probably it's possible to get a font size and based on that set exact height but I didn't want to miss any edge cases and adding few newlines doesn't seem to be an overhead at all.Also probably otherwise we would need to take into account things like
space between lines
,padding
...Android
I exposed
setMaxLines
in the same waysetLines
was exposed before so I'm pretty confident it's correct however I still need to test it.Fabric
I implemented numberOfLines and maximumNumberOfLines similarly to what I did for paper architecture but it turned out that there is one edge case. Whenever you tapped the enter button it added a new line to the text input. Even though NSTextContainer clearly had set maximumNumberOfLines property. I checked what are differences between paper and Fabric implementation when it comes to using NSTextContainer but I wasn't able to spot any difference. Fonts, spaces, other text attributes were exactly the same for every character. In RN docs I found that TextInput already have support for numberOfLines to I checked if the problem occurs also there. Turned out that problem is there too and moreover it's also in paper architecture. I checked differences on how NSContainer is used and spotted a different order of methods called on NSTextContainer, NSTextStorage and NSLayoutManager. After changing the order the problem is gone everywhere.
Changelog
[CATEGORY] [TYPE] - Message
Test Plan
I basically run the RNTester app with and without fabric.