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

Allow custom optional visibility observer #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

GeKorm
Copy link

@GeKorm GeKorm commented Jul 11, 2018

What:
This PR allows users to

  1. Omit lazy-loading completely, no need for additional dependencies
  2. Provide any visibility observer

Why:
The main thing this PR achieves isn't much different than #51 I would say the only differences are:

  1. It's easier to omit the observer (no need to provide a mock for onEnter to make all images visible)
  2. It provides a few additional ways of defining an observer, especially because it seems many people like the child render prop pattern
  3. It fixes a potential bug in onEnter

How:
Depending on what the user provides, in order:

Checklist:

  • Documentation
  • Tests | Nope, wanted to discuss first
  • Ready to be merged
  • Added myself to contributors table

Please feel free to check the published fork npm install @gekorm/react-ideal-image

if (shouldAutoDownload) this.load(false)
this.setState(
{pickedSrc, shouldAutoDownload, url},
shouldAutoDownload ? () => this.load(false) : undefined,
Copy link
Author

Choose a reason for hiding this comment

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

It's important for this to be callback otherwise this.load could have stale state (I encountered this with url being undefined)

height={2095}
observer={Waypoint}
>
<Waypoint scrollableAncestor="window" /> // onEnter and onLeave are passed automatically
Copy link
Author

@GeKorm GeKorm Jul 11, 2018

Choose a reason for hiding this comment

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

I started working on this PR mainly because I needed to provide scrollableAncestor="window". Lazy-loading didn't work at all without this. I'm guessing it's either due to SSR or overflow: auto in a parent, both common scenarios.

Copy link
Owner

Choose a reason for hiding this comment

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

It is not because of SSR (SSR should be properly handled)

@stereobooster
Copy link
Owner

I don't want to overcomplicate already complex component, rather I would search a way to separate existing component into compassable subcomponents to be able to construct out of it what you want. For example, you do not observer - simply do not use observer subcomponent. This was my initial idea, but it was hard and I decided to construct one big component for the demo and handle this idea latter.

Maybe try approach similar to state-containers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants