Simplifie translation code

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
Šimon Brandner 2021-05-03 17:49:55 +02:00
parent d8d380c74d
commit be2da6376e
No known key found for this signature in database
GPG key ID: 9760693FDD98A790

View file

@ -126,8 +126,6 @@ export default class CallPreview extends React.Component<IProps, IState> {
private initX = 0; private initX = 0;
private initY = 0; private initY = 0;
private lastX = DEFAULT_X_OFFSET;
private lastY = DEFAULT_Y_OFFSET;
public componentDidMount() { public componentDidMount() {
this.roomStoreToken = RoomViewStore.addListener(this.onRoomViewStoreUpdate); this.roomStoreToken = RoomViewStore.addListener(this.onRoomViewStoreUpdate);
@ -199,8 +197,8 @@ export default class CallPreview extends React.Component<IProps, IState> {
this.setState({moving: true}); this.setState({moving: true});
this.initX = event.pageX - this.lastX; this.initX = event.pageX - this.state.translationX;
this.initY = event.pageY - this.lastY; this.initY = event.pageY - this.state.translationY;
}; };
private onMoving = (event: React.MouseEvent | MouseEvent) => { private onMoving = (event: React.MouseEvent | MouseEvent) => {
@ -215,27 +213,30 @@ export default class CallPreview extends React.Component<IProps, IState> {
const precalculatedLastX = event.pageX - this.initX; const precalculatedLastX = event.pageX - this.initX;
const precalculatedLastY = event.pageY - this.initY; const precalculatedLastY = event.pageY - this.initY;
let translationX;
let translationY;
// Avoid overflow on the x axis // Avoid overflow on the x axis
if (precalculatedLastX + width >= window.innerWidth) { if (precalculatedLastX + width >= window.innerWidth) {
this.lastX = window.innerWidth - width; translationX = window.innerWidth - width;
} else if (precalculatedLastX <= 0) { } else if (precalculatedLastX <= 0) {
this.lastX = 0; translationX = 0;
} else { } else {
this.lastX = precalculatedLastX; translationX = precalculatedLastX;
} }
// Avoid overflow on the y axis // Avoid overflow on the y axis
if (precalculatedLastY + height >= window.innerHeight) { if (precalculatedLastY + height >= window.innerHeight) {
this.lastY = window.innerHeight - height; translationY = window.innerHeight - height;
} else if (precalculatedLastY <= 0) { } else if (precalculatedLastY <= 0) {
this.lastY = 0; translationY = 0;
} else { } else {
this.lastY = precalculatedLastY; translationY = precalculatedLastY;
} }
this.setState({ this.setState({
translationX: this.lastX, translationX: translationX,
translationY: this.lastY, translationY: translationY,
}); });
}; };