2016-01-06 05:11:07 +03:00
|
|
|
/*
|
|
|
|
Copyright 2015 OpenMarket Ltd
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
const React = require('react');
|
|
|
|
const ReactDOM = require("react-dom");
|
2017-12-26 04:03:18 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2017-10-11 19:56:17 +03:00
|
|
|
const Tinter = require("../../../Tinter");
|
2016-01-06 05:11:07 +03:00
|
|
|
|
2016-04-16 03:00:10 +03:00
|
|
|
var TintableSvg = React.createClass({
|
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,
|
|
|
|
},
|
|
|
|
|
2016-01-07 06:39:00 +03:00
|
|
|
componentWillMount: function() {
|
2016-01-07 13:18:18 +03:00
|
|
|
this.fixups = [];
|
2016-01-07 06:39:00 +03:00
|
|
|
},
|
|
|
|
|
2016-01-06 05:11:07 +03:00
|
|
|
componentDidMount: function() {
|
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) {
|
2016-04-16 03:00:10 +03:00
|
|
|
// console.log("TintableSvg.onLoad for " + this.props.src);
|
2016-01-07 06:59:09 +03:00
|
|
|
this.fixups = Tinter.calcSvgFixups([event.target]);
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-04-17 23:46:27 +03:00
|
|
|
module.exports = TintableSvg;
|