| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1911,6 +1911,20 @@ export const testWrap_childMargin_vertical = test( | |||
| 1911 | 1911 | } | |
| 1912 | 1912 | ); | |
| 1913 | 1913 | ||
| 1914 | + let activity_flexbox_with_proxy_view_container = () => getViews( | ||
| 1915 | + `<FlexboxLayout id="flexbox"> | ||
| 1916 | + <ProxyViewContainer></ProxyViewContainer> | ||
| 1917 | + </FlexboxLayout>` | ||
| 1918 | + ); | ||
| 1919 | + | ||
| 1920 | + export const testFlexboxLayout_does_not_crash_with_proxy_view_container = test( | ||
| 1921 | + activity_flexbox_with_proxy_view_container, | ||
| 1922 | + noop, | ||
| 1923 | + ({root, flexbox}) => { | ||
| 1924 | + TKUnit.assert(flexbox.id === "flexbox", "FlexboxLayout actually there"); | ||
| 1925 | + } | ||
| 1926 | + ); | ||
| 1927 | + | ||
| 1914 | 1928 | // Omit testEmptyChildren | |
| 1915 | 1929 | // Omit testDivider_directionRow_verticalBeginning | |
| 1916 | 1930 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -94,6 +94,28 @@ import makeMeasureSpec = layout.makeMeasureSpec; | |||
| 94 | 94 | import getMeasureSpecMode = layout.getMeasureSpecMode; | |
| 95 | 95 | import getMeasureSpecSize = layout.getMeasureSpecSize; | |
| 96 | 96 | ||
| 97 | + // `eachLayoutChild` iterates over children, and we need more - indexed access. | ||
| 98 | + // This class tries to accomodate that by collecting all children in an | ||
| 99 | + // array no more than once per measure. | ||
| 100 | + class MeasureContext { | ||
| 101 | + private children: View[]; | ||
| 102 | + | ||
| 103 | + constructor(private owner: FlexboxLayout) { | ||
| 104 | + this.children = []; | ||
| 105 | + this.owner.eachLayoutChild((child) => { | ||
| 106 | + this.children.push(child); | ||
| 107 | + }); | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + public get childrenCount(): number { | ||
| 111 | + return this.children.length; | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + public childAt(index: number): View { | ||
| 115 | + return this.children[index]; | ||
| 116 | + } | ||
| 117 | + } | ||
| 118 | + | ||
| 97 | 119 | class FlexLine { | |
| 98 | 120 | ||
| 99 | 121 | _left: number = Number.MAX_VALUE; | |
@@ -144,15 +166,17 @@ export class FlexboxLayout extends FlexboxLayoutBase { | |||
| 144 | 166 | private _orderCache: number[]; | |
| 145 | 167 | private _flexLines: FlexLine[] = []; | |
| 146 | 168 | private _childrenFrozen: boolean[]; | |
| 169 | + private measureContext: MeasureContext; | ||
| 147 | 170 | ||
| 148 | 171 | public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void { | |
| 172 | + this.measureContext = new MeasureContext(this); | ||
| 149 | 173 | // Omit: super.onMeasure(widthMeasureSpec, heightMeasureSpec); | |
| 150 | 174 | ||
| 151 | 175 | if (this._isOrderChangedFromLastMeasurement) { | |
| 152 | 176 | this._reorderedIndices = this._createReorderedIndices(); | |
| 153 | 177 | } | |
| 154 | - if (!this._childrenFrozen || this._childrenFrozen.length < this.getChildrenCount()) { | ||
| 155 | - this._childrenFrozen = new Array(this.getChildrenCount()); | ||
| 178 | + if (!this._childrenFrozen || this._childrenFrozen.length < this.measureContext.childrenCount) { | ||
| 179 | + this._childrenFrozen = new Array(this.measureContext.childrenCount); | ||
| 156 | 180 | } | |
| 157 | 181 | ||
| 158 | 182 | switch (this.flexDirection) { | |
@@ -177,13 +201,13 @@ export class FlexboxLayout extends FlexboxLayoutBase { | |||
| 177 | 201 | child = null; | |
| 178 | 202 | } else { | |
| 179 | 203 | let reorderedIndex = this._reorderedIndices[index]; | |
| 180 | - child = this.getChildAt(reorderedIndex); | ||
| 204 | + child = this.measureContext.childAt(reorderedIndex); | ||
| 181 | 205 | } | |
| 182 | 206 | return child; | |
| 183 | 207 | } | |
| 184 | 208 | ||
| 185 | 209 | private _createReorderedIndices(): number[] { | |
| 186 | - let childCount = this.getChildrenCount(); | ||
| 210 | + let childCount = this.measureContext.childrenCount; | ||
| 187 | 211 | let orders = this._createOrders(childCount); | |
| 188 | 212 | return this._sortOrdersIntoReorderedIndices(childCount, orders); | |
| 189 | 213 | } | |
@@ -206,7 +230,7 @@ export class FlexboxLayout extends FlexboxLayoutBase { | |||
| 206 | 230 | private _createOrders(childCount: number): Order[] { | |
| 207 | 231 | let orders: Order[] = []; | |
| 208 | 232 | for (let i = 0; i < childCount; i++) { | |
| 209 | - let child = this.getChildAt(i); | ||
| 233 | + let child = this.measureContext.childAt(i); | ||
| 210 | 234 | let order = new Order(); | |
| 211 | 235 | order.order = FlexboxLayout.getOrder(child); | |
| 212 | 236 | order.index = i; | |
@@ -216,15 +240,15 @@ export class FlexboxLayout extends FlexboxLayoutBase { | |||
| 216 | 240 | } | |
| 217 | 241 | ||
| 218 | 242 | private get _isOrderChangedFromLastMeasurement(): boolean { | |
| 219 | - let childCount = this.getChildrenCount(); | ||
| 243 | + let childCount = this.measureContext.childrenCount; | ||
| 220 | 244 | if (!this._orderCache) { | |
| 221 | 245 | this._orderCache = []; | |
| 222 | 246 | } | |
| 223 | 247 | if (this._orderCache.length !== childCount) { | |
| 224 | 248 | return true; | |
| 225 | 249 | } | |
| 226 | 250 | for (let i = 0; i < childCount; i++) { | |
| 227 | - let view = this.getChildAt(i); | ||
| 251 | + let view = this.measureContext.childAt(i); | ||
| 228 | 252 | if (view === null) { | |
| 229 | 253 | continue; | |
| 230 | 254 | } | |
@@ -244,7 +268,7 @@ export class FlexboxLayout extends FlexboxLayoutBase { | |||
| 244 | 268 | this._flexLines.length = 0; | |
| 245 | 269 | ||
| 246 | 270 | (() => { | |
| 247 | - let childCount = this.getChildrenCount(); | ||
| 271 | + let childCount = this.measureContext.childrenCount; | ||
| 248 | 272 | let paddingStart = FlexboxLayout.getPaddingStart(this); | |
| 249 | 273 | let paddingEnd = FlexboxLayout.getPaddingEnd(this); | |
| 250 | 274 | let largestHeightInRow = Number.MIN_VALUE; | |
@@ -359,7 +383,7 @@ export class FlexboxLayout extends FlexboxLayoutBase { | |||
| 359 | 383 | ||
| 360 | 384 | this._flexLines.length = 0; | |
| 361 | 385 | ||
| 362 | - let childCount = this.getChildrenCount(); | ||
| 386 | + let childCount = this.measureContext.childrenCount; | ||
| 363 | 387 | let paddingTop = this.effectivePaddingTop; | |
| 364 | 388 | let paddingBottom = this.effectivePaddingBottom; | |
| 365 | 389 | let largestWidthInColumn = Number.MIN_VALUE; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments