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

fix(android): 📺 makeImageFromView respect scroll offset #2306

Merged
merged 11 commits into from
Apr 2, 2024

Conversation

Nodonisko
Copy link
Contributor

@Nodonisko Nodonisko commented Mar 21, 2024

fixes #2171
fixes #2063
The underlying problem is not attributed to padding but to snapshots being captured from the top part of the FlatList, which may have already unmounted some components due to scroll offset.

The update corrects a flaw where the ScrollView offset was disregarded, causing snapshots to capture only the topmost section of the ScrollView, irrespective of the user's scroll position.

In the process of fixing this, another issue surfaced: if the ScrollView doesn't extend across the full height (or width, for horizontal views), the unoccupied area would appear in the snapshot. To address this, I've implemented a clipping mechanism.

Additionally, I've added e2e tests but I probably don't know how to use them because I've encountered several issues (help appreciated):

  1. The new test generates only an empty, transparent PNG.
  2. I am not sure if the ref used for scrollTo actions functions correctly, as it might execute after the snapshot is taken.
  3. Running tests locally results in numerous differences and failures in areas I haven't modified.

Some screenshots for reference:

@Nodonisko Nodonisko force-pushed the fix/android-snapshot-scrollview branch from 99399ec to 463dfd5 Compare March 21, 2024 19:59
@Nodonisko
Copy link
Contributor Author

Nodonisko commented Mar 21, 2024

Also how do you format code? There is no prettier in repository so I used default VSCode formatter, but not sure if it's correct solution.

@Nodonisko Nodonisko changed the title fix(android): makeImageFromView respect scroll offset fix(android): 📺 makeImageFromView respect scroll offset Mar 21, 2024
@wcandillon
Copy link
Contributor

@Nodonisko formatting is done via prettier you didn't see it because eslint takes care of it.

@wcandillon
Copy link
Contributor

this looks very cool :)

@wcandillon
Copy link
Contributor

Well done :)) I've very excited about this.

package.json Outdated Show resolved Hide resolved
Copy link
Contributor

@wcandillon wcandillon left a comment

Choose a reason for hiding this comment

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

very very cool, added two small comments to the PR

@wcandillon wcandillon self-requested a review April 1, 2024 11:02
<ScrollView
style={styles.scrollview}
ref={(ref) => {
ref?.scrollTo({ y: 200 });
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@wcandillon Maybe remove these refs in all Snapshots since they doesn't work anyway because snapshot is taken before it scrolls?

Copy link
Contributor

Choose a reason for hiding this comment

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

we do wait before taking the screenshot but it is possible that on CI it is too slow to work. Locally I was getting a consistent result. If I see that it is unstable on CI, I will indeed change it.

Copy link
Contributor

Choose a reason for hiding this comment

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

You seem to be pretty sure that the test will be flaky there. I should probably be very careful there :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, I would prefer slightly less cover in tests than flakines :-)

@wcandillon wcandillon merged commit 4e63f30 into Shopify:main Apr 2, 2024
9 checks passed
@wcandillon
Copy link
Contributor

@Nodonisko thank you for this ❤️

@Nodonisko
Copy link
Contributor Author

Thank you too for help ❤️

Copy link
Contributor

github-actions bot commented Apr 2, 2024

🎉 This PR is included in version 1.0.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants