| 28 | * Cached-content is not be re-measured. |
| 29 | */ |
| 30 | export default class CellMeasurer extends React.PureComponent<Props> { |
| 31 | static __internalCellMeasurerFlag = false; |
| 32 | |
| 33 | _child: {current: HTMLElement | null} = React.createRef(); |
| 34 | |
| 35 | componentDidMount() { |
| 36 | this._maybeMeasureCell(); |
| 37 | } |
| 38 | |
| 39 | componentDidUpdate() { |
| 40 | this._maybeMeasureCell(); |
| 41 | } |
| 42 | |
| 43 | render() { |
| 44 | const {children} = this.props; |
| 45 | |
| 46 | const resolvedChildren = |
| 47 | typeof children === 'function' |
| 48 | ? children({measure: this._measure, registerChild: this._registerChild}) |
| 49 | : children; |
| 50 | |
| 51 | if (resolvedChildren === null) { |
| 52 | return resolvedChildren; |
| 53 | } |
| 54 | |
| 55 | return cloneElement(resolvedChildren, { |
| 56 | ref: node => { |
| 57 | if (typeof resolvedChildren.ref === 'function') { |
| 58 | resolvedChildren.ref(node); |
| 59 | } else if (resolvedChildren.ref) { |
| 60 | resolvedChildren.ref.current = node; |
| 61 | } |
| 62 | this._child.current = node; |
| 63 | }, |
| 64 | }); |
| 65 | } |
| 66 | |
| 67 | _getCellMeasurements() { |
| 68 | const {cache} = this.props; |
| 69 | |
| 70 | const node = this._child.current; |
| 71 | |
| 72 | // TODO Check for a bad combination of fixedWidth and missing numeric width or vice versa with height |
| 73 | |
| 74 | if ( |
| 75 | node && |
| 76 | node.ownerDocument && |
| 77 | node.ownerDocument.defaultView && |
| 78 | node instanceof node.ownerDocument.defaultView.HTMLElement |
| 79 | ) { |
| 80 | const styleWidth = node.style.width; |
| 81 | const styleHeight = node.style.height; |
| 82 | |
| 83 | // If we are re-measuring a cell that has already been measured, |
| 84 | // It will have a hard-coded width/height from the previous measurement. |
| 85 | // The fact that we are measuring indicates this measurement is probably stale, |
| 86 | // So explicitly clear it out (eg set to "auto") so we can recalculate. |
| 87 | // See issue #593 for more info. |
nothing calls this directly
no test coverage detected
searching dependent graphs…