React Native Fiber: Fix errors in children management

Reviewed By: bvaughn

Differential Revision: D4905062

fbshipit-source-id: 43c24e7bcaf06eb4c7385b7022d0f20cf42d6f2f
This commit is contained in:
Ben Alpert 2017-04-18 18:24:01 -07:00 committed by Facebook Github Bot
parent 23e8fcc68c
commit 8f2d73d50b
1 changed files with 29 additions and 18 deletions

View File

@ -71,10 +71,7 @@ const NativeRenderer = ReactFiberReconciler({
parentInstance: Instance | Container, parentInstance: Instance | Container,
child: Instance | TextInstance, child: Instance | TextInstance,
): void { ): void {
const childTag = typeof child === 'number' ? child : child._nativeTag;
const childTag = typeof child === 'number'
? child
: child._nativeTag;
if (typeof parentInstance === 'number') { if (typeof parentInstance === 'number') {
// Root container // Root container
@ -85,16 +82,32 @@ const NativeRenderer = ReactFiberReconciler({
} else { } else {
const children = parentInstance._children; const children = parentInstance._children;
children.push(child); const index = children.indexOf(child);
UIManager.manageChildren( if (index >= 0) {
parentInstance._nativeTag, // containerTag children.splice(index, 1);
[], // moveFromIndices children.push(child);
[], // moveToIndices
[childTag], // addChildReactTags UIManager.manageChildren(
[children.length - 1], // addAtIndices parentInstance._nativeTag, // containerTag
[], // removeAtIndices [index], // moveFromIndices
); [children.length - 1], // moveToIndices
[], // addChildReactTags
[], // addAtIndices
[], // removeAtIndices
);
} else {
children.push(child);
UIManager.manageChildren(
parentInstance._nativeTag, // containerTag
[], // moveFromIndices
[], // moveToIndices
[childTag], // addChildReactTags
[children.length - 1], // addAtIndices
[], // removeAtIndices
);
}
} }
}, },
@ -267,12 +280,12 @@ const NativeRenderer = ReactFiberReconciler({
const children = (parentInstance: any)._children; const children = (parentInstance: any)._children;
const beforeChildIndex = children.indexOf(beforeChild);
const index = children.indexOf(child); const index = children.indexOf(child);
// Move existing child or add new child? // Move existing child or add new child?
if (index >= 0) { if (index >= 0) {
children.splice(index, 1); children.splice(index, 1);
const beforeChildIndex = children.indexOf(beforeChild);
children.splice(beforeChildIndex, 0, child); children.splice(beforeChildIndex, 0, child);
UIManager.manageChildren( UIManager.manageChildren(
@ -284,11 +297,10 @@ const NativeRenderer = ReactFiberReconciler({
[], // removeAtIndices [], // removeAtIndices
); );
} else { } else {
const beforeChildIndex = children.indexOf(beforeChild);
children.splice(beforeChildIndex, 0, child); children.splice(beforeChildIndex, 0, child);
const childTag = typeof child === 'number' const childTag = typeof child === 'number' ? child : child._nativeTag;
? child
: child._nativeTag;
UIManager.manageChildren( UIManager.manageChildren(
(parentInstance: any)._nativeTag, // containerID (parentInstance: any)._nativeTag, // containerID
@ -387,7 +399,6 @@ findNodeHandle.injection.injectFindNode((fiber: Fiber) =>
NativeRenderer.findHostInstance(fiber)); NativeRenderer.findHostInstance(fiber));
findNodeHandle.injection.injectFindRootNodeID(instance => instance); findNodeHandle.injection.injectFindRootNodeID(instance => instance);
// Intercept lifecycle errors and ensure they are shown with the correct stack // Intercept lifecycle errors and ensure they are shown with the correct stack
// trace within the native redbox component. // trace within the native redbox component.
ReactFiberErrorLogger.injection.injectDialog( ReactFiberErrorLogger.injection.injectDialog(