JS-driven screenshot approach via ScreenshotHelper native module#106
Open
EmilioBejasa wants to merge 2 commits into
Open
JS-driven screenshot approach via ScreenshotHelper native module#106EmilioBejasa wants to merge 2 commits into
EmilioBejasa wants to merge 2 commits into
Conversation
Instead of waiting for ReactMarker.CONTENT_APPEARED from the native side, each component calls NativeModules.ScreenshotHelper.takeScreenshot(name) from useEffect via requestAnimationFrame. The native module takes the screenshot and releases a CountDownLatch, unblocking the test thread. This inverts control: the JS render cycle determines when the screenshot is taken, rather than native heuristics about when React is "done". Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Instead of 19 sequential parameterized tests, ComponentSurfaceTest.screenshotAll starts all surfaces in a single runOnMainSync. The JS thread queues work for all of them at once; each calls ScreenshotHelper.takeScreenshot independently and counts down a shared CountDownLatch. Test count drops from 21 to 3. ScreenshotHelperModule now uses ConcurrentHashMap<String, WeakReference<View>> and a single shared CountDownLatch instead of single-value statics. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
tdrhq
requested changes
Apr 7, 2026
|
|
||
| val bundleLoader = JSBundleLoader.createAssetLoader( | ||
| context, "assets://index.android.bundle", true) | ||
| val delegate = DefaultReactHostDelegate( |
Contributor
There was a problem hiding this comment.
after PR #103 is approved and merged, I want you to refactor the code from IsolatedTest, not copy-paste a completely duplicate version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ScreenshotHelperModule— a native module that JS calls when a component has finished renderingwithAutoScreenshot(name, Component)HOC which callsNativeModules.ScreenshotHelper.takeScreenshot(name)fromuseEffect+requestAnimationFrameReactHostFixturesets aCountDownLatch+ view reference before starting each surface, then waits for JS to release itScreenshotHelperPackageto register the module with the isolatedReactHostImplWhy
Instead of using
ReactMarker.CONTENT_APPEARED(a native heuristic), the JS render cycle itself determines when the screenshot is taken.useEffectfires after React has committed the tree;requestAnimationFramedefers by one frame to let native layout settle. This inverts control to the JS side.Test plan
app:recordDebugAndroidTestScreenshotTest)🤖 Generated with Claude Code