protected _checkAndReportLayout()

in src/web/ViewBase.tsx [114:158]


    protected _checkAndReportLayout(): Promise<void> {
        if (!this._isMounted) {
            return Promise.resolve(void 0);
        }

        const container = this._getContainer();
        if (!container) {
            return Promise.resolve(void 0);
        }

        const newX = container.offsetLeft;
        const newY = container.offsetTop;
        const marginTop = !container.style.marginTop ? 0 : parseInt(container.style.marginTop, 10) || 0;
        const marginBottom = !container.style.marginBottom ? 0 : parseInt(container.style.marginBottom, 10) || 0;
        const marginRight = !container.style.marginRight ? 0 : parseInt(container.style.marginRight, 10) || 0;
        const marginLeft = !container.style.marginLeft ? 0 : parseInt(container.style.marginLeft, 10) || 0;
        const newWidth = container.offsetWidth + marginRight + marginLeft;
        const newHeight = container.offsetHeight + marginTop + marginBottom;

        if (this._lastX !== newX || this._lastY !== newY || this._lastWidth !== newWidth || this._lastHeight !== newHeight) {
            this._lastX = newX;
            this._lastY = newY;
            this._lastWidth = newWidth;
            this._lastHeight = newHeight;

            const deferred = new Defer<void>();
            ViewBase._reportLayoutChange(() => {
                if (!this._isMounted || !this.props.onLayout) {
                    deferred.resolve(void 0);
                    return;
                }

                this.props.onLayout({
                    x: newX,
                    y: newY,
                    width: this._lastWidth,
                    height: this._lastHeight,
                });
                deferred.resolve(void 0);
            });
            return deferred.promise();
        }

        return Promise.resolve(void 0);
    }