2016-01-06 05:11:07 +03:00
|
|
|
/*
|
|
|
|
Copyright 2015 OpenMarket Ltd
|
2019-12-20 03:45:24 +03:00
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
2016-01-06 05:11:07 +03:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2019-09-06 20:35:52 +03:00
|
|
|
import React from 'react';
|
2017-12-26 04:03:18 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2019-09-06 20:35:52 +03:00
|
|
|
import createReactClass from 'create-react-class';
|
|
|
|
import Tinter from "../../../Tinter";
|
2016-01-06 05:11:07 +03:00
|
|
|
|
2019-09-06 20:35:52 +03:00
|
|
|
const TintableSvg = createReactClass({
|
2016-01-06 05:11:07 +03:00
|
|
|
displayName: 'TintableSvg',
|
|
|
|
|
|
|
|
propTypes: {
|
2017-12-26 04:03:18 +03:00
|
|
|
src: PropTypes.string.isRequired,
|
|
|
|
width: PropTypes.string.isRequired,
|
|
|
|
height: PropTypes.string.isRequired,
|
|
|
|
className: PropTypes.string,
|
2016-01-06 05:11:07 +03:00
|
|
|
},
|
|
|
|
|
2016-04-16 03:00:10 +03:00
|
|
|
statics: {
|
|
|
|
// list of currently mounted TintableSvgs
|
|
|
|
mounts: {},
|
|
|
|
idSequence: 0,
|
|
|
|
},
|
|
|
|
|
2020-03-31 23:14:17 +03:00
|
|
|
componentDidMount: function() {
|
2016-01-07 13:18:18 +03:00
|
|
|
this.fixups = [];
|
2016-01-07 06:39:00 +03:00
|
|
|
|
2016-04-16 03:00:10 +03:00
|
|
|
this.id = TintableSvg.idSequence++;
|
|
|
|
TintableSvg.mounts[this.id] = this;
|
2016-01-06 05:11:07 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
componentWillUnmount: function() {
|
2016-04-16 03:00:10 +03:00
|
|
|
delete TintableSvg.mounts[this.id];
|
2016-01-07 06:39:00 +03:00
|
|
|
},
|
|
|
|
|
2016-04-16 03:00:10 +03:00
|
|
|
tint: function() {
|
|
|
|
// TODO: only bother running this if the global tint settings have changed
|
|
|
|
// since we loaded!
|
2016-01-07 06:59:09 +03:00
|
|
|
Tinter.applySvgFixups(this.fixups);
|
2016-01-06 05:11:07 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onLoad: function(event) {
|
2019-01-03 21:55:56 +03:00
|
|
|
// console.log("TintableSvg.onLoad for " + this.props.src);
|
|
|
|
this.fixups = Tinter.calcSvgFixups([event.target]);
|
2016-01-07 06:59:09 +03:00
|
|
|
Tinter.applySvgFixups(this.fixups);
|
2016-01-06 05:11:07 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
return (
|
2017-10-11 19:56:17 +03:00
|
|
|
<object className={"mx_TintableSvg " + (this.props.className ? this.props.className : "")}
|
2016-01-06 05:11:07 +03:00
|
|
|
type="image/svg+xml"
|
2017-10-11 19:56:17 +03:00
|
|
|
data={this.props.src}
|
|
|
|
width={this.props.width}
|
|
|
|
height={this.props.height}
|
|
|
|
onLoad={this.onLoad}
|
2017-01-07 18:53:45 +03:00
|
|
|
tabIndex="-1"
|
2016-04-17 23:46:27 +03:00
|
|
|
/>
|
2016-01-06 05:11:07 +03:00
|
|
|
);
|
2017-10-11 19:56:17 +03:00
|
|
|
},
|
2016-01-06 05:11:07 +03:00
|
|
|
});
|
2016-04-16 03:00:10 +03:00
|
|
|
|
2016-11-16 17:16:51 +03:00
|
|
|
// Register with the Tinter so that we will be told if the tint changes
|
|
|
|
Tinter.registerTintable(function() {
|
|
|
|
if (TintableSvg.mounts) {
|
|
|
|
Object.keys(TintableSvg.mounts).forEach((id) => {
|
|
|
|
TintableSvg.mounts[id].tint();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-12-20 03:45:24 +03:00
|
|
|
export default TintableSvg;
|