-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Conversation
@@ -14,7 +14,8 @@ | |||
* limitations under the License. | |||
*/ | |||
|
|||
import {Messaging, WindowPortEmulator} from './messaging.js'; | |||
import {Messaging, WindowPortEmulator} from './messaging'; | |||
import {TouchHandler} from './touch_handler'; |
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.
Please change file name to touch-handler
.
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.
done
@@ -231,6 +272,7 @@ export class Messaging { | |||
this.sendResponseError_(requestId, message.name, reason); | |||
}); | |||
} | |||
return true; |
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.
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?
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.
removed
@@ -160,6 +161,8 @@ export class AmpViewerIntegration { | |||
|
|||
listenOnce( | |||
this.win, 'unload', this.handleUnload_.bind(this, messaging)); | |||
|
|||
new TouchHandler(this.win, messaging); |
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.
Let's add viewer.getParam('swipe') == '1'
right away?
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.
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.
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.
done
constructor(win, messaging) { | ||
/** @const {!Window} */ | ||
this.win = win; | ||
/** @private {!./messaging.Messaging} */ |
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.
@const
?
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.
done
listenForTouchEvents() { | ||
const handleEvent = this.handleEvent_.bind(this); | ||
|
||
listen(this.win, 'touchstart', handleEvent); |
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.
Let's listen on this.win.document
. Window is not cross-platform.
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.
done
handleEvent_(e) { | ||
switch (e.type) { | ||
case 'touchstart': | ||
this.tracking_ = true; |
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.
Is there any scroll direction protection to avoid forwarding 100% of events?
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.
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.
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.
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_) { |
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.
Let's add TODO(...): switch to passive events and pan-touch action
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.
done
return this.requestFullOverlay_(); | ||
case 'cancelFullOverlay': | ||
return this.cancelFullOverlay_(); | ||
case 'pushHistory': |
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.
FYI. replaceHistory is also a WIP @muxin. Though not really relevant to this cl.
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.
acknowledged.
@@ -160,6 +161,8 @@ export class AmpViewerIntegration { | |||
|
|||
listenOnce( | |||
this.win, 'unload', this.handleUnload_.bind(this, messaging)); | |||
|
|||
new TouchHandler(this.win, messaging); |
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.
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; |
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.
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.
/cc @brandondiamond |
case 'touchmove': | ||
this.forwardEvent_(e); | ||
break; | ||
default: |
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.
nit: remove
* 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
* 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
No description provided.