1
1
import * as React from "react" ;
2
- import CONSTANTS , { SENSOR_LIST , GESTURES } from "../../../constants" ;
2
+ import { SENSOR_LIST , GESTURES , CONSTANTS } from "../../../constants" ;
3
3
import { ISensorProps , ISliderProps } from "../../../viewUtils" ;
4
4
import { ThreeDimensionSlider } from "./threeDimensionSlider/ThreeDimensionSlider" ;
5
5
import { Dropdown } from "../../Dropdown" ;
@@ -13,6 +13,7 @@ const MOTION_SLIDER_PROPS_X: ISliderProps = {
13
13
minValue : - 1023 ,
14
14
type : SENSOR_LIST . MOTION_X ,
15
15
} ;
16
+
16
17
const MOTION_SLIDER_PROPS_Y : ISliderProps = {
17
18
axisLabel : "Y" ,
18
19
maxLabel : "Front" ,
@@ -21,6 +22,7 @@ const MOTION_SLIDER_PROPS_Y: ISliderProps = {
21
22
minValue : - 1023 ,
22
23
type : SENSOR_LIST . MOTION_Y ,
23
24
} ;
25
+
24
26
const MOTION_SLIDER_PROPS_Z : ISliderProps = {
25
27
axisLabel : "Z" ,
26
28
maxLabel : "Down" ,
@@ -39,6 +41,7 @@ const MOTION_SENSOR_PROPERTIES: ISensorProps = {
39
41
] ,
40
42
unitLabel : "Lux" ,
41
43
} ;
44
+
42
45
interface IProps {
43
46
axisValues : {
44
47
X_AXIS : number ;
@@ -51,56 +54,68 @@ interface IProps {
51
54
}
52
55
53
56
const GESTURE_BUTTON_MESSAGE = "Send Gesture" ;
57
+ const MANUAL_ACCELERATION_MESSAGE = "Set the acceleration manually here" ;
54
58
55
- export const Accelerometer : React . FC < IProps > = ( props : IProps ) => {
56
- return (
57
- < div className = "AccelerometerBar" >
58
- < br />
59
- { /* Implement Gestures Here */ }
60
- < Dropdown options = { GESTURES } onSelect = { props . onSelectGestures } />
61
- < SensorButton
62
- label = { GESTURE_BUTTON_MESSAGE }
63
- onMouseDown = { ( ) => {
64
- if ( props . onSendGesture ) {
65
- props . onSendGesture ( true ) ;
66
- }
67
- } }
68
- onMouseUp = { ( ) => {
69
- if ( props . onSendGesture ) {
70
- props . onSendGesture ( false ) ;
71
- }
72
- } }
73
- onKeyDown = { ( e : React . KeyboardEvent ) => {
74
- handleOnKeyDown ( e , props . onSendGesture ) ;
75
- } }
76
- onKeyUp = { ( e : React . KeyboardEvent ) => {
77
- handleOnKeyUp ( e , props . onSendGesture ) ;
78
- } }
79
- type = "gesture"
80
- />
81
- < ThreeDimensionSlider
82
- axisProperties = { MOTION_SENSOR_PROPERTIES }
83
- onUpdateValue = { props . onUpdateValue }
84
- axisValues = { props . axisValues }
85
- />
86
- </ div >
87
- ) ;
88
- } ;
89
- const handleOnKeyDown = (
90
- e : React . KeyboardEvent ,
91
- onSendGesture ?: ( isActive : boolean ) => void
92
- ) => {
93
- if ( e . key === CONSTANTS . KEYBOARD_KEYS . ENTER ) {
94
- console . log ( "gestures" ) ;
95
- if ( onSendGesture ) onSendGesture ( true ) ;
96
- }
97
- } ;
98
- const handleOnKeyUp = (
99
- e : React . KeyboardEvent ,
100
- onSendGesture ?: ( isActive : boolean ) => void
101
- ) => {
102
- if ( e . key === CONSTANTS . KEYBOARD_KEYS . ENTER ) {
103
- console . log ( "gesturesUp" ) ;
104
- if ( onSendGesture ) onSendGesture ( false ) ;
59
+ export class Accelerometer extends React . Component < IProps > {
60
+ private sensorButtonRef : React . RefObject < SensorButton > = React . createRef ( ) ;
61
+ render ( ) {
62
+ return (
63
+ < div className = "AccelerometerBar" >
64
+ < br />
65
+ < Dropdown
66
+ options = { GESTURES }
67
+ onSelect = { this . props . onSelectGestures }
68
+ />
69
+ < SensorButton
70
+ ref = { this . sensorButtonRef }
71
+ label = { GESTURE_BUTTON_MESSAGE }
72
+ onMouseDown = { ( ) => {
73
+ if ( this . props . onSendGesture ) {
74
+ this . props . onSendGesture ( true ) ;
75
+ }
76
+ } }
77
+ onMouseUp = { ( ) => {
78
+ if ( this . props . onSendGesture ) {
79
+ this . props . onSendGesture ( false ) ;
80
+ }
81
+ } }
82
+ onKeyDown = { ( e : React . KeyboardEvent ) => {
83
+ this . handleOnKeyDown ( e , this . props . onSendGesture ) ;
84
+ } }
85
+ onKeyUp = { ( e : React . KeyboardEvent ) => {
86
+ this . handleOnKeyUp ( e , this . props . onSendGesture ) ;
87
+ } }
88
+ type = "gesture"
89
+ />
90
+ < br />
91
+ < p > { MANUAL_ACCELERATION_MESSAGE } </ p >
92
+
93
+ < ThreeDimensionSlider
94
+ axisProperties = { MOTION_SENSOR_PROPERTIES }
95
+ onUpdateValue = { this . props . onUpdateValue }
96
+ axisValues = { this . props . axisValues }
97
+ />
98
+ </ div >
99
+ ) ;
105
100
}
106
- } ;
101
+ private handleOnKeyDown = (
102
+ e : React . KeyboardEvent ,
103
+ onSendGesture ?: ( isActive : boolean ) => void
104
+ ) => {
105
+ if ( e . key === CONSTANTS . KEYBOARD_KEYS . ENTER ) {
106
+ this . sensorButtonRef ! . current ! . setButtonClass ( true ) ;
107
+ if ( onSendGesture ) onSendGesture ( true ) ;
108
+ }
109
+ } ;
110
+
111
+ private handleOnKeyUp = (
112
+ e : React . KeyboardEvent ,
113
+ onSendGesture ?: ( isActive : boolean ) => void
114
+ ) => {
115
+ if ( e . key === CONSTANTS . KEYBOARD_KEYS . ENTER ) {
116
+ this . sensorButtonRef ! . current ! . setButtonClass ( false ) ;
117
+
118
+ if ( onSendGesture ) onSendGesture ( false ) ;
119
+ }
120
+ } ;
121
+ }
0 commit comments