-
Notifications
You must be signed in to change notification settings - Fork 507
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
Correct visibility when fade is chained #2597
Conversation
When a new fade is called inside the onComplete event of first fade out, then the opacity fades as expected but the visibility will not be set back to visible. This happens because the first fade sets the visibility after the fade is done. So the onComplete actually fires before the visibility is set.
element.set('tween', { | ||
duration: 100, | ||
onComplete: function (){ | ||
if(runOnce){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tab/space problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ibolmo will fix, thanks
(sorry it took me some time to answer on this) So, I would like us to follow @ibolmo 's suggestion and simplify this method. The docs say:
The code needed to support what the Docs say
Question
|
Note your change would be Question 1: Nope. if else is more expensive than a simple conditional. |
@ibolmo, you were right about the "note", i edited/corrected above. About One option is to add this line under, inside the
This will also be applied in other Another option, based on the one above, is adding a flag on the storage, and retrieve/reset inside the Otherwise I see only the "chain option" as is in the PR, based on what @arian added to solve past problems; i.e. that the |
I'm confused. Why isn't this working already. Looking at render: function(element, property, value, unit){
element.setStyle(property, this.serve(value, unit));
}, Therefore visibility should be taken care of because of: setStyle: function(property, value){
if (property == 'opacity'){
if (value != null) value = parseFloat(value);
setOpacity(this, value);
return this;
} and var setOpacity = (hasOpacity ? function(element, opacity){
element.style.opacity = opacity;
} : (hasFilter ? function(element, opacity){
if (!element.currentStyle || !element.currentStyle.hasLayout)
element.style.zoom = 1;
if (opacity == null || opacity == 1){
setFilter(element, reAlpha, '');
if (opacity == 1 && getOpacity(element) != 1) setFilter(element, reAlpha,
'alpha(opacity=100)');
} else {
setFilter(element, reAlpha, 'alpha(opacity=' + (opacity * 100).limit(0,
100).round() + ')');
}
} : setVisibility)); On Mon, May 26, 2014 at 5:45 PM, Sergio Crisostomo <notifications@github.com
|
@ibolmo If we change this behaviour, so that when If we set fade: function(method){
var tween = this.get('tween');
if (!method || method == 'toggle') method = this.getStyle('opacity') ? 'out' : 'in';
//<1.3compat>
if (arguments.length == 2) {
tween.set('opacity', arguments[0]);
tween.start('opacity', arguments[1]);
return this;
}
//</1.3compat>
if (method == 'in') tween.start('opacity', 1);
if (method == 'out') tween.start('opacity', 0);
if (method == 'show') tween.set('opacity', 1);
if (method == 'hide') tween.set('opacity', 0);
if (typeof method == 'number') tween.start('opacity', method);
var to = tween.to[0].value, visible = this.getStyle('visibility') == 'visible';
function changeVisibility(value, $tween){
if ($tween.$chain.length){
$tween.chain(function (){
this.element.setStyle('visibility', value);
this.callChain();
});
} else {
this.setStyle('visibility', value);
}
};
if (to && !visible) changeVisibility.call(this, 'visible', tween);
if (to == 0 && visible) changeVisibility.call(this, 'hidden', tween);
return this;
}, Would be nice to have @arian looking at this refactor since he was the one to fix the |
Let's wait on @arian but I'd say drop the visibility. If we dropped it in On Tue, May 27, 2014 at 6:42 AM, Sergio Crisostomo <notifications@github.com
|
If I recall correctly, we made the "stop setting visibility in setStyle" change for 1.4.0, which was a logical change. But then we had to very quickly release 1.4.1 to fix fade, because our implementation of that always set visibility to hidden after fading opacity to 0 (arguably makes sense to do that anyway, I wouldn't be in favour of "just" dropping the setting of visibility in fade, expecting problems if we do. We should first investigate if we want to do such a breaking change. #2074 and #2081 provide more context. |
Based on that I would say we should add: Warning pseudo tween.addEvent('complete', function(){
(opacity == 0) ? hide : visibile;
}); On Tue, May 27, 2014 at 8:12 AM, Tim Wienk notifications@github.com wrote:
|
@arian could you give your opinion here? |
What @timwienk said. So instead of refactoring the entire method, it should do exactly the same as it does now, but slightly different so it sets the visibility at the right moment (which was the original issue). |
022928b
to
31cd649
Compare
Really nice feedback from you guys! I made now a new approach and cleaned the PR. |
31cd649
to
b3c009e
Compare
this.setStyle('visibility', to == 0 ? 'hidden' : 'visible'); | ||
} else if (to != 0){ | ||
if (fade.$chain.length){ | ||
fade.chain(function (){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove space in function ()
same in L103.
After the space is cleaned, this LGTM. I think we can invest more time in this, but it's something that I think we can revisit when we refactor for 1.6. |
Correct visibility when fade is chained
fixes #2593
When a new fade is called inside the onComplete event of first fade out,
then the opacity fades as expected but the visibility will not be set back to
visible
. This happens because the first fade sets the visibility after the fade is done. So the onComplete actually fires before the visibility is set.related/history #2074