Merge pull request #2036 from matrix-org/dbkr/many_persistedelements
Give PersistedElement a key
This commit is contained in:
commit
bfbd499737
2 changed files with 19 additions and 13 deletions
|
@ -16,28 +16,24 @@ limitations under the License.
|
||||||
|
|
||||||
const React = require('react');
|
const React = require('react');
|
||||||
const ReactDOM = require('react-dom');
|
const ReactDOM = require('react-dom');
|
||||||
|
const PropTypes = require('prop-types');
|
||||||
|
|
||||||
// Shamelessly ripped off Modal.js. There's probably a better way
|
// Shamelessly ripped off Modal.js. There's probably a better way
|
||||||
// of doing reusable widgets like dialog boxes & menus where we go and
|
// of doing reusable widgets like dialog boxes & menus where we go and
|
||||||
// pass in a custom control as the actual body.
|
// pass in a custom control as the actual body.
|
||||||
|
|
||||||
const ContainerId = "mx_PersistedElement";
|
function getOrCreateContainer(containerId) {
|
||||||
|
let container = document.getElementById(containerId);
|
||||||
function getOrCreateContainer() {
|
|
||||||
let container = document.getElementById(ContainerId);
|
|
||||||
|
|
||||||
if (!container) {
|
if (!container) {
|
||||||
container = document.createElement("div");
|
container = document.createElement("div");
|
||||||
container.id = ContainerId;
|
container.id = containerId;
|
||||||
document.body.appendChild(container);
|
document.body.appendChild(container);
|
||||||
}
|
}
|
||||||
|
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Greater than that of the ContextualMenu
|
|
||||||
const PE_Z_INDEX = 5000;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class of component that renders its children in a separate ReactDOM virtual tree
|
* Class of component that renders its children in a separate ReactDOM virtual tree
|
||||||
* in a container element appended to document.body.
|
* in a container element appended to document.body.
|
||||||
|
@ -50,6 +46,14 @@ const PE_Z_INDEX = 5000;
|
||||||
* bounding rect as the parent of PE.
|
* bounding rect as the parent of PE.
|
||||||
*/
|
*/
|
||||||
export default class PersistedElement extends React.Component {
|
export default class PersistedElement extends React.Component {
|
||||||
|
|
||||||
|
static propTypes = {
|
||||||
|
// Unique identifier for this PersistedElement instance
|
||||||
|
// Any PersistedElements with the same persistKey will use
|
||||||
|
// the same DOM container.
|
||||||
|
persistKey: PropTypes.string.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.collectChildContainer = this.collectChildContainer.bind(this);
|
this.collectChildContainer = this.collectChildContainer.bind(this);
|
||||||
|
@ -97,18 +101,16 @@ export default class PersistedElement extends React.Component {
|
||||||
left: parentRect.left + 'px',
|
left: parentRect.left + 'px',
|
||||||
width: parentRect.width + 'px',
|
width: parentRect.width + 'px',
|
||||||
height: parentRect.height + 'px',
|
height: parentRect.height + 'px',
|
||||||
zIndex: PE_Z_INDEX,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const content = <div ref={this.collectChild}>
|
const content = <div ref={this.collectChild} style={this.props.style}>
|
||||||
{this.props.children}
|
{this.props.children}
|
||||||
</div>;
|
</div>;
|
||||||
|
|
||||||
ReactDOM.render(content, getOrCreateContainer());
|
ReactDOM.render(content, getOrCreateContainer('mx_persistedElement_'+this.props.persistKey));
|
||||||
|
|
||||||
return <div ref={this.collectChildContainer}></div>;
|
return <div ref={this.collectChildContainer}></div>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,10 @@ import WidgetUtils from '../../../utils/WidgetUtils';
|
||||||
|
|
||||||
const widgetType = 'm.stickerpicker';
|
const widgetType = 'm.stickerpicker';
|
||||||
|
|
||||||
|
// We sit in a context menu, so the persisted element container needs to float
|
||||||
|
// above it, so it needs a greater z-index than the ContextMenu
|
||||||
|
const STICKERPICKER_Z_INDEX = 5000;
|
||||||
|
|
||||||
export default class Stickerpicker extends React.Component {
|
export default class Stickerpicker extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
@ -211,7 +215,7 @@ export default class Stickerpicker extends React.Component {
|
||||||
width: this.popoverWidth,
|
width: this.popoverWidth,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<PersistedElement>
|
<PersistedElement containerId="mx_persisted_stickerPicker" style={{zIndex: STICKERPICKER_Z_INDEX}}>
|
||||||
<AppTile
|
<AppTile
|
||||||
collectWidgetMessaging={this._collectWidgetMessaging}
|
collectWidgetMessaging={this._collectWidgetMessaging}
|
||||||
id={stickerpickerWidget.id}
|
id={stickerpickerWidget.id}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue