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

Add partialVisiblity property. #15

Merged
merged 1 commit into from
Jun 17, 2015
Merged

Add partialVisiblity property. #15

merged 1 commit into from
Jun 17, 2015

Conversation

kompot
Copy link
Collaborator

@kompot kompot commented Jun 16, 2015

If partialVisibility is set then element is considered visible if only part of it is visible.

@joshwnj
Copy link
Owner

joshwnj commented Jun 16, 2015

Nice idea, thanks @kompot ! Sorry I'm not merging straight away, I'd just like to take a bit of a closer look tomorrow morning and explore more how it impacts existing functionality. Probably write a new test case too. Will respond to this soon.

@kompot
Copy link
Collaborator Author

kompot commented Jun 16, 2015

Thanks, great!

@kof
Copy link
Collaborator

kof commented Jun 16, 2015

Suggestion: rename isVisible property to visibility which can have values: 'visible', 'hidden', 'partial' or similar ...

@kof
Copy link
Collaborator

kof commented Jun 16, 2015

onChange(visibility, rect)

@joshwnj
Copy link
Owner

joshwnj commented Jun 17, 2015

@kompot @kof all good suggestions.

I'm wondering whether we can find something backwards-compatible. What would you all think about leaving onChange to mean a change from "fully visible or not", and also adding a new optional onPartialChange callback which indicates a change from "at least partially visible or not visible at all".

@kompot would that work for your use-case?

@kompot
Copy link
Collaborator Author

kompot commented Jun 17, 2015

onPartialChange would work ok for me, so any way everybody agrees on.

But there might be some confusion. Consider element is fully visible, then it becomes partially visible. Should we fire onPartialChange? According to the name — may be. But logically I guess no. In my case definitely not.

@kof 's suggestion to make it enum instead of boolean seems reasonable to me.

@joshwnj
Copy link
Owner

joshwnj commented Jun 17, 2015

@kompot yeah the reason I'm thinking 2 separate callbacks instead of a single with enum value is that question of "when is the callback called?". I'm thinking that in most cases you would either care about full visibility or partial visibility, but not so much the transition from partial-to-full.

But I agree the naming I proposed could be tightened up to be clearer.

@joshwnj
Copy link
Owner

joshwnj commented Jun 17, 2015

Another option that would preserve backwards-compatibility:

  • add a threshold prop, which has a default value of 1.0.
  • the check function will calculate what percentage of the sensor is visible and give a value between 0.0 (fully hidden) and 1.0 (fully visible).
  • the onChange callback is only called when visibility crosses the threshold in either direction.

What do you think?

@kof
Copy link
Collaborator

kof commented Jun 17, 2015

I think with proper versioning and changelog, breaking changes are not an issue at all.

👎 for 2 callbacks, makes api more complex

Libs should not be opinionated. I can perfectly think of use cases where its important to know when element changes from partial to visible or hidden states.

@joshwnj
Copy link
Owner

joshwnj commented Jun 17, 2015

Sure, I agree that we don't want to overly complicate things here.

@kompot I've had a closer look and I think the way you've implemented it is good as it won't change the behaviour until you opt-in with the partialVisibility prop.

I'd like to consider a more comprehensive solution that allows you to get notifications about both partial and full visibility. Possibly removing the partialVisibility prop and making this the default behaviour. But as this will possibly be a breaking change I'll merge this PR for now. We'll want to add a test-case for partial visibility moving forward as well.

Thanks!

joshwnj added a commit that referenced this pull request Jun 17, 2015
@joshwnj joshwnj merged commit cffffff into joshwnj:master Jun 17, 2015
@joshwnj
Copy link
Owner

joshwnj commented Jun 17, 2015

@kompot published as v2.1.0

@kof
Copy link
Collaborator

kof commented Jun 17, 2015

@joshwnj I think @kompot agreed on my enum proposal, lets move it in this direction and release 3.0

@joshwnj
Copy link
Owner

joshwnj commented Jun 17, 2015

Yes, I think it's a good plan. We can also see if there are any other breaking-changes needing to be made to roll into 3.0

Before then, it's a good opportunity to try partial visibility some more and see how it affects things. Eg. I'm thinking a "threshold" prop will definitely be useful because at the moment even 1px of visibility will trigger onChange, and in a lot of cases you'd want it to be less sensitive.

I'll create a new issue to discuss any other things people want to see in 3.0

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.

3 participants