Skip to content

Commit

Permalink
Align View creation flow between Fabric and non-Fabric
Browse files Browse the repository at this point in the history
Summary:
Ship responsibility for most View creation logic to ViewManager, where it already largely lies, and simplify code in Fabric and non-Fabric mounting layers.

Notably, some of this work was *already* being duplicated so we can expect an extremely tiny perf gain here.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D26742711

fbshipit-source-id: 4213766d4cd366bc69cd47d4654f7b269bb9e7f4
  • Loading branch information
JoshuaGross authored and facebook-github-bot committed Mar 5, 2021
1 parent ea34953 commit a65cd68
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,6 @@ public void createView(
view =
viewManager.createView(
reactTag, mThemedReactContext, propsDiffMap, stateWrapper, mJSResponderHandler);
view.setId(reactTag);
}

ViewState viewState = new ViewState(reactTag, view, viewManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,6 @@ public synchronized void createView(
viewManager.createView(tag, themedContext, initialProps, null, 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);
}
} finally {
Systrace.endSection(Systrace.TRACE_TAG_REACT_VIEW);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ public C createShadowNodeInstance() {
/**
* Subclasses should return a new View instance of the proper type. This is an optional method
* that will call createViewInstance for you. Override it if you need props upon creation of the
* view.
* view, or state.
*
* <p>If you override this method, you *must* guarantee that you you're handling updateProperties,
* view.setId, addEventEmitters, and updateState/updateExtraData properly!
*
* @param reactTag reactTag that should be set as ID of the view instance
* @param reactContext ReactContext used to initialize view instance
Expand All @@ -140,6 +143,7 @@ public C createShadowNodeInstance() {
if (initialProps != null) {
updateProperties(view, initialProps);
}
// Only present in Fabric; but always present in Fabric.
if (stateWrapper != null) {
Object extraData = updateState(view, initialProps, stateWrapper);
if (extraData != null) {
Expand Down

0 comments on commit a65cd68

Please sign in to comment.