@@ -20,6 +20,8 @@ import PropTypes from 'prop-types';
20
20
21
21
import ResizeObserver from 'resize-observer-polyfill' ;
22
22
23
+ import dis from '../../../dispatcher' ;
24
+
23
25
// Shamelessly ripped off Modal.js. There's probably a better way
24
26
// of doing reusable widgets like dialog boxes & menus where we go and
25
27
// pass in a custom control as the actual body.
@@ -64,9 +66,17 @@ export default class PersistedElement extends React.Component {
64
66
super ( ) ;
65
67
this . collectChildContainer = this . collectChildContainer . bind ( this ) ;
66
68
this . collectChild = this . collectChild . bind ( this ) ;
67
- this . _onContainerResize = this . _onContainerResize . bind ( this ) ;
68
-
69
- this . resizeObserver = new ResizeObserver ( this . _onContainerResize ) ;
69
+ this . _repositionChild = this . _repositionChild . bind ( this ) ;
70
+ this . _onAction = this . _onAction . bind ( this ) ;
71
+
72
+ this . resizeObserver = new ResizeObserver ( this . _repositionChild ) ;
73
+ // Annoyingly, a resize observer is insufficient, since we also care
74
+ // about when the element moves on the screen without changing its
75
+ // dimensions. Doesn't look like there's a ResizeObserver equivalent
76
+ // for this, so we bodge it by listening for document resize and
77
+ // the timeline_resize action.
78
+ window . addEventListener ( 'resize' , this . _repositionChild ) ;
79
+ this . _dispatcherRef = dis . register ( this . _onAction ) ;
70
80
}
71
81
72
82
/**
@@ -113,9 +123,17 @@ export default class PersistedElement extends React.Component {
113
123
componentWillUnmount ( ) {
114
124
this . updateChildVisibility ( this . child , false ) ;
115
125
this . resizeObserver . disconnect ( ) ;
126
+ window . removeEventListener ( 'resize' , this . _repositionChild ) ;
127
+ dis . unregister ( this . _dispatcherRef ) ;
128
+ }
129
+
130
+ _onAction ( payload ) {
131
+ if ( payload . action === 'timeline_resize' ) {
132
+ this . _repositionChild ( ) ;
133
+ }
116
134
}
117
135
118
- _onContainerResize ( ) {
136
+ _repositionChild ( ) {
119
137
this . updateChildPosition ( this . child , this . childContainer ) ;
120
138
}
121
139
0 commit comments