| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1975,6 +1975,20 @@ export const testWrap_childMargin_vertical = test( | |||
| 1975 | 1975 | } | |
| 1976 | 1976 | ); | |
| 1977 | 1977 | ||
| 1978 | + let activity_flexbox_with_proxy_view_container = () => getViews( | ||
| 1979 | + `<FlexboxLayout id="flexbox"> | ||
| 1980 | + <ProxyViewContainer></ProxyViewContainer> | ||
| 1981 | + </FlexboxLayout>` | ||
| 1982 | + ); | ||
| 1983 | + | ||
| 1984 | + export const testFlexboxLayout_does_not_crash_with_proxy_view_container = test( | ||
| 1985 | + activity_flexbox_with_proxy_view_container, | ||
| 1986 | + noop, | ||
| 1987 | + ({root, flexbox}) => { | ||
| 1988 | + TKUnit.assert(flexbox.id === "flexbox", "FlexboxLayout actually there"); | ||
| 1989 | + } | ||
| 1990 | + ); | ||
| 1991 | + | ||
| 1978 | 1992 | // Omit testEmptyChildren | |
| 1979 | 1993 | // Omit testDivider_directionRow_verticalBeginning | |
| 1980 | 1994 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -67,6 +67,28 @@ import makeMeasureSpec = utils.layout.makeMeasureSpec; | |||
| 67 | 67 | import getMeasureSpecMode = utils.layout.getMeasureSpecMode; | |
| 68 | 68 | import getMeasureSpecSize = utils.layout.getMeasureSpecSize; | |
| 69 | 69 | ||
| 70 | + // `eachLayoutChild` iterates over children, and we need more - indexed access. | ||
| 71 | + // This class tries to accomodate that by collecting all children in an | ||
| 72 | + // array no more than once per measure. | ||
| 73 | + class MeasureContext { | ||
| 74 | + private children: View[]; | ||
| 75 | + | ||
| 76 | + constructor(private owner: FlexboxLayout) { | ||
| 77 | + this.children = []; | ||
| 78 | + this.owner.eachLayoutChild((child) => { | ||
| 79 | + this.children.push(child); | ||
| 80 | + }); | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + public get childrenCount(): number { | ||
| 84 | + return this.children.length; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + public childAt(index: number): View { | ||
| 88 | + return this.children[index]; | ||
| 89 | + } | ||
| 90 | + } | ||
| 91 | + | ||
| 70 | 92 | class FlexLine { | |
| 71 | 93 | ||
| 72 | 94 | _left: number = Number.MAX_VALUE; | |
@@ -117,6 +139,7 @@ export class FlexboxLayout extends FlexboxLayoutBase { | |||
| 117 | 139 | private _orderCache: number[]; | |
| 118 | 140 | private _flexLines: FlexLine[] = []; | |
| 119 | 141 | private _childrenFrozen: boolean[]; | |
| 142 | + private measureContext: MeasureContext; | ||
| 120 | 143 | ||
| 121 | 144 | _setNativeFlexDirection(flexDirection: FlexDirection) { | |
| 122 | 145 | // lint happy no-op | |
@@ -141,15 +164,16 @@ export class FlexboxLayout extends FlexboxLayoutBase { | |||
| 141 | 164 | } | |
| 142 | 165 | ||
| 143 | 166 | public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void { | |
| 167 | + this.measureContext = new MeasureContext(this); | ||
| 144 | 168 | LayoutBase.adjustChildrenLayoutParams(this, widthMeasureSpec, heightMeasureSpec); | |
| 145 | 169 | ||
| 146 | 170 | // Omit: super.onMeasure(widthMeasureSpec, heightMeasureSpec); | |
| 147 | 171 | ||
| 148 | 172 | if (this._isOrderChangedFromLastMeasurement) { | |
| 149 | 173 | this._reorderedIndices = this._createReorderedIndices(); | |
| 150 | 174 | } | |
| 151 | - if (!this._childrenFrozen || this._childrenFrozen.length < this.getChildrenCount()) { | ||
| 152 | - this._childrenFrozen = new Array(this.getChildrenCount()); | ||
| 175 | + if (!this._childrenFrozen || this._childrenFrozen.length < this.measureContext.childrenCount) { | ||
| 176 | + this._childrenFrozen = new Array(this.measureContext.childrenCount); | ||
| 153 | 177 | } | |
| 154 | 178 | ||
| 155 | 179 | switch (this.flexDirection) { | |
@@ -174,13 +198,13 @@ export class FlexboxLayout extends FlexboxLayoutBase { | |||
| 174 | 198 | child = null; | |
| 175 | 199 | } else { | |
| 176 | 200 | let reorderedIndex = this._reorderedIndices[index]; | |
| 177 | - child = this.getChildAt(reorderedIndex); | ||
| 201 | + child = this.measureContext.childAt(reorderedIndex); | ||
| 178 | 202 | } | |
| 179 | 203 | return child; | |
| 180 | 204 | } | |
| 181 | 205 | ||
| 182 | 206 | private _createReorderedIndices(): number[] { | |
| 183 | - let childCount = this.getChildrenCount(); | ||
| 207 | + let childCount = this.measureContext.childrenCount; | ||
| 184 | 208 | let orders = this._createOrders(childCount); | |
| 185 | 209 | return this._sortOrdersIntoReorderedIndices(childCount, orders); | |
| 186 | 210 | } | |
@@ -203,7 +227,7 @@ export class FlexboxLayout extends FlexboxLayoutBase { | |||
| 203 | 227 | private _createOrders(childCount: number): Order[] { | |
| 204 | 228 | let orders: Order[] = []; | |
| 205 | 229 | for (let i = 0; i < childCount; i++) { | |
| 206 | - let child = this.getChildAt(i); | ||
| 230 | + let child = this.measureContext.childAt(i); | ||
| 207 | 231 | let order = new Order(); | |
| 208 | 232 | order.order = FlexboxLayout.getOrder(child); | |
| 209 | 233 | order.index = i; | |
@@ -213,15 +237,15 @@ export class FlexboxLayout extends FlexboxLayoutBase { | |||
| 213 | 237 | } | |
| 214 | 238 | ||
| 215 | 239 | private get _isOrderChangedFromLastMeasurement(): boolean { | |
| 216 | - let childCount = this.getChildrenCount(); | ||
| 240 | + let childCount = this.measureContext.childrenCount; | ||
| 217 | 241 | if (!this._orderCache) { | |
| 218 | 242 | this._orderCache = []; | |
| 219 | 243 | } | |
| 220 | 244 | if (this._orderCache.length !== childCount) { | |
| 221 | 245 | return true; | |
| 222 | 246 | } | |
| 223 | 247 | for (let i = 0; i < childCount; i++) { | |
| 224 | - let view = this.getChildAt(i); | ||
| 248 | + let view = this.measureContext.childAt(i); | ||
| 225 | 249 | if (view === null) { | |
| 226 | 250 | continue; | |
| 227 | 251 | } | |
@@ -241,7 +265,7 @@ export class FlexboxLayout extends FlexboxLayoutBase { | |||
| 241 | 265 | this._flexLines.length = 0; | |
| 242 | 266 | ||
| 243 | 267 | (() => { | |
| 244 | - let childCount = this.getChildrenCount(); | ||
| 268 | + let childCount = this.measureContext.childrenCount; | ||
| 245 | 269 | let paddingStart = FlexboxLayout.getPaddingStart(this); | |
| 246 | 270 | let paddingEnd = FlexboxLayout.getPaddingEnd(this); | |
| 247 | 271 | let largestHeightInRow = Number.MIN_VALUE; | |
@@ -355,7 +379,7 @@ export class FlexboxLayout extends FlexboxLayoutBase { | |||
| 355 | 379 | ||
| 356 | 380 | this._flexLines.length = 0; | |
| 357 | 381 | ||
| 358 | - let childCount = this.getChildrenCount(); | ||
| 382 | + let childCount = this.measureContext.childrenCount; | ||
| 359 | 383 | let paddingTop = this.paddingTop; | |
| 360 | 384 | let paddingBottom = this.paddingBottom; | |
| 361 | 385 | let largestWidthInColumn = Number.MIN_VALUE; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments