Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement {,un}hideInstance on RN renderer #14115

Merged
merged 1 commit into from
Nov 5, 2018

Conversation

sophiebits
Copy link
Collaborator

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)

@sebmarkbage
Copy link
Collaborator

Hm. We shouldn't assume that the flattening happens the way it does today. There is a configuration layer that determines that. Perhaps we can call { style: {display: ....} } to ReactNativeAttributePayload somehow?

I was hoping that we'd be able to batch these into the normal properties update call so there is only one updateView call. I suspect this can lead to subtle bugs depending on the order of these updateView calls not getting flipped and it'll cause two updates where one is expected.

However, eventually this will all go away with Fabric.

We should add a fix to Fabric too at the same time so they line up. That one might be more straightforward.

@sizebot
Copy link

sizebot commented Nov 5, 2018

Details of bundled changes.

Comparing: 8eca0ef...bb0a833

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactNativeRenderer-dev.js +0.1% +0.1% 554.44 KB 554.88 KB 121.35 KB 121.43 KB RN_FB_DEV
ReactNativeRenderer-prod.js 🔺+0.6% 🔺+0.4% 238.53 KB 240.06 KB 42.02 KB 42.2 KB RN_FB_PROD
ReactNativeRenderer-dev.js +0.1% +0.1% 554.11 KB 554.56 KB 121.25 KB 121.34 KB RN_OSS_DEV
ReactNativeRenderer-prod.js 🔺+0.6% 🔺+0.4% 238.55 KB 240.08 KB 42.02 KB 42.2 KB RN_OSS_PROD
ReactFabric-dev.js +0.1% +0.1% 544.63 KB 545.18 KB 118.86 KB 118.94 KB RN_FB_DEV
ReactFabric-prod.js 🔺+0.3% 🔺+0.5% 233.42 KB 234.03 KB 40.72 KB 40.91 KB RN_FB_PROD
ReactFabric-dev.js +0.1% +0.1% 544.66 KB 545.21 KB 118.88 KB 118.95 KB RN_OSS_DEV
ReactFabric-prod.js 🔺+0.3% 🔺+0.5% 233.45 KB 234.07 KB 40.74 KB 40.93 KB RN_OSS_PROD
ReactNativeRenderer-profiling.js +0.3% +0.3% 244.24 KB 245.03 KB 43.23 KB 43.35 KB RN_OSS_PROFILING
ReactFabric-profiling.js +0.3% +0.4% 237.99 KB 238.61 KB 41.99 KB 42.17 KB RN_OSS_PROFILING
ReactNativeRenderer-profiling.js +0.3% +0.3% 244.22 KB 245.01 KB 43.23 KB 43.36 KB RN_FB_PROFILING
ReactFabric-profiling.js +0.3% +0.4% 237.95 KB 238.57 KB 41.97 KB 42.15 KB RN_FB_PROFILING

scheduler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
scheduler.development.js n/a n/a 0 B 19.17 KB 0 B 5.74 KB UMD_DEV
scheduler.production.min.js n/a n/a 0 B 3.16 KB 0 B 1.53 KB UMD_PROD

Generated by 🚫 dangerJS

@sophiebits
Copy link
Collaborator Author

You mean it's OK to hardcode {style: {display}} but not {display}? I can change that.

@sebmarkbage
Copy link
Collaborator

Yes. I'm uneasy with double updateView calls. But I think I'm ok with it, considering it's legacy in a Fabric world. So the only action items are 1) avoid the hard coding 2) fix fabric.

instance._nativeTag,
viewConfig.uiViewClassName,
{display: 'none'},
);
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this happen? E.g. returning a string from render?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you do

<Text><Suspense>{string}</Suspense></Text>

I think so. it seems weird, I don't know if this is complicated, and we never do this right now so I opted to skip it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe these are just like any other shadow node inside text from the native's perspective so I think we could send the display: none property here too.

cc @shergin

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe currently the only most outer <Text> supports display: none, but I think that's incorrect behavior (and I will fix it).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe in the DOM version we actually just set the string to empty string "" while hidden and then reset it to its current value.

Seems like we could do the same for RN without needing to fix the native side.

@sophiebits sophiebits force-pushed the rn-hide-unhide branch 2 times, most recently from 10018bf to 48a084b Compare November 5, 2018 22:53
@sophiebits
Copy link
Collaborator Author

This OK? I don't love the diff call in unhide but I can't think of a correct way to do it better.

throw new Error('Not yet implemented.');
const node = instance.node;
const updatePayload = ReactNativeAttributePayload.diff(
{...props, style: [props.style, {display: 'none'}]},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does spread compile to?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object.assign({}, props, { style: [props.style, { display: "none" }] }),

which is polyfilled https://github.com/facebook/react-native/blob/cc90c20bf60c72fc1b42f3306636847ce7f478e5/Libraries/polyfills/Object.es6.js#L15

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)
@sophiebits sophiebits merged commit 9d47143 into facebook:master Nov 5, 2018
gaearon pushed a commit to gaearon/react that referenced this pull request Nov 6, 2018
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)
jetoneza pushed a commit to jetoneza/react that referenced this pull request Jan 23, 2019
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)
n8schloss pushed a commit to n8schloss/react that referenced this pull request Jan 31, 2019
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants