/** Invoked by React to create a new node with a given tag has its properties changed. */ public void updateView(int tag, String className, ReadableMap props) { ViewManager viewManager = mViewManagers.get(className); if (viewManager == null) { throw new IllegalViewOperationException("Got unknown view type: " + className); } ReactShadowNode cssNode = mShadowNodeRegistry.getNode(tag); if (cssNode == null) { throw new IllegalViewOperationException("Trying to update non-existent view with tag " + tag); } if (props != null) { CatalystStylesDiffMap styles = new CatalystStylesDiffMap(props); cssNode.updateProperties(styles); if (!cssNode.isVirtual()) { mNativeViewHierarchyOptimizer.handleUpdateView(cssNode, className, styles); } } }
private void assertNodeDoesNotNeedCustomLayoutForChildren(ReactShadowNode node) { ViewManager viewManager = Assertions.assertNotNull(mViewManagers.get(node.getViewClass())); ViewGroupManager viewGroupManager; if (viewManager instanceof ViewGroupManager) { viewGroupManager = (ViewGroupManager) viewManager; } else { throw new IllegalViewOperationException( "Trying to use view " + node.getViewClass() + " as a parent, but its Manager doesn't extends ViewGroupManager"); } if (viewGroupManager != null && viewGroupManager.needsCustomLayoutForChildren()) { throw new IllegalViewOperationException( "Trying to measure a view using measureLayout/measureLayoutRelativeToParent relative to" + " an ancestor that requires custom layout for it's children (" + node.getViewClass() + "). Use measure instead."); } }
public void createView( int rootViewTagForContext, int tag, String className, @Nullable CatalystStylesDiffMap initialProps) { UiThreadUtil.assertOnUiThread(); ViewManager viewManager = mViewManagers.get(className); View view = viewManager.createView(mRootViewsContext.get(rootViewTagForContext), mJSResponderHandler); mTagsToViews.put(tag, view); mTagsToViewManagers.put(tag, viewManager); // Use android View id field to store React tag. This is possible since we don't inflate // React views from layout xmls. Thus it is easier to just reuse that field instead of // creating another (potentially much more expensive) mapping from view to React tag view.setId(tag); if (initialProps != null) { viewManager.updateProperties(view, initialProps); } }
/** Invoked by React to create a new node with a given tag, class name and properties. */ public void createView(int tag, String className, int rootViewTag, ReadableMap props) { ViewManager viewManager = mViewManagers.get(className); ReactShadowNode cssNode = viewManager.createShadowNodeInstance(); ReactShadowNode rootNode = mShadowNodeRegistry.getNode(rootViewTag); cssNode.setReactTag(tag); cssNode.setViewClassName(className); cssNode.setRootNode(rootNode); cssNode.setThemedContext(rootNode.getThemedContext()); mShadowNodeRegistry.addNode(cssNode); CatalystStylesDiffMap styles = null; if (props != null) { styles = new CatalystStylesDiffMap(props); cssNode.updateProperties(styles); } if (!cssNode.isVirtual()) { mNativeViewHierarchyOptimizer.handleCreateView(cssNode, rootViewTag, styles); } }