-
Notifications
You must be signed in to change notification settings - Fork 25.6k
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
greedy-nav is not reliable on small devices #2664
Comments
I believe the issue is JavaScript related. The script that determines how wide the nav space is changes depending on when it tries to figure out that value. When you have a logo it could determine the width differently depending on if the image loads before or after. This is why it’s inconsistent. Perhaps someone better with JavaScript has a fix. I forked the script from the greedy nav repo so not sure how to improve it. |
Thank you for your answer! I'm not at all an expert JavaScript programmer, but I'll be testing other "priority+ navigation" implementations, to see if I can get any good results with them, or maybe get some insights on how to improve the current greedy nav implementation. Or maybe none of those, and just learn a bunch in the process. |
Hey, I come with good news! After 2-3 days of intense testing and searching, I'm pretty sure I've managed to identify and solve the bug! 1st bug:Behavior:
note: 2nd bug:Behavior:
The way this is implemented makes sure it works even if the the user adds another image on the navbar, for some reason. After this 2 fixes, the bugs are not reproducible anymore. If it is relevant, I could make a pull request, just tell me. |
Thanks for digging into this issue, great work uncovering the issues. An since not everyone will have a header logo I feel bad including unnecessary JavaScript if it's not needed. Not sure if there's a better way to handle that and not overcomplicate things. That said I'm all for your fix on the first bug. Could you submit a PR and then myself and others could test it out. Thanks again! |
Hey no problem! I'm just trying to give back something as this theme is being so useful to me. |
I've come up with something based on imagesloaded and relevant discussions here and here. This doesn't add any dependencies and simply doesn't do anything if the page doesn't have a logo. If it does have a logo, it checks if it's loaded before continuing:
I've tested with Chrome/Firefox mobile browsers, as well as Instagram and Telegram's in-app browsers and it worked 100% of the time, even if the logo has a broken src. It should work with legacy browsers as well.
|
After thinking a little bit more, I've realized I wasn't using jQuery enough, and the code was overcomplicated because of that. I've come up with this simpler version, using more jQuery (since it is already a dependency), that works the same, but is significantly cleaner:
|
Nice work. |
Thank you. |
After some more intense work and study I have more things to share: I was testing my code on a 320px wide Iphone device I have access to, and I couldn't understand why in some test cases the first navbar item was being shown partially hidden under the title. I knew this wasn't a race condition issue anymore, because, unlike before, this behavior happend 100% of the times. I also knew this wasn't related to the code I've added, because using the unmodified version of the script I've also got the same results. This got me to do yet another deep dive into the script, and then I had to face something that had me boggled since I've started analyzing the greedy-nav script: The way it calculates the available space for links on the navbar. The relevant line is The width of the visible links element decreased by 10 pixels is an educated guess of the available space, but it is not precise. The developers of greedy-nav are certainly not to blame, as doing precise calculations adds a considerable amount of complexity, and in my opinion, defeats the purpose of it as a versatile and lightweight priority+ navbar implementation. If you want to calculate the precise available space for navItems, you need to take the navbar inner width and decrease from it the width of every visible element (except for the links). But how different the precise measurement and the approximation could be, you may ask? On a page without a logo, I've measured a 10px difference on a 360px width Android device, and a remarkable 30px difference on the mentioned 320px width Iphone device. Thats not at all insignificant as it represents +9% of the Iphone device width and can easily result in consistent glitches on some devices in some pages (as in my test case). As we're talking about precision (and good use of space), there's 2 another issues.
So I've implemented in the script all those things I've mentioned. I've done my best, doing performance tests all along, to make this the less performance greedy as I could. This of course inevitably added time complexity to the code, since I've added some grabby calculations (particularly elements widths measurements). That being said, at least in my test cases the added complexity is not at all performance critical, nor can it be perceived by the user, or outside of performance testing. This is tested both with and without the logo and the search toggle. I'm proud to say this adds what I call "pixel perfect responsivity". :)
|
All sounds good to me. Eager to test this out in a PR. |
I've opened the Pull request 2674. |
This issue has been automatically marked as stale because it has not had recent activity. If this is a bug and you can still reproduce this error on the If this is a feature request, please consider whether it can be accomplished in another way. If it cannot, please elaborate on why it is core to this project and why you feel more than 80% of users would find this beneficial. This issue will automatically be closed in 7 days if no further activity occurs. Thank you for all your contributions. |
Environment
Expected behavior
Greedy nav is supposed to always show the same amount of visible-links and hidden-links, and it doesn't seem the case.
I've created two new repositories using the remote theme starter to demonstrate issues I've been having consistently using minimal mistakes. One of them (mmbasic) I've made no changes, and the other (mmlogo) I've added the bio-photo as the logo just to show another example which seem to be easier to reproduce the bug.
This is how the pages will load most of the time on my Android device, which is the expected behaviour:
mmbasic:
https://imgur.com/z5jEdB8
mmlogo:
https://imgur.com/ZAJCwVq
Steps to reproduce the behavior
This is how the pages are rendered sometimes, when opening the page for the first time:
mmbasic:
https://imgur.com/2BbpxzD (Notice "Categories" is gone)
https://imgur.com/0h1o70I (All links are visible, "Posts" is hidden because of overflow and "Categories" is hidden behind the title)
mmlogo:
https://imgur.com/n1jpuVV ("Posts" is hidden behind the title)
To reproduce it, simply open one of the pages on a mobile (android) device: https://www.miguel.dev.br/mmbasic/ or https://www.miguel.dev.br/mmlogo/
Other
availableSpace = $vlinks.width() - 10;
line to a calculation of the window's width decreased by some "rem" (font-size) value, which was obviously dumb and only viable with my particular setup of "logo + title".I'm about to get my hands dirty again trying to implement https://github.com/gijsroge/priority-navigation or one of the other alternatives listed there on one of my two projects that are using Minimal Mistakes to get a better fix for myself, and depending on my results I'll share here. Thought I would open this issue before though.
Needless to say, I'm in love with Minimal Mistakes, it's a really great job!
The text was updated successfully, but these errors were encountered: