( instance: Instance, type: string, oldProps: Props, newProps: Props, keepChildren: boolean, newChildSet: ?ChildSet, )
| 445 | export const supportsPersistence = true; |
| 446 | |
| 447 | export function cloneInstance( |
| 448 | instance: Instance, |
| 449 | type: string, |
| 450 | oldProps: Props, |
| 451 | newProps: Props, |
| 452 | keepChildren: boolean, |
| 453 | newChildSet: ?ChildSet, |
| 454 | ): Instance { |
| 455 | const viewConfig = instance.canonical.viewConfig; |
| 456 | const updatePayload = diffAttributePayloads( |
| 457 | oldProps, |
| 458 | newProps, |
| 459 | viewConfig.validAttributes, |
| 460 | ); |
| 461 | // TODO: If the event handlers have changed, we need to update the current props |
| 462 | // in the commit phase but there is no host config hook to do it yet. |
| 463 | // So instead we hack it by updating it in the render phase. |
| 464 | instance.canonical.currentProps = newProps; |
| 465 | |
| 466 | const node = instance.node; |
| 467 | let clone; |
| 468 | if (keepChildren) { |
| 469 | if (updatePayload !== null) { |
| 470 | clone = cloneNodeWithNewProps(node, updatePayload); |
| 471 | } else { |
| 472 | // No changes |
| 473 | return instance; |
| 474 | } |
| 475 | } else { |
| 476 | // If passChildrenWhenCloningPersistedNodes is enabled, children will be non-null |
| 477 | if (newChildSet != null) { |
| 478 | if (updatePayload !== null) { |
| 479 | clone = cloneNodeWithNewChildrenAndProps( |
| 480 | node, |
| 481 | newChildSet, |
| 482 | updatePayload, |
| 483 | ); |
| 484 | } else { |
| 485 | clone = cloneNodeWithNewChildren(node, newChildSet); |
| 486 | } |
| 487 | } else { |
| 488 | if (updatePayload !== null) { |
| 489 | clone = cloneNodeWithNewChildrenAndProps(node, updatePayload); |
| 490 | } else { |
| 491 | clone = cloneNodeWithNewChildren(node); |
| 492 | } |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | return { |
| 497 | node: clone, |
| 498 | canonical: instance.canonical, |
| 499 | }; |
| 500 | } |
| 501 | |
| 502 | export function cloneHiddenInstance( |
| 503 | instance: Instance, |
no test coverage detected