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

Commit 8a99c71

Browse files
authored
Merge pull request #2094 from matrix-org/dbkr/reposition_jitsi__release
Fix persistend element location not updating
2 parents c6ad30f + 1c0f778 commit 8a99c71

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/components/views/elements/PersistedElement.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import PropTypes from 'prop-types';
2020

2121
import ResizeObserver from 'resize-observer-polyfill';
2222

23+
import dis from '../../../dispatcher';
24+
2325
// Shamelessly ripped off Modal.js. There's probably a better way
2426
// of doing reusable widgets like dialog boxes & menus where we go and
2527
// pass in a custom control as the actual body.
@@ -64,9 +66,17 @@ export default class PersistedElement extends React.Component {
6466
super();
6567
this.collectChildContainer = this.collectChildContainer.bind(this);
6668
this.collectChild = this.collectChild.bind(this);
67-
this._onContainerResize = this._onContainerResize.bind(this);
68-
69-
this.resizeObserver = new ResizeObserver(this._onContainerResize);
69+
this._repositionChild = this._repositionChild.bind(this);
70+
this._onAction = this._onAction.bind(this);
71+
72+
this.resizeObserver = new ResizeObserver(this._repositionChild);
73+
// Annoyingly, a resize observer is insufficient, since we also care
74+
// about when the element moves on the screen without changing its
75+
// dimensions. Doesn't look like there's a ResizeObserver equivalent
76+
// for this, so we bodge it by listening for document resize and
77+
// the timeline_resize action.
78+
window.addEventListener('resize', this._repositionChild);
79+
this._dispatcherRef = dis.register(this._onAction);
7080
}
7181

7282
/**
@@ -113,9 +123,17 @@ export default class PersistedElement extends React.Component {
113123
componentWillUnmount() {
114124
this.updateChildVisibility(this.child, false);
115125
this.resizeObserver.disconnect();
126+
window.removeEventListener('resize', this._repositionChild);
127+
dis.unregister(this._dispatcherRef);
128+
}
129+
130+
_onAction(payload) {
131+
if (payload.action === 'timeline_resize') {
132+
this._repositionChild();
133+
}
116134
}
117135

118-
_onContainerResize() {
136+
_repositionChild() {
119137
this.updateChildPosition(this.child, this.childContainer);
120138
}
121139

0 commit comments

Comments
 (0)