Skip to content

Commit 0355975

Browse files
elicwhitefacebook-github-bot
authored andcommitted
Explain why and how to keep JS<->Naitve view configs in sync
Reviewed By: sahrens Differential Revision: D9485764 fbshipit-source-id: 673748b0ded666b8d17ed221e1208cffefb6c859
1 parent 64a5253 commit 0355975

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Libraries/Utilities/verifyComponentAttributeEquivalence.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,29 @@ const getNativeComponentAttributes = require('getNativeComponentAttributes');
1515

1616
import type {ReactNativeBaseComponentViewConfig} from 'ReactNativeTypes';
1717

18+
/**
19+
* The purpose of this function is to validate that the view config that
20+
* native exposes for a given view manager is the same as the view config
21+
* that is specified for that view manager in JS.
22+
*
23+
* In order to improve perf, we want to avoid calling into native to get
24+
* the view config when each view manager is used. To do this, we are moving
25+
* the configs to JS. In the future we will use these JS based view configs
26+
* to codegen the view manager on native to ensure they stay in sync without
27+
* this runtime check.
28+
*
29+
* If this function fails, that likely means a change was made to the native
30+
* view manager without updating the JS config as well. Ideally you can make
31+
* that direct change to the JS config. If you don't know what the differences
32+
* are, the best approach I've found is to create a view that prints
33+
* the return value of getNativeComponentAttributes, and then copying that
34+
* text and pasting it back into JS:
35+
* <Text selectable={true}>{JSON.stringify(getNativeComponentAttributes('RCTView'))}</Text>
36+
*
37+
* This is meant to be a stopgap until the time comes when we only have a
38+
* single source of truth. I wonder if this message will still be here two
39+
* years from now...
40+
*/
1841
function verifyComponentAttributeEquivalence(
1942
componentName: string,
2043
config: ReactNativeBaseComponentViewConfig<>,

0 commit comments

Comments
 (0)