Manually assign id of the top-level View to match top-level react tag

Summary:
Nodes create a FlatViewGroup for a root node element, and NativeViewHierarchyManager assigns it an id that matches root node it. Now this top-level FlatViewGroup is added to a ReactRootView. In non-nodes, this ReactRootView has an id that matches root View id, and when this ReactRootView gets detached from Window, it sends an event to NativeViewHierarchyManager that says that all the children of this View must be removed recursively. This works great in non-Nodes, but fails in Nodes because ReactRootView has no id (-1) and NativeViewHierarchyManager fails to find a corresponding ReactShadowNode, throwing an Exception. To fix the issue and make it work again we need to assign this View id of the top level shadow node. This creates a minor issue, where 2 Views (ReactRootView and its only child) share the same id, but that is not a problem because we don't enforce uniqueness of the ids, and don't rely on getViewById().

This was originally implemented, but then I removed it because I thought it wasn't truly needed. Turns out, it is needed.

Reviewed By: sriramramani

Differential Revision: D2873995
This commit is contained in:
Denis Koroskin 2016-01-28 14:30:43 -08:00 committed by Ahmed El-Helw
parent 0b79d44dcf
commit 461871364b
1 changed files with 5 additions and 0 deletions

View File

@ -45,6 +45,11 @@ import com.facebook.react.uimanager.ViewManagerRegistry;
FlatViewGroup root = new FlatViewGroup(themedContext);
view.addView(root);
// When unmounting, ReactInstanceManager.detachViewFromInstance() will check id of the
// top-level View (SizeMonitoringFrameLayout) and pass it back to JS. We want that View's id to
// be set, otherwise NativeViewHierarchyManager will not be able to cleanup properly.
view.setId(tag);
addRootViewGroup(tag, root, themedContext);
}