Fix non-compiling Java snippet in Android Fabric Native Component guide - #5211
Fix non-compiling Java snippet in Android Fabric Native Component guide#5211dazakdev wants to merge 1 commit into
Conversation
|
Hi @dazakdev! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
5184acf to
68c0114
Compare
The ReactWebView.java snippet fails to compile as written: LayoutParams resolves to AbsoluteLayout.LayoutParams which has no (int, int) constructor, there is no context variable in scope, and EventDispatcher is never imported. Also enable JavaScript, which the Android WebView disables by default while the WKWebView used on iOS enables it, so that the component behaves the same on both platforms. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
68c0114 to
e517fd9
Compare
1. The Java snippet does not compile
WebView extends AbsoluteLayout, so the simple nameLayoutParamsresolves toAbsoluteLayout.LayoutParams, which has no(int, int)constructor → qualified asViewGroup.LayoutParams+ import.contextvariable is in scope →getContext().EventDispatcheris used as a declared type but never imported. Missing from every version of this page.Same failure on
compileSdk35, 36 and 37 — name/overload resolution, independent of AGP and React Native version. Present since #4288. The Kotlin tab is unaffected: Kotlin resolvesLayoutParams(...)toViewGroup.LayoutParams(int, int)and infers theEventDispatchertype.2. JavaScript is enabled on iOS, disabled on Android
The iOS page uses
_webView = [WKWebView new];—WKWebpagePreferences.allowsContentJavaScriptdefaults totrue. The AndroidWebViewdefaults tofalseand the guide never sets it, so the same component runs web content differently per platform. Not fatal for the tutorial's own URL, which renders server-side, but it silently breaks JS-dependent pages.Added the call to both language tabs and a paragraph naming the asymmetry.
Test plan
Both snippets were copied out of the updated page into an Android library module of a React Native 0.86 app.
compileDebugJavaWithJavacreports the three errors above before the change,BUILD SUCCESSFULafter.compileDebugKotlinsucceeds before and after — only the JavaScript line differs.sourceURLset todata:text/html,<body><h1>no-js</h1><script>document.body.textContent='js-ran'</script>: the component as documented today rendersno-js, with the added line it rendersjs-ran.The same three Java errors are in
website/versioned_docs/version-0.77…version-0.87. README says not to edit the generated versioned docs, so this PR leaves them alone; #4673 backported an equivalent fix as a separate PR, happy to do the same here.