@@ -103,17 +103,12 @@ class TodosWebview extends Component {
103103 intl : intlShape ,
104104 } ;
105105
106- resizeObserver = new window . ResizeObserver ( ( [ element ] ) => {
107- const bounds = element . target . getBoundingClientRect ( ) ;
108-
109- ipcRenderer . send ( RESIZE_TODO_VIEW , {
110- width : bounds . width ,
111- height : bounds . height ,
112- x : bounds . x ,
113- y : element . target . offsetTop ,
114- } ) ;
106+ resizeObserver = new window . ResizeObserver ( ( ) => {
107+ this . resizeBrowserView ( ) ;
115108 } ) ;
116109
110+ todosContainerRef = React . createRef ( )
111+
117112 componentWillMount ( ) {
118113 const { width } = this . props ;
119114
@@ -123,19 +118,21 @@ class TodosWebview extends Component {
123118 }
124119
125120 componentDidMount ( ) {
126- this . node . addEventListener ( 'mousemove' , this . resizePanel . bind ( this ) ) ;
127- this . node . addEventListener ( 'mouseup' , this . stopResize . bind ( this ) ) ;
128- this . node . addEventListener ( 'mouseleave' , this . stopResize . bind ( this ) ) ;
121+ this . todosContainerRef . current . addEventListener ( 'mousemove' , this . resizePanel . bind ( this ) ) ;
122+ this . todosContainerRef . current . addEventListener ( 'mouseup' , this . stopResize . bind ( this ) ) ;
123+ this . todosContainerRef . current . addEventListener ( 'mouseleave' , this . stopResize . bind ( this ) ) ;
129124
130- this . resizeObserver . observe ( this . node ) ;
125+ this . resizeObserver . observe ( this . todosContainerRef . current ) ;
131126
132- const bounds = this . node . getBoundingClientRect ( ) ;
127+ this . resizeBrowserView ( ) ;
128+ }
133129
130+ componentWillUnmount ( ) {
134131 ipcRenderer . send ( RESIZE_TODO_VIEW , {
135- width : bounds . width ,
136- height : bounds . height ,
137- x : bounds . x ,
138- y : bounds . y ,
132+ width : 0 ,
133+ height : 0 ,
134+ x : 0 ,
135+ y : 0 ,
139136 } ) ;
140137 }
141138
@@ -193,6 +190,20 @@ class TodosWebview extends Component {
193190 }
194191 }
195192
193+ resizeBrowserView ( ) {
194+ if ( this . todosContainerRef . current ) {
195+ const bounds = this . todosContainerRef . current . getBoundingClientRect ( ) ;
196+
197+ ipcRenderer . send ( RESIZE_TODO_VIEW , {
198+ width : bounds . width ,
199+ height : bounds . height ,
200+ x : bounds . x ,
201+ y : this . todosContainerRef . current . offsetTop ,
202+ } ) ;
203+ }
204+ }
205+
206+
196207 render ( ) {
197208 const {
198209 classes,
@@ -224,7 +235,7 @@ class TodosWebview extends Component {
224235 } ) }
225236 style = { { width : displayedWidth } }
226237 onMouseUp = { ( ) => this . stopResize ( ) }
227- ref = { ( node ) => { this . node = node ; } }
238+ ref = { this . todosContainerRef }
228239 id = "todos-panel"
229240 >
230241 < div
0 commit comments