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

touch forwarding from ampdoc to viewer #7563

Merged
merged 20 commits into from
Feb 25, 2017
Merged

Conversation

chenshay
Copy link
Contributor

No description provided.

@@ -14,7 +14,8 @@
* limitations under the License.
*/

import {Messaging, WindowPortEmulator} from './messaging.js';
import {Messaging, WindowPortEmulator} from './messaging';
import {TouchHandler} from './touch_handler';
Copy link
Contributor

Choose a reason for hiding this comment

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

Please change file name to touch-handler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -231,6 +272,7 @@ export class Messaging {
this.sendResponseError_(requestId, message.name, reason);
});
}
return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is new return type necessary? If yes, please add @return to jsdoc and document. Though, since we throw an error above, it looks like it's always true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

@@ -160,6 +161,8 @@ export class AmpViewerIntegration {

listenOnce(
this.win, 'unload', this.handleUnload_.bind(this, messaging));

new TouchHandler(this.win, messaging);
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add viewer.getParam('swipe') == '1' right away?

Copy link

Choose a reason for hiding this comment

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

Should this go in the cap parameter instead of being it's own parameter? I don't care, but if you want to switch to cap I'm happy to start using it for anything new.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

constructor(win, messaging) {
/** @const {!Window} */
this.win = win;
/** @private {!./messaging.Messaging} */
Copy link
Contributor

Choose a reason for hiding this comment

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

@const?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

listenForTouchEvents() {
const handleEvent = this.handleEvent_.bind(this);

listen(this.win, 'touchstart', handleEvent);
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's listen on this.win.document. Window is not cross-platform.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

handleEvent_(e) {
switch (e.type) {
case 'touchstart':
this.tracking_ = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any scroll direction protection to avoid forwarding 100% of events?

Copy link

Choose a reason for hiding this comment

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

The Google script does do some detection, which is what it uses tracking_ for. This was done primarily to support horizontal scrolling within an iframe. This is no longer possible so I think this should work without the detection. It would just be an optimization to add it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

after chatting offline w/ @ericfs, I'm removing the tracking_ as it's not really useful.

const msg = this.copyTouchEvent_(e);
this.messaging_.sendRequest(e.type, msg, false);
}
if (this.scrollLocked_) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add TODO(...): switch to passive events and pan-touch action

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@dvoytenko
Copy link
Contributor

@chenshay This looks great! But I'd recommend to also have @ericfs or @RJSumi to scan through this.

return this.requestFullOverlay_();
case 'cancelFullOverlay':
return this.cancelFullOverlay_();
case 'pushHistory':
Copy link

Choose a reason for hiding this comment

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

FYI. replaceHistory is also a WIP @muxin. Though not really relevant to this cl.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

acknowledged.

@@ -160,6 +161,8 @@ export class AmpViewerIntegration {

listenOnce(
this.win, 'unload', this.handleUnload_.bind(this, messaging));

new TouchHandler(this.win, messaging);
Copy link

Choose a reason for hiding this comment

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

Should this go in the cap parameter instead of being it's own parameter? I don't care, but if you want to switch to cap I'm happy to start using it for anything new.

handleEvent_(e) {
switch (e.type) {
case 'touchstart':
this.tracking_ = true;
Copy link

Choose a reason for hiding this comment

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

The Google script does do some detection, which is what it uses tracking_ for. This was done primarily to support horizontal scrolling within an iframe. This is no longer possible so I think this should work without the detection. It would just be an optimization to add it.

@ericfs
Copy link

ericfs commented Feb 22, 2017

/cc @brandondiamond

@chenshay chenshay changed the title DO NOT SUBMIT - IN PROGRESS - touch forwarding from ampdoc to viewer touch forwarding from ampdoc to viewer Feb 23, 2017
case 'touchmove':
this.forwardEvent_(e);
break;
default:
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: remove

@chenshay chenshay merged commit 750bb21 into ampproject:master Feb 25, 2017
@chenshay chenshay deleted the touch branch February 25, 2017 02:05
adelinamart pushed a commit that referenced this pull request Mar 1, 2017
* touch forwarding

* touch_handler

* touch events

* another

* rename

* bla

* copy partial event

* process touch events

* fix

* bla

* type

* remove mouse events

* resolving merge conflicts

* register handlers + scroll locking

* remove console.log

* fixes

* file rename

* unit tests

* unit tests

* lint
mrjoro pushed a commit to mrjoro/amphtml that referenced this pull request Apr 28, 2017
* touch forwarding

* touch_handler

* touch events

* another

* rename

* bla

* copy partial event

* process touch events

* fix

* bla

* type

* remove mouse events

* resolving merge conflicts

* register handlers + scroll locking

* remove console.log

* fixes

* file rename

* unit tests

* unit tests

* lint
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