@@ -14,74 +14,31 @@ See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
1616
17- import React from "react" ;
18- import "context-filter-polyfill" ;
17+ import React , { CSSProperties } from "react" ;
1918
2019interface IProps {
21- backgroundImage ?: CanvasImageSource ;
20+ backgroundImage ?: string ;
21+ blurMultiplier ?: number ;
2222}
2323
24- interface IState {
25- // Left Panel image
26- lpImage ?: string ;
27- }
28-
29- export default class BackdropPanel extends React . PureComponent < IProps , IState > {
30- private style = getComputedStyle ( document . documentElement ) ;
31-
32- public state : IState = { } ;
33-
34- public componentDidMount ( ) {
35- this . onResize ( ) ;
36- }
37-
38- public componentDidUpdate ( prevProps : IProps ) {
39- if ( prevProps . backgroundImage !== this . props . backgroundImage ) {
40- this . onResize ( ) ;
24+ export const BackdropPanel : React . FC < IProps > = ( { backgroundImage, blurMultiplier } ) => {
25+ if ( ! backgroundImage ) return null ;
26+
27+ const styles : CSSProperties = { } ;
28+ if ( blurMultiplier ) {
29+ const rootStyle = getComputedStyle ( document . documentElement ) ;
30+ const blurValue = rootStyle . getPropertyValue ( '--lp-background-blur' ) ;
31+ const pixelsValue = blurValue . replace ( 'px' , '' ) ;
32+ const parsed = parseInt ( pixelsValue , 10 ) ;
33+ if ( ! isNaN ( parsed ) ) {
34+ styles . filter = `blur(${ parsed * blurMultiplier } px)` ;
4135 }
4236 }
43-
44- private onResize = ( ) => {
45- if ( this . props . backgroundImage ) {
46- this . refreshBackdropImage ( ) ;
47- }
48- } ;
49-
50- private refreshBackdropImage = ( ) : void => {
51- const leftPanelCanvas = document . createElement ( 'canvas' ) ;
52- const leftPanelContext = leftPanelCanvas . getContext ( "2d" ) ;
53- const { backgroundImage } = this . props ;
54-
55- const imageWidth = ( backgroundImage as ImageBitmap ) . width ;
56- const imageHeight = ( backgroundImage as ImageBitmap ) . height ;
57-
58- leftPanelCanvas . width = window . screen . width * 0.5 ;
59- leftPanelCanvas . height = window . screen . height ;
60-
61- const roomListBlur = this . style . getPropertyValue ( '--lp-background-blur' ) ;
62-
63- leftPanelContext . filter = `blur(${ roomListBlur } )` ;
64- leftPanelContext . drawImage (
65- backgroundImage ,
66- 0 , 0 ,
67- imageWidth , imageHeight ,
68- 0 ,
69- 0 ,
70- window . screen . width * 0.5 ,
71- window . screen . height ,
72- ) ;
73- this . setState ( {
74- lpImage : leftPanelCanvas . toDataURL ( 'image/jpeg' , 1 ) ,
75-
76- } ) ;
77- } ;
78-
79- public render ( ) {
80- if ( ! this . props . backgroundImage ) return null ;
81- return < div className = "mx_BackdropPanel" >
82- { this . state ?. lpImage !== 'data:,' && < img
83- className = "mx_BackdropPanel--canvas"
84- src = { this . state . lpImage } /> }
85- </ div > ;
86- }
87- }
37+ return < div className = "mx_BackdropPanel" >
38+ < img
39+ style = { styles }
40+ className = "mx_BackdropPanel--image"
41+ src = { backgroundImage } />
42+ </ div > ;
43+ } ;
44+ export default BackdropPanel ;
0 commit comments