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

Commit 5ead53b

Browse files
authored
Merge pull request #6483 from SimonBrandner/fix/dont-anim-resize/18261
Fix PiP resize issues
2 parents f7d0419 + f532c30 commit 5ead53b

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-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
);

src/components/views/voip/VideoFeed.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export default class VideoFeed extends React.Component<IProps, IState> {
5959

6060
componentDidMount() {
6161
this.props.feed.addListener(CallFeedEvent.NewStream, this.onNewStream);
62+
this.element.current?.addEventListener('resize', this.onResize);
6263
this.playMedia();
6364
}
6465

0 commit comments

Comments
 (0)