Skip to content

Conversation

@mateoguzmana
Copy link
Collaborator

@mateoguzmana mateoguzmana commented Feb 21, 2025

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:

yarn test-android
yarn android

@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 Feb 21, 2025
@mateoguzmana mateoguzmana marked this pull request as ready for review February 24, 2025 08:18
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Feb 24, 2025
@cortinico cortinico requested a review from alanleedev February 24, 2025 10:35
@alanleedev
Copy link
Contributor

alanleedev commented Feb 24, 2025

@mateoguzmana I don't think we should convert ReactClippingViewGroup to Kotlin with it's children like ReactViewGroup left as Java. It will result in the same issue as before.
We need to look at if converting its child classes (e.g. ReactViewGroup) together to Kotlin would be possible solution.

Looking at the code more closely, I think I found the problem.

Comment on lines 22 to 31
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
}
Copy link
Contributor

@alanleedev alanleedev Feb 25, 2025

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.

  1. override var removeClippedSubviews: Boolean = false creates a new backing field for ReactHorizontalScrollContainerLegacyView.kt instead of using parent class.
    So remove the = false and add get() as it will give error without it.

  2. You need to use super.removeClippedSubviews to access parent field but if you use field it is setting the value on the backing field for the current class and not the parent.

Suggested change
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.

Copy link
Contributor

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.

  1. So property in Kotlin interface just creates Java setXXX()/getXXX() methods.

  2. If Java class has setter/getter, chlld Kotlin class can reference them using a Kotlin property but it is just calling the setXXX()/getXXX()

  3. Just like in Java, if Kotlin child want to set the property of the parent, it needs to use super.XXX so 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 )

Copy link
Collaborator Author

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.

@alanleedev
Copy link
Contributor

@mateoguzmana Could you also make sure Java -> Kt conversion retains the file commit history and not treated as deleting and adding a new file?

@mateoguzmana mateoguzmana force-pushed the refactor/kotlinify-react-clipping-view-group-reland branch from eef8180 to 6fd5421 Compare February 25, 2025 19:31
@mateoguzmana
Copy link
Collaborator Author

Could you also make sure Java -> Kt conversion retains the file commit history and not treated as deleting and adding a new file?

This is a very good point, I think we should take this into account for other PRs as well as I've noticed many of them not keeping the history once migrated. It seems to happen most of the time when using Android Studio to do an initial conversion as it stages the file automatically as a deletion.

I've done it now for this PR by renaming first using git mv and then adding the changes after moving it with git – but GitHub somehow still shows the file as deleted and added, not so sure if it's an issue on the UI only, but in my local editor I still see the history. See:

image image

@facebook-github-bot
Copy link
Contributor

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

@alanleedev
Copy link
Contributor

alanleedev commented Feb 25, 2025

I've done it now for this PR by renaming first using git mv and then adding the changes after moving it with git – but GitHub somehow still shows the file as deleted and added, not so sure if it's an issue on the UI only, but in my local editor I still see the history. See:

@mateoguzmana Thanks for checking. I think it could be an issue with GitHub so importing the PR as is.
I think next time you can try to do the rename as a single commit and add additional changes as a separate commit and it may show up properly in GitHub.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Feb 26, 2025
@facebook-github-bot
Copy link
Contributor

@alanleedev merged this pull request in ac57ec4.

@react-native-bot
Copy link
Collaborator

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?

@alanleedev
Copy link
Contributor

@mateoguzmana BTW, I had to amend the PR before merging to keep the history.

@mateoguzmana
Copy link
Collaborator Author

@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:

@alanleedev
Copy link
Contributor

@alanleedev did you do anything in particular? (just for my knowledge)

@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?

gabrieldonadel pushed a commit to gabrieldonadel/react-native that referenced this pull request Aug 12, 2025
…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
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. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants