Reland: Migrate ReactClippingViewGroup to Kotlin (#49413)#49607
Reland: Migrate ReactClippingViewGroup to Kotlin (#49413)#49607mateoguzmana wants to merge 2 commits into
ReactClippingViewGroup to Kotlin (#49413)#49607Conversation
|
@mateoguzmana Looking at the code more closely, I think I found the problem. |
There was a problem hiding this comment.
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.
@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.
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? |


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: