diff --git a/src/widget/widget.js b/src/widget/widget.js index 11fe5c2..e2faeb1 100644 --- a/src/widget/widget.js +++ b/src/widget/widget.js @@ -88,13 +88,13 @@ class Widget extends React.Component { }; } - inputDataChanged(widget, data, controlID) { + inputDataChanged(widget, data, controlID, controlValue) { // controlID is the path to the widget customProperty that is changed (for example 'value') // modify the widget customProperty if (controlID !== '') { let updatedWidget = JSON.parse(JSON.stringify(widget)); - updatedWidget.customProperties[controlID] = data; + updatedWidget.customProperties[controlID] = controlValue; AppDispatcher.dispatch({ type: 'widgets/start-edit', token: this.state.sessionToken, @@ -118,7 +118,7 @@ class Widget extends React.Component { type: 'icData/inputChanged', ic: icID, signal: signal[0].index, - data + data: signal[0].scalingFactor * data }); } @@ -179,14 +179,14 @@ class Widget extends React.Component { return this.inputDataChanged(widget, value, controlID)} + onInputChanged={(value, controlID, controlValue) => this.inputDataChanged(widget, value, controlID, controlValue)} signals={this.state.signals} /> } else if (widget.type === 'NumberInput') { return this.inputDataChanged(widget, value, controlID)} + onInputChanged={(value, controlID, controlValue) => this.inputDataChanged(widget, value, controlID, controlValue)} signals={this.state.signals} /> } else if (widget.type === 'Slider') { @@ -194,7 +194,7 @@ class Widget extends React.Component { widget={widget} editing={this.props.editing} onWidgetChange={(w) => this.props.onWidgetStatusChange(w, this.props.index) } - onInputChanged={(value, controlID) => this.inputDataChanged(widget, value, controlID)} + onInputChanged={(value, controlID, controlValue) => this.inputDataChanged(widget, value, controlID, controlValue)} signals={this.state.signals} /> } else if (widget.type === 'Gauge') { diff --git a/src/widget/widgets/button.js b/src/widget/widgets/button.js index e3a11a0..e95e740 100644 --- a/src/widget/widgets/button.js +++ b/src/widget/widgets/button.js @@ -28,11 +28,16 @@ class WidgetButton extends Component { } } + static getDerivedStateFromProps(props, state){ + return { + pressed: props.widget.customProperties.pressed + } + } + onPress(e) { if (e.button === 0 && !this.props.widget.customProperties.toggle) { - this.setState({ pressed: true }); - this.valueChanged(this.props.widget.customProperties.on_value); + this.valueChanged(this.props.widget.customProperties.on_value, true); } } @@ -43,15 +48,14 @@ class WidgetButton extends Component { if (this.props.widget.customProperties.toggle) { nextState = !this.state.pressed; } - this.props.widget.customProperties.pressed = nextState; - this.setState({pressed: nextState}); - this.valueChanged(nextState ? this.props.widget.customProperties.on_value : this.props.widget.customProperties.off_value); + this.valueChanged(nextState ? this.props.widget.customProperties.on_value : this.props.widget.customProperties.off_value, nextState); } } - valueChanged(newValue) { - if (this.props.onInputChanged) - this.props.onInputChanged(newValue, 'pressed'); + valueChanged(newValue, pressed) { + if (this.props.onInputChanged) { + this.props.onInputChanged(newValue, 'pressed', pressed); + } } render() { diff --git a/src/widget/widgets/input.js b/src/widget/widgets/input.js index 7fe7c38..0b87617 100644 --- a/src/widget/widgets/input.js +++ b/src/widget/widgets/input.js @@ -71,7 +71,7 @@ class WidgetInput extends Component { valueChanged(newValue) { if (this.props.onInputChanged) { - this.props.onInputChanged(Number(newValue), 'value'); + this.props.onInputChanged(Number(newValue), 'value', Number(newValue)); } } diff --git a/src/widget/widgets/slider.js b/src/widget/widgets/slider.js index 89f4da7..10bb055 100644 --- a/src/widget/widgets/slider.js +++ b/src/widget/widgets/slider.js @@ -105,7 +105,7 @@ class WidgetSlider extends Component { valueChanged(newValue) { if (this.props.onInputChanged) { - this.props.onInputChanged(newValue, 'value'); + this.props.onInputChanged(newValue, 'value', newValue); } }