Skip to content

Commit

Permalink
Implement {,un}hideInstance on RN renderer (facebook#14115)
Browse files Browse the repository at this point in the history
This is required to use lazy.

Test Plan:
* Verified lazy works on a real world use case (shows spinner, shows real content).
* Verified that if I change the primary content's styles to have `display: 'none'` then it never appears (i.e., the code in `unhide` reads the styles successfully)
  • Loading branch information
sophiebits authored and jetoneza committed Jan 23, 2019
1 parent 863541e commit aa657ad
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
23 changes: 21 additions & 2 deletions packages/react-native-renderer/src/ReactFabricHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,16 @@ export function cloneHiddenInstance(
props: Props,
internalInstanceHandle: Object,
): Instance {
throw new Error('Not yet implemented.');
const viewConfig = instance.canonical.viewConfig;
const node = instance.node;
const updatePayload = ReactNativeAttributePayload.create(
{style: {display: 'none'}},
viewConfig.validAttributes,
);
return {
node: cloneNodeWithNewProps(node, updatePayload),
canonical: instance.canonical,
};
}

export function cloneUnhiddenInstance(
Expand All @@ -390,7 +399,17 @@ export function cloneUnhiddenInstance(
props: Props,
internalInstanceHandle: Object,
): Instance {
throw new Error('Not yet implemented.');
const viewConfig = instance.canonical.viewConfig;
const node = instance.node;
const updatePayload = ReactNativeAttributePayload.diff(
{...props, style: [props.style, {display: 'none'}]},
props,
viewConfig.validAttributes,
);
return {
node: cloneNodeWithNewProps(node, updatePayload),
canonical: instance.canonical,
};
}

export function createHiddenTextInstance(
Expand Down
23 changes: 21 additions & 2 deletions packages/react-native-renderer/src/ReactNativeHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,15 +454,34 @@ export function resetTextContent(instance: Instance): void {
}

export function hideInstance(instance: Instance): void {
throw new Error('Not yet implemented.');
const viewConfig = instance.viewConfig;
const updatePayload = ReactNativeAttributePayload.create(
{style: {display: 'none'}},
viewConfig.validAttributes,
);
UIManager.updateView(
instance._nativeTag,
viewConfig.uiViewClassName,
updatePayload,
);
}

export function hideTextInstance(textInstance: TextInstance): void {
throw new Error('Not yet implemented.');
}

export function unhideInstance(instance: Instance, props: Props): void {
throw new Error('Not yet implemented.');
const viewConfig = instance.viewConfig;
const updatePayload = ReactNativeAttributePayload.diff(
{...props, style: [props.style, {display: 'none'}]},
props,
viewConfig.validAttributes,
);
UIManager.updateView(
instance._nativeTag,
viewConfig.uiViewClassName,
updatePayload,
);
}

export function unhideTextInstance(
Expand Down

0 comments on commit aa657ad

Please sign in to comment.