Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

feat(sidenav): track sidenav visibility and enter / leave backdrop if needed #6486

Closed

Conversation

devversion
Copy link
Member

  • Revert scope value if sidenav is shown.
  • Throttle Resize Events

Fixes #4595

function revalidateVisibility() {
var lastValue = scope.isOpen;
if (isHidden(element, true, true) && scope.isOpen == true) scope.isOpen = false;
else if (!isHidden(element, true, true) && scope.isOpen == false) scope.isOpen = true;
Copy link
Member

Choose a reason for hiding this comment

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

Brackets, scope.isOpen == true is the same as scope.isOpen and ternary operator

@devversion devversion force-pushed the feat/sidenav-track-visibility branch 2 times, most recently from b89b094 to 950216f Compare January 1, 2016 21:33
@devversion
Copy link
Member Author

@EladBezalel - Completed all your suggestions, thanks for reviewing!

@@ -229,6 +229,9 @@ function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $animate,
var lastParentOverFlow;
var triggeringElement = null;
var promise = $q.when(true);
var skipSidenav = false;
var skipNextUpdate = false;
var $window = angular.element(window);
Copy link
Member

Choose a reason for hiding this comment

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

You can use DI to get $window

Copy link
Member Author

Choose a reason for hiding this comment

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

Will be better, yes!

@devversion devversion force-pushed the feat/sidenav-track-visibility branch 3 times, most recently from fcfff73 to b2d0548 Compare January 5, 2016 17:22
@devversion
Copy link
Member Author

@EladBezalel - Fixed the suggestions + Improved isHidden Method (more clear and less code) - Can you verify the new version?

*/
function isHidden(computedStyle, offsetParent) {
if (computedStyle && window.getComputedStyle(element[0]).display === 'none') return true;
if (offsetParent && element[0].offsetParent == null) return true;
Copy link
Member

Choose a reason for hiding this comment

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

why not doing

if (computedStyle && window.getComputedStyle(element[0]).display === 'none' ||
   offsetParent && !element[0].offsetParent) {
  return true;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes that's also possible, but I thought we should have a clear variant, because this method is really important and needs to be easy to understand, but if you want I can simplify the code?

@devversion devversion force-pushed the feat/sidenav-track-visibility branch from b2d0548 to 9fd9ed6 Compare January 9, 2016 10:01
scope.isOpen = false;
} else if (!isHidden(true, true) && !scope.isOpen) {
scope.isOpen = true;
}
Copy link
Member

Choose a reason for hiding this comment

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

Isn't that equals to:

scope.isOpen = !(isHidden(true, true) && scope.isOpen);

Copy link
Member Author

Choose a reason for hiding this comment

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

No that works not, because I noticed that we only should update if that if statements are true, and we should not set the scope always

Copy link
Member

Choose a reason for hiding this comment

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

Sorry i couldn't understand, are we watching for isOpen changes?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry for the late answer. Yes updateIsOpen (the actual method which triggers open and close animations) is called by watching isOpen.

@devversion devversion force-pushed the feat/sidenav-track-visibility branch 2 times, most recently from 6e426c1 to e8817ee Compare January 9, 2016 10:24
* @param computedStyle Check Computed Style
* @param offsetParent Check Offset Parent
*/
function isHidden(computedStyle, offsetParent) {
Copy link
Member

Choose a reason for hiding this comment

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

Is this function is generic enough to be on the util service?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, definitely, should I add it?

Copy link
Member

Choose a reason for hiding this comment

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

yes

Copy link
Member Author

Choose a reason for hiding this comment

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

Done 👍 Added to Util + added tests to validate the functionality.

}
});
var actions = [isOpen ? $animate.enter(backdrop, parent) : $animate.leave(backdrop)];
if (!skipSidenav) actions.push(isOpen ? $animate.removeClass(element, 'md-closed') : $animate.addClass(element, 'md-closed'));
Copy link
Member

Choose a reason for hiding this comment

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

Please break this line

Copy link
Member Author

Choose a reason for hiding this comment

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

Done ✋ I should definitely use that conventions (how I call it) in my next PR's so we would save much time 😄 - Already done in my newer PR's

@ThomasBurleson ThomasBurleson modified the milestone: 1.0.5 Feb 4, 2016
scope.isOpen = !!oldValue;
return;
}
element.toggleClass('md-closed', wasClosed);
Copy link
Member

Choose a reason for hiding this comment

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

Can't you reuse that?

element.removeClass('md-closed');
if ($mdUtil.isHidden(element, true, false) && !skipSidenav) {
  skipNextUpdate = true;
  scope.isOpen = !!oldValue;
}
element.toggleClass('md-closed', wasClosed);

Copy link
Member Author

Choose a reason for hiding this comment

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

No, won't work, because I need to revert the class before the scope watcher will be triggered.

Copy link
Member

Choose a reason for hiding this comment

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

element.removeClass('md-closed');
var isHidden = $mdUtil.isHidden(element, true, false);
element.toggleClass('md-closed', wasClosed);

if (isHidden && !skipSidenav) {
  skipNextUpdate = true;
  scope.isOpen = !!oldValue;
}

?

Copy link
Member Author

Choose a reason for hiding this comment

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

This still needs the return, but yes this will work, because we check before removing the class 👍

-> Updated

@ThomasBurleson ThomasBurleson modified the milestones: 1.0.5, 1.0.6 Feb 4, 2016
@EladBezalel EladBezalel added needs: review This PR is waiting on review from the team and removed needs: work labels Feb 6, 2016
@EladBezalel
Copy link
Member

@ThomasBurleson please review

@devversion devversion added the needs: rebase This PR needs to be rebased on the latest commits from master and conflicts need to be resolved label Mar 21, 2016
@ThomasBurleson ThomasBurleson modified the milestones: 1.0.6, 1.0.8 Apr 4, 2016
@ThomasBurleson ThomasBurleson modified the milestones: 1.0.8, Backlog Apr 21, 2016
@ThomasBurleson ThomasBurleson modified the milestones: - Backlog, Deprecated May 26, 2016
@devversion
Copy link
Member Author

@EladBezalel I think this PR is not really a high priority, not much developers are complaining about it. What do you think? Should we remove it from the deprecation progress?

@devversion devversion deleted the feat/sidenav-track-visibility branch June 2, 2016 10:15
@ThomasBurleson
Copy link
Contributor

This issue is closed as part of our ‘Surge Focus on Material 2' efforts.
For details, see our forum posting @ http://bit.ly/1UhZyWs.

@Splaktar Splaktar changed the title feat(sidenav): track sidenav vissibilty and enter / leave backdrop if needed feat(sidenav): track sidenav visibility and enter / leave backdrop if needed Jul 30, 2018
@Splaktar Splaktar removed needs: rebase This PR needs to be rebased on the latest commits from master and conflicts need to be resolved needs: review This PR is waiting on review from the team labels Jul 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants