Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit f532c30

Browse files
committed
Don't animate when resizing and move when the PiP changes size
Signed-off-by: Šimon Brandner <[email protected]>
1 parent 001490f commit f532c30

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/components/views/voip/CallPreview.tsx

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export default class CallPreview extends React.Component<IProps, IState> {
146146
this.roomStoreToken = RoomViewStore.addListener(this.onRoomViewStoreUpdate);
147147
document.addEventListener("mousemove", this.onMoving);
148148
document.addEventListener("mouseup", this.onEndMoving);
149-
window.addEventListener("resize", this.snap);
149+
window.addEventListener("resize", this.onResize);
150150
this.dispatcherRef = dis.register(this.onAction);
151151
MatrixClientPeg.get().on(CallEvent.RemoteHoldUnhold, this.onCallRemoteHold);
152152
}
@@ -156,14 +156,18 @@ export default class CallPreview extends React.Component<IProps, IState> {
156156
MatrixClientPeg.get().removeListener(CallEvent.RemoteHoldUnhold, this.onCallRemoteHold);
157157
document.removeEventListener("mousemove", this.onMoving);
158158
document.removeEventListener("mouseup", this.onEndMoving);
159-
window.removeEventListener("resize", this.snap);
159+
window.removeEventListener("resize", this.onResize);
160160
if (this.roomStoreToken) {
161161
this.roomStoreToken.remove();
162162
}
163163
dis.unregister(this.dispatcherRef);
164164
SettingsStore.unwatchSetting(this.settingsWatcherRef);
165165
}
166166

167+
private onResize = (): void => {
168+
this.snap(false);
169+
};
170+
167171
private animationCallback = () => {
168172
// If the PiP isn't being dragged and there is only a tiny difference in
169173
// the desiredTranslation and translation, quit the animationCallback
@@ -207,7 +211,7 @@ export default class CallPreview extends React.Component<IProps, IState> {
207211
}
208212
}
209213

210-
private snap = () => {
214+
private snap(animate?: boolean): void {
211215
const translationX = this.desiredTranslationX;
212216
const translationY = this.desiredTranslationY;
213217
// We subtract the PiP size from the window size in order to calculate
@@ -236,10 +240,17 @@ export default class CallPreview extends React.Component<IProps, IState> {
236240
this.desiredTranslationY = PADDING.top;
237241
}
238242

239-
// We start animating here because we want the PiP to move when we're
240-
// resizing the window
241-
this.scheduledUpdate.mark();
242-
};
243+
if (animate) {
244+
// We start animating here because we want the PiP to move when we're
245+
// resizing the window
246+
this.scheduledUpdate.mark();
247+
} else {
248+
this.setState({
249+
translationX: this.desiredTranslationX,
250+
translationY: this.desiredTranslationY,
251+
});
252+
}
253+
}
243254

244255
private onRoomViewStoreUpdate = () => {
245256
if (RoomViewStore.getRoomId() === this.state.roomId) return;
@@ -310,7 +321,7 @@ export default class CallPreview extends React.Component<IProps, IState> {
310321

311322
private onEndMoving = () => {
312323
this.moving = false;
313-
this.snap();
324+
this.snap(true);
314325
};
315326

316327
public render() {
@@ -333,6 +344,7 @@ export default class CallPreview extends React.Component<IProps, IState> {
333344
secondaryCall={this.state.secondaryCall}
334345
pipMode={true}
335346
onMouseDownOnHeader={this.onStartMoving}
347+
onResize={this.onResize}
336348
/>
337349
</div>
338350
);

0 commit comments

Comments
 (0)