-
Notifications
You must be signed in to change notification settings - Fork 25k
Reland: Migrate ReactClippingViewGroup to Kotlin (#49413)
#49607
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
Reland: Migrate ReactClippingViewGroup to Kotlin (#49413)
#49607
Conversation
|
@mateoguzmana Looking at the code more closely, I think I found the problem. |
| override var removeClippedSubviews: Boolean = false | ||
| set(value) { | ||
| // removeClippedSubviews logic may read metrics before the offsetting we do in onLayout() and | ||
| // is such unsafe | ||
| if (isRTL) { | ||
| field = false | ||
| } else { | ||
| field = value | ||
| } |
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.
I think there are issue with this code.
-
override var removeClippedSubviews: Boolean = falsecreates a new backing field forReactHorizontalScrollContainerLegacyView.ktinstead of using parent class.
So remove the= falseand addget()as it will give error without it. -
You need to use
super.removeClippedSubviewsto access parent field but if you usefieldit is setting the value on the backing field for the current class and not the parent.
| override var removeClippedSubviews: Boolean = false | |
| set(value) { | |
| // removeClippedSubviews logic may read metrics before the offsetting we do in onLayout() and | |
| // is such unsafe | |
| if (isRTL) { | |
| field = false | |
| } else { | |
| field = value | |
| } | |
| override var removeClippedSubviews: Boolean | |
| get() = super.removeCLippedSubviews | |
| set(value) { | |
| // removeClippedSubviews logic may read metrics before the offsetting we do in onLayout() and | |
| // is such unsafe | |
| if (isRTL) { | |
| super. removeClippedSubviews = false | |
| } else { | |
| super. removeClippedSubviews = value | |
| } |
I'll test this out and report result later.
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.
@mateoguzmana Above change is verified to work and is not causing a crash.
I first though there might be some interop magic that was happening but Kotlin properties are just automatically handling setter/getters under the hood and there is nothing special about it.
-
So property in Kotlin interface just creates Java setXXX()/getXXX() methods.
-
If Java class has setter/getter, chlld Kotlin class can reference them using a Kotlin property but it is just calling the setXXX()/getXXX()
-
Just like in Java, if Kotlin child want to set the property of the parent, it needs to use
super.XXXso it will call the setter/getter in the parent.
Things are different if the inheritance hierarchy is all Kotlin. Child can just access the property without specifying super.
(cc @cortinico )
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.
Thank you so much for the thorough explanation and for checking this in-depth; it makes a lot of sense now. Sorry for the back-and-forth on this one :)
I've applied these changes in 6fd5421.
|
@mateoguzmana Could you also make sure Java -> Kt conversion retains the file commit history and not treated as deleting and adding a new file? |
eef8180 to
6fd5421
Compare
|
@alanleedev has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@mateoguzmana Thanks for checking. I think it could be an issue with GitHub so importing the PR as is. |
|
@alanleedev merged this pull request in ac57ec4. |
|
This pull request was successfully merged by @mateoguzmana in ac57ec4 When will my fix make it into a release? | How to file a pick request? |
|
@mateoguzmana BTW, I had to amend the PR before merging to keep the history. |
@alanleedev did you do anything in particular? (just for my knowledge) When I pull the latest from the main branch and check the history of the file (with either code editor or using git commands) I still see the file as a full addition and the renaming is not in the history – I'm afraid it didn't fully work. –– When writing this comment I got curious and dug deeper into how this works with git. Seems like there is a "similarity score" and that's how git detects whether to consider a file as an addition/deletion or to keep it as "renamed with changes". There are some interesting posts about this online, quite interesting:
|
@mateoguzmana I had to run some Sapling command to make sure the history was kept in internal Meta codebase using Sapling (fork of Mercurial). I guess things may look different in GitHub. @cortinico Do you know the best practice here for OSS? |
…acebook#49607) Summary: Reland of facebook#49413 which was reverted due to an internal crash. I've attempted to do a solution to keep backwards compatibility but doesn't seem to work – keeping the original solution for now, perhaps something else can be cleaned up to avoid the breakage. ## Changelog: [INTERNAL] - Migrate com.facebook.react.uimanager.ReactClippingViewGroup to Kotlin Pull Request resolved: facebook#49607 Test Plan: ```bash yarn test-android yarn android ``` Verified that the update changes do not cause a crash. Test flow: - login to BizApp using Instagram account - on home screen scroll down to Insights section - it should show without crashing Reviewed By: arushikesarwani94 Differential Revision: D70200000 Pulled By: alanleedev fbshipit-source-id: 89bc948c1b91d9419d4b6e1885d949c4a3c20986


Summary:
Reland of #49413 which was reverted due to an internal crash. I've attempted to do a solution to keep backwards compatibility but doesn't seem to work – keeping the original solution for now, perhaps something else can be cleaned up to avoid the breakage.
Changelog:
[INTERNAL] - Migrate com.facebook.react.uimanager.ReactClippingViewGroup to Kotlin
Test Plan: