This repository has been archived by the owner on Dec 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate accelerometer from gestures
- Loading branch information
1 parent
4fa9340
commit 4c32700
Showing
5 changed files
with
135 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import * as React from "react"; | ||
import SensorButton from "../SensorButton"; | ||
import { Dropdown } from "../../Dropdown"; | ||
import CONSTANTS, { GESTURES } from "../../../constants"; | ||
|
||
const GESTURE_BUTTON_MESSAGE = "Send Gesture"; | ||
interface IProps { | ||
onSelectGestures?: (event: React.ChangeEvent<HTMLSelectElement>) => void; | ||
onSendGesture?: (isActive: boolean) => void; | ||
} | ||
export class Gesture extends React.Component<IProps> { | ||
private sensorButtonRef: React.RefObject<SensorButton> = React.createRef(); | ||
render() { | ||
return ( | ||
<div | ||
className="gesture" | ||
style={{ | ||
display: "flex", | ||
flexDirection: "column", | ||
justifyContent: "space-between", | ||
height: "75px", | ||
}} | ||
> | ||
<Dropdown | ||
name="gesture selection" | ||
options={GESTURES} | ||
onSelect={this.props.onSelectGestures} | ||
/> | ||
<SensorButton | ||
ref={this.sensorButtonRef} | ||
label={GESTURE_BUTTON_MESSAGE} | ||
onMouseDown={() => { | ||
if (this.props.onSendGesture) { | ||
this.props.onSendGesture(true); | ||
} | ||
}} | ||
onMouseUp={() => { | ||
if (this.props.onSendGesture) { | ||
this.props.onSendGesture(false); | ||
} | ||
}} | ||
onKeyDown={this.handleOnKeyDown} | ||
onKeyUp={this.handleOnKeyUp} | ||
type="gesture" | ||
/> | ||
</div> | ||
); | ||
} | ||
private handleOnKeyDown = (e: React.KeyboardEvent) => { | ||
if (e.key === CONSTANTS.KEYBOARD_KEYS.ENTER) { | ||
this.sensorButtonRef!.current!.setButtonClass(true); | ||
if (this.props.onSendGesture) { | ||
this.props.onSendGesture(true); | ||
} | ||
} | ||
}; | ||
|
||
private handleOnKeyUp = ( | ||
e: React.KeyboardEvent, | ||
onSendGesture?: (isActive: boolean) => void | ||
) => { | ||
if (e.key === CONSTANTS.KEYBOARD_KEYS.ENTER) { | ||
this.sensorButtonRef!.current!.setButtonClass(false); | ||
|
||
if (this.props.onSendGesture) { | ||
this.props.onSendGesture(false); | ||
} | ||
} | ||
}; | ||
} |