summaryrefslogtreecommitdiffhomepage
path: root/gui/src/renderer
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2021-09-29 15:14:09 +0200
committerOskar Nyberg <oskar@mullvad.net>2021-09-30 14:25:48 +0200
commitf3281cb63b891358abc2b4e20010a152f0f79d09 (patch)
tree9c433da4ae06fd2b5fa98e5e02a2df4d675b9a6f /gui/src/renderer
parentbe607a7f1ee7ed8ba12f8e3cb3a65b586931bfa2 (diff)
downloadmullvadvpn-f3281cb63b891358abc2b4e20010a152f0f79d09.tar.xz
mullvadvpn-f3281cb63b891358abc2b4e20010a152f0f79d09.zip
Wait with switch onChange until after transition
Diffstat (limited to 'gui/src/renderer')
-rw-r--r--gui/src/renderer/components/Switch.tsx15
1 files changed, 13 insertions, 2 deletions
diff --git a/gui/src/renderer/components/Switch.tsx b/gui/src/renderer/components/Switch.tsx
index 0f90a4e7e1..e3b722c721 100644
--- a/gui/src/renderer/components/Switch.tsx
+++ b/gui/src/renderer/components/Switch.tsx
@@ -17,6 +17,9 @@ interface IProps {
interface IState {
isOn: boolean;
isPressed: boolean;
+ // gRPC calls cause the transition to glitch for some reason. Waiting with the onchange event
+ // until after the transition prevents the visual glitch from happening.
+ notifyOnTransitionEnd: boolean;
}
const PAN_DISTANCE = 10;
@@ -56,6 +59,7 @@ export default class Switch extends React.PureComponent<IProps, IState> {
public state: IState = {
isOn: this.props.isOn,
isPressed: false,
+ notifyOnTransitionEnd: false,
};
private containerRef = React.createRef<HTMLDivElement>();
@@ -93,6 +97,7 @@ export default class Switch extends React.PureComponent<IProps, IState> {
isOn={this.state.isOn}
isPressed={this.state.isPressed}
onMouseDown={this.handleMouseDown}
+ onTransitionEnd={this.onTransitionEnd}
/>
</SwitchContainer>
);
@@ -103,13 +108,19 @@ export default class Switch extends React.PureComponent<IProps, IState> {
assignToRef(element, this.props.forwardedRef);
};
+ private onTransitionEnd = (event: React.TransitionEvent) => {
+ if (this.state.notifyOnTransitionEnd && event.propertyName === 'left') {
+ this.notify();
+ }
+ };
+
private handleClick = () => {
if (this.props.disabled) {
return;
}
if (!this.changedDuringPan) {
- this.setState((state) => ({ isOn: !state.isOn }), this.notify);
+ this.setState((state) => ({ isOn: !state.isOn, notifyOnTransitionEnd: true }));
}
// Needs to be reset to allow clicks on container after panning.
@@ -161,7 +172,7 @@ export default class Switch extends React.PureComponent<IProps, IState> {
if (this.state.isOn !== nextOn) {
this.startPos = event.clientX;
this.changedDuringPan = true;
- this.setState({ isOn: nextOn });
+ this.setState({ isOn: nextOn, notifyOnTransitionEnd: false });
}
}
};