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 touch support in our carousel #25776

Merged
merged 12 commits into from
Oct 20, 2018
Merged

Add touch support in our carousel #25776

merged 12 commits into from
Oct 20, 2018

Conversation

Johann-S
Copy link
Member

@Johann-S Johann-S commented Mar 3, 2018

  • Add unit test
  • Documentation

Fixes: #17118

@Johann-S Johann-S force-pushed the v4-carousel-hammer branch 2 times, most recently from 6951e04 to e91aee5 Compare March 3, 2018 21:15
@XhmikosR
Copy link
Member

XhmikosR commented Mar 3, 2018

Its quite a big addition... Can't we do the basic stuff ourselves?

@@ -2,6 +2,8 @@
<script>window.jQuery || document.write('<script src="{{ site.baseurl }}/assets/js/vendor/jquery-slim.min.js"><\/script>')</script>

<script src="{{ site.baseurl }}/assets/js/vendor/popper.min.js"{% if site.github %} integrity="{{ site.cdn.popper_hash }}" crossorigin="anonymous"{% endif %}></script>
<script src="{{ site.baseurl }}/assets/js/vendor/hammer.min.js"{% if site.github %} integrity="{{ site.cdn.hammer_hash }}" crossorigin="anonymous"{% endif %}></script>
Copy link
Member

@XhmikosR XhmikosR Mar 3, 2018

Choose a reason for hiding this comment

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

You need to add it in package.json (uglify) too for the docs package.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's strange but Popper isn't in our doc-minify task 🤔

Copy link
Member

Choose a reason for hiding this comment

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

True, indeed. Just leave it as is and I'll give it a go in the next days and let you know. :)

@Johann-S
Copy link
Member Author

Johann-S commented Mar 3, 2018

I don't think it's a big change here, we add an optionnal lib, if folks need a touch support that's all

@XhmikosR
Copy link
Member

XhmikosR commented Mar 3, 2018

Sure, but can't we have the basic functionality without a 20 KB file? I recall you had a branch in the past.

@Johann-S
Copy link
Member Author

Johann-S commented Mar 3, 2018

This won't be added in our dist files, so we won't add 20 kb

I'm not in favor of adding logics about touch detection and swipe detection when they are libs which can do that better than me

@XhmikosR
Copy link
Member

XhmikosR commented Mar 3, 2018

I agree on that, but then one would say why don't you support jQuery mobile or whatever other lib there's out there.

Anyway, I'm not against this, I just want us to think it through.

@Johann-S
Copy link
Member Author

Johann-S commented Mar 3, 2018

I think HammerJS is a good choice, Angular chose HammerJS too

@Johann-S Johann-S force-pushed the v4-carousel-hammer branch 2 times, most recently from a8b3276 to 89fcc36 Compare March 4, 2018 00:05
if (this._config.keyboard) {
$(this._element)
.on(Event.KEYDOWN, (event) => this._keydown(event))
}

if (touchSupported) {
this.hammer.on(Event.SWIPELEFT, () => this.next())
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't here a check quired if hammer support is enabled or the hammer reference exists to prevent a reference error? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep that's true nice catch 👍

@Johann-S Johann-S force-pushed the v4-carousel-hammer branch 2 times, most recently from 502272d to bef1560 Compare March 4, 2018 16:28
@Johann-S Johann-S changed the title WIP: Add touch support on our carousel with Hammer Add touch support on our carousel with Hammer Mar 4, 2018
@@ -20,11 +20,15 @@
}())
</script>
<script src="../../assets/js/vendor/popper.min.js"></script>
<script src="../../assets/js/vendor/hammer.min.js"></script>
Copy link
Member

Choose a reason for hiding this comment

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

Maybe load this from node_modules?

Copy link
Member

Choose a reason for hiding this comment

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

Scratch that, it's a peerDependency. How about using the CDN instead of adding yet one more file?

Copy link
Member Author

Choose a reason for hiding this comment

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

yep sure !

@@ -17,6 +17,8 @@ module.exports = (config) => {
files: [
jqueryFile,
'assets/js/vendor/popper.min.js',
'assets/js/vendor/hammer.min.js',
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't be needed.

@Johann-S Johann-S force-pushed the v4-carousel-hammer branch 2 times, most recently from 1c34111 to 5823397 Compare April 10, 2018 07:50
@Johann-S
Copy link
Member Author

@patrickhlauke everything is fine now, can you confirm it ? Thanks 👍

js/src/carousel.js Outdated Show resolved Hide resolved
@Johann-S Johann-S force-pushed the v4-carousel-hammer branch 3 times, most recently from 8bcaeb3 to 652161f Compare October 16, 2018 11:46
@patrickhlauke
Copy link
Member

i can have one last actual live test later tonight on my phones and Surface, but conceptually this all looks good to me now

@Johann-S
Copy link
Member Author

It works fine for me 👍

/CC @XhmikosR if you want to do some tests too

@patrickhlauke
Copy link
Member

https://deploy-preview-25776--twbs-bootstrap4.netlify.com/docs/4.1/components/carousel/ seems to be working fine now (tested there as i've not got my build/test environment all set up again at the moment) ... but man, the aggressive caching/service worker really gets in the way of quickly checking changes out sometimes...

possibly more related to netlify here: on IE11 and Edge, I found that the carousels are unresponsive for quite a long time after page load (unless you kick them into action if there are the "<" / ">" controls). it seems the browser is waiting for some file to load from the network, and only once it gives up does it run the onload stuff.

@XhmikosR
Copy link
Member

There is actually no service worker on netlify; it doesn't run the production scripts on purpose.

@patrickhlauke
Copy link
Member

There is actually no service worker on netlify; it doesn't run the production scripts on purpose.

i found i had to force refresh (and in the case of Firefox, go in and delete session storage etc) while testing. not quite sure why then...aggressive caching? i see pwa.js is loaded as well if that means anything...i'm actually not sure if this is related to service worker or not.

in any case, it seems to be the carbon ads json that is never loaded (shows as "(pending)" in the F12 tools' network tab). only once the browser gives up trying to load it is the JS on page load actually executed.

anyway, that's all tangential. the carousel swipe thing now seems to work nicely

@XhmikosR
Copy link
Member

Correction, the service worker is being there albeit broken on dev mode. I definitely need to finish #26868 and #27320.

I'm gonna look into this branch later and get back to you guys.

@XhmikosR
Copy link
Member

This no longer works for me with Firefox 63 devtools and say S9 emulation. It works fine with Chrome though.

@Johann-S
Copy link
Member Author

@XhmikosR that's strange it works perfectly on my Android with Firefox

@XhmikosR
Copy link
Member

Well a real touch device is not the same as the emulator :) That being said I don't know if we should even care about it. I just thought I'd report it since Firefox is my main browser and this worked in the previous patches.

@Johann-S
Copy link
Member Author

I think we should test using BrowserStack here

@patrickhlauke
Copy link
Member

patrickhlauke commented Oct 20, 2018

The reason why it's not working in Firefox's device emulation is that we check for navigator.maxTouchPoints (part of the pointer events spec), but device emulation doesn't fake this value. So touchSupported evaluates to false in the code, and none of the swipe code is attached. tl;dr: it's the fault of Firefox's emulation.

firefox-devtools-emulation-touch
https://patrickhlauke.github.io/touch/tests/pointer-multitouch-detect.html

[edit: filed a bug here: Bug 1500672 - Responsive Design Mode with touch simulation: navigator.maxTouchPoints still zero]

@mdo mdo mentioned this pull request Oct 20, 2018
@XhmikosR
Copy link
Member

All right, let's merge this then. Great work everyone!

@XhmikosR XhmikosR changed the title Add touch support on our carousel Add touch support in our carousel Oct 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants