-
Notifications
You must be signed in to change notification settings - Fork 14
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
feat(FEC-9481): distributed keyboard handler to decorator #464
Conversation
create keyboard decorator event to implement in each compnent which use keyboard event on player area.
* @private | ||
*/ | ||
_shouldHandledKeyboardEvent(): boolean { | ||
return this.props.isKeyboardEnable && !this.props.shareOverlay && !this.props.playerNav; |
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.
share overlay can set isKeyboardEnable: false
by itself instead of this, no?
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.
No, if user will change the isKeyboardEnable
to false
and then share will change it to false
as well and then true
the final state of isKeyboardEnable
will be true
and that's not what the user wants.
There is another solution that could contain internalKeyboard
state and externalKeyboard
state but I don't think it's needed here.
src/components/language/language.js
Outdated
@@ -76,6 +79,38 @@ class Language extends Component { | |||
*/ | |||
componentDidMount() { | |||
this.props.eventManager.listen(document, 'click', e => this.handleClickOutside(e)); | |||
this.props.addKeyboardHandler({code: KeyMap.C}, event => { | |||
event.preventDefault(); |
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.
import this handler from keyboard.js
. we can't maintain code like this twice.
same for all new handlers in this change
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.
we'll not.
keyboard.js
is deprecated if someone wants to use it he'll need to write the logic by himself I don't think we need to maintain this code anymore.
if (!this._keyboardListeners[keyCode]) { | ||
this._keyboardListeners[keyCode] = callback; | ||
} | ||
window.console.log(this._keyboardListeners[keyCode]); |
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.
delete
* @private | ||
*/ | ||
_shouldHandledKeyboardEvent(): boolean { | ||
return this.props.isKeyboardEnable && !this.props.shareOverlay && !this.props.playerNav; |
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.
No, if user will change the isKeyboardEnable
to false
and then share will change it to false
as well and then true
the final state of isKeyboardEnable
will be true
and that's not what the user wants.
There is another solution that could contain internalKeyboard
state and externalKeyboard
state but I don't think it's needed here.
src/components/language/language.js
Outdated
@@ -76,6 +79,38 @@ class Language extends Component { | |||
*/ | |||
componentDidMount() { | |||
this.props.eventManager.listen(document, 'click', e => this.handleClickOutside(e)); | |||
this.props.addKeyboardHandler({code: KeyMap.C}, event => { | |||
event.preventDefault(); |
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.
we'll not.
keyboard.js
is deprecated if someone wants to use it he'll need to write the logic by himself I don't think we need to maintain this code anymore.
* @extends {Component} | ||
*/ | ||
class KeyboardEventProvider extends Component { | ||
_events: Object = {keydown: 1, keyup: 2, keypress: 3}; |
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.
keypress is deprecated, please remove
https://developer.mozilla.org/en-US/docs/Web/API/Document/keypress_event
* @returns {void} | ||
*/ | ||
componentWillUnmount(): void { | ||
const {eventManager, playerContainer} = this.props; |
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.
withEventManager
destroys the event manager on componentWillUnmount
, so no need for this
* @memberof withKeyboardEvent | ||
*/ | ||
render(): React$Element<any> | void { | ||
return <WrappedComponent {...this.props} registerEvents={eventHandlers => this.registerEvents(eventHandlers)} />; |
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.
registerEvents
as an API is too generic name.
If we are passing this as named prop it should be understood it is addKeyboardBindings or addKeyboardEvent
src/components/language/language.js
Outdated
|
||
_keyboardEventHandlers: Array<KeyboardEventHandlers> = [ | ||
{ | ||
eventType: 'keydown', |
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.
each event should have
{
eventType?,
key,
handler
}
cause each key binding can have different eventType potentially
Also, eventType should be optional cause keyDown is the 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.
I grouped by eventType to make it clear
[{eventType:keydown,
handlers:[]}]
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.
Handler -> {key:keyboardKey, action:function}
|
||
const COMPONENT_NAME = 'KEYBOARD_PROVIDER'; | ||
|
||
export const keyboardEvents: Object = {keydown: 1, keyup: 2}; |
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.
ENUM is CAPITAL snake case KEYBOARD_EVENTS KEYDOWN KEYUP
Description of the Changes
create keyboard decorator event to implement in each component which use keyboard event on player area.
Solves: FEC-9481
CheckLists