uicore-ts 1.1.88 → 1.1.102
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiledScripts/UICore.js +3 -0
- package/compiledScripts/UICore.js.map +2 -2
- package/compiledScripts/UIRectangle.d.ts +4 -0
- package/compiledScripts/UIRectangle.js +19 -4
- package/compiledScripts/UIRectangle.js.map +2 -2
- package/compiledScripts/UITableView.d.ts +34 -0
- package/compiledScripts/UITableView.js +214 -25
- package/compiledScripts/UITableView.js.map +3 -3
- package/compiledScripts/UITextView.d.ts +49 -39
- package/compiledScripts/UITextView.js +137 -126
- package/compiledScripts/UITextView.js.map +2 -2
- package/compiledScripts/UIView.d.ts +40 -2
- package/compiledScripts/UIView.js +242 -89
- package/compiledScripts/UIView.js.map +2 -2
- package/package.json +1 -1
- package/scripts/UICore.ts +5 -0
- package/scripts/UIRectangle.ts +35 -5
- package/scripts/UITableView.ts +330 -93
- package/scripts/UITextView.ts +273 -358
- package/scripts/UIView.ts +361 -90
package/scripts/UIView.ts
CHANGED
|
@@ -117,7 +117,7 @@ export type UIViewAddControlEventTargetObject<T extends { controlEvent: Record<s
|
|
|
117
117
|
sender: UIView,
|
|
118
118
|
event: Event
|
|
119
119
|
) => void) & Partial<UIViewAddControlEventTargetObject<T>>
|
|
120
|
-
|
|
120
|
+
|
|
121
121
|
}>
|
|
122
122
|
|
|
123
123
|
|
|
@@ -149,7 +149,8 @@ export class UIView extends UIObject {
|
|
|
149
149
|
_UIViewIntrinsicTemporaryWidth?: string
|
|
150
150
|
_UIViewIntrinsicTemporaryHeight?: string
|
|
151
151
|
_enabled: boolean = YES
|
|
152
|
-
_frame?: UIRectangle & { zIndex?: number }
|
|
152
|
+
_frame?: UIRectangle & { zIndex?: number };
|
|
153
|
+
_frameCache?: UIRectangle
|
|
153
154
|
_backgroundColor: UIColor = UIColor.transparentColor
|
|
154
155
|
|
|
155
156
|
_viewHTMLElement!: HTMLElement & LooseObject
|
|
@@ -228,13 +229,35 @@ export class UIView extends UIObject {
|
|
|
228
229
|
private _resizeObserverEntry?: ResizeObserverEntry
|
|
229
230
|
protected _intrinsicSizesCache: Record<string, UIRectangle> = {}
|
|
230
231
|
|
|
231
|
-
static
|
|
232
|
+
private static _virtualLayoutingDepth = 0
|
|
233
|
+
|
|
234
|
+
static get isVirtualLayouting(): boolean {
|
|
235
|
+
return this._virtualLayoutingDepth > 0
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
get isVirtualLayouting(): boolean {
|
|
239
|
+
return UIView._virtualLayoutingDepth > 0
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
startVirtualLayout() {
|
|
243
|
+
UIView._virtualLayoutingDepth = UIView._virtualLayoutingDepth + 1
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
finishVirtualLayout() {
|
|
247
|
+
if (UIView._virtualLayoutingDepth === 0) {
|
|
248
|
+
throw new Error("Unbalanced finishVirtualLayout()")
|
|
249
|
+
}
|
|
250
|
+
UIView._virtualLayoutingDepth = UIView._virtualLayoutingDepth - 1
|
|
251
|
+
}
|
|
252
|
+
|
|
232
253
|
_frameForVirtualLayouting?: UIRectangle
|
|
233
254
|
|
|
234
255
|
// Change this to no if the view contains pure HTML content that does not
|
|
235
256
|
// use frame logic that can influence the intrinsic size
|
|
236
257
|
usesVirtualLayoutingForIntrinsicSizing = YES
|
|
237
258
|
|
|
259
|
+
_contentInsets = { top: 0, left: 0, bottom: 0, right: 0 }
|
|
260
|
+
|
|
238
261
|
|
|
239
262
|
constructor(
|
|
240
263
|
elementID: string = ("UIView" + UIView.nextIndex),
|
|
@@ -270,24 +293,145 @@ export class UIView extends UIObject {
|
|
|
270
293
|
}
|
|
271
294
|
|
|
272
295
|
|
|
273
|
-
static get pageHeight() {
|
|
296
|
+
// static get pageHeight() {
|
|
297
|
+
// const body = document.body
|
|
298
|
+
// const html = document.documentElement
|
|
299
|
+
// return Math.max(
|
|
300
|
+
// body.scrollHeight,
|
|
301
|
+
// body.offsetHeight,
|
|
302
|
+
// html.clientHeight,
|
|
303
|
+
// html.scrollHeight,
|
|
304
|
+
// html.offsetHeight
|
|
305
|
+
// )
|
|
306
|
+
// }
|
|
307
|
+
//
|
|
308
|
+
// static get pageWidth() {
|
|
309
|
+
// const body = document.body
|
|
310
|
+
// const html = document.documentElement
|
|
311
|
+
// return Math.max(body.scrollWidth, body.offsetWidth, html.clientWidth, html.scrollWidth, html.offsetWidth)
|
|
312
|
+
// }
|
|
313
|
+
|
|
314
|
+
//#region Static Properties - Page Dimensions Cache
|
|
315
|
+
|
|
316
|
+
private static _cachedPageWidth: number | undefined
|
|
317
|
+
private static _cachedPageHeight: number | undefined
|
|
318
|
+
private static _pageDimensionsCacheValid = false
|
|
319
|
+
private static _resizeObserverInitialized = false
|
|
320
|
+
|
|
321
|
+
//#endregion
|
|
322
|
+
|
|
323
|
+
//#region Static Methods - Page Dimensions
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Initialize resize observer to invalidate cache when page dimensions change.
|
|
327
|
+
* This is called lazily on first access.
|
|
328
|
+
*/
|
|
329
|
+
private static _initializePageDimensionsCacheIfNeeded() {
|
|
330
|
+
if (this._resizeObserverInitialized) {
|
|
331
|
+
return
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
this._resizeObserverInitialized = true
|
|
335
|
+
|
|
336
|
+
// Invalidate cache on window resize
|
|
337
|
+
window.addEventListener('resize', () => {
|
|
338
|
+
this._pageDimensionsCacheValid = false
|
|
339
|
+
}, { passive: true })
|
|
340
|
+
|
|
341
|
+
// Observe document.body for mutations that might affect dimensions
|
|
342
|
+
const bodyObserver = new ResizeObserver(() => {
|
|
343
|
+
this._pageDimensionsCacheValid = false
|
|
344
|
+
})
|
|
345
|
+
|
|
346
|
+
// Start observing once body is available
|
|
347
|
+
if (document.body) {
|
|
348
|
+
bodyObserver.observe(document.body)
|
|
349
|
+
} else {
|
|
350
|
+
// Wait for DOMContentLoaded if body isn't ready yet
|
|
351
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
352
|
+
bodyObserver.observe(document.body)
|
|
353
|
+
}, { once: true })
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// Also invalidate on DOM mutations that might add/remove content
|
|
357
|
+
const mutationObserver = new MutationObserver(() => {
|
|
358
|
+
this._pageDimensionsCacheValid = false
|
|
359
|
+
})
|
|
360
|
+
|
|
361
|
+
const observeMutations = () => {
|
|
362
|
+
mutationObserver.observe(document.body, {
|
|
363
|
+
childList: true,
|
|
364
|
+
subtree: true,
|
|
365
|
+
attributes: true,
|
|
366
|
+
attributeFilter: ['style', 'class']
|
|
367
|
+
})
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
if (document.body) {
|
|
371
|
+
observeMutations()
|
|
372
|
+
} else {
|
|
373
|
+
document.addEventListener('DOMContentLoaded', observeMutations, { once: true })
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Compute and cache page dimensions.
|
|
379
|
+
* Only triggers reflow when cache is invalid.
|
|
380
|
+
*/
|
|
381
|
+
private static _updatePageDimensionsCacheIfNeeded() {
|
|
382
|
+
if (this._pageDimensionsCacheValid &&
|
|
383
|
+
this._cachedPageWidth !== undefined &&
|
|
384
|
+
this._cachedPageHeight !== undefined) {
|
|
385
|
+
return
|
|
386
|
+
}
|
|
387
|
+
|
|
274
388
|
const body = document.body
|
|
275
389
|
const html = document.documentElement
|
|
276
|
-
|
|
390
|
+
|
|
391
|
+
// Compute both at once to minimize reflows
|
|
392
|
+
this._cachedPageWidth = Math.max(
|
|
393
|
+
body.scrollWidth,
|
|
394
|
+
body.offsetWidth,
|
|
395
|
+
html.clientWidth,
|
|
396
|
+
html.scrollWidth,
|
|
397
|
+
html.offsetWidth
|
|
398
|
+
)
|
|
399
|
+
|
|
400
|
+
this._cachedPageHeight = Math.max(
|
|
277
401
|
body.scrollHeight,
|
|
278
402
|
body.offsetHeight,
|
|
279
403
|
html.clientHeight,
|
|
280
404
|
html.scrollHeight,
|
|
281
405
|
html.offsetHeight
|
|
282
406
|
)
|
|
407
|
+
|
|
408
|
+
this._pageDimensionsCacheValid = true
|
|
283
409
|
}
|
|
284
410
|
|
|
285
411
|
static get pageWidth() {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
return
|
|
412
|
+
this._initializePageDimensionsCacheIfNeeded()
|
|
413
|
+
this._updatePageDimensionsCacheIfNeeded()
|
|
414
|
+
return this._cachedPageWidth!
|
|
289
415
|
}
|
|
290
416
|
|
|
417
|
+
static get pageHeight() {
|
|
418
|
+
this._initializePageDimensionsCacheIfNeeded()
|
|
419
|
+
this._updatePageDimensionsCacheIfNeeded()
|
|
420
|
+
return this._cachedPageHeight!
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Manually invalidate the page dimensions cache.
|
|
425
|
+
* Useful if you know dimensions changed and want to force a recalculation.
|
|
426
|
+
*/
|
|
427
|
+
static invalidatePageDimensionsCache() {
|
|
428
|
+
this._pageDimensionsCacheValid = false
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
//#endregion
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
|
|
291
435
|
centerInContainer() {
|
|
292
436
|
this.style.left = "50%"
|
|
293
437
|
this.style.top = "50%"
|
|
@@ -890,7 +1034,7 @@ export class UIView extends UIObject {
|
|
|
890
1034
|
|
|
891
1035
|
public get frame() {
|
|
892
1036
|
let result: UIRectangle & { zIndex?: number }
|
|
893
|
-
if (!
|
|
1037
|
+
if (!this.isVirtualLayouting) {
|
|
894
1038
|
result = this._frame?.copy() as any
|
|
895
1039
|
}
|
|
896
1040
|
else {
|
|
@@ -923,7 +1067,7 @@ export class UIView extends UIObject {
|
|
|
923
1067
|
if (zIndex != undefined) {
|
|
924
1068
|
rectangle.zIndex = zIndex
|
|
925
1069
|
}
|
|
926
|
-
if (!
|
|
1070
|
+
if (!this.isVirtualLayouting) {
|
|
927
1071
|
this._frame = rectangle
|
|
928
1072
|
}
|
|
929
1073
|
else {
|
|
@@ -939,7 +1083,7 @@ export class UIView extends UIObject {
|
|
|
939
1083
|
rectangle.scale(1 / this.scale)
|
|
940
1084
|
}
|
|
941
1085
|
|
|
942
|
-
if (!
|
|
1086
|
+
if (!this.isVirtualLayouting) {
|
|
943
1087
|
UIView._setAbsoluteSizeAndPosition(
|
|
944
1088
|
this.viewHTMLElement,
|
|
945
1089
|
rectangle.topLeft.x,
|
|
@@ -961,7 +1105,7 @@ export class UIView extends UIObject {
|
|
|
961
1105
|
get bounds() {
|
|
962
1106
|
|
|
963
1107
|
let _frame: (UIRectangle & { zIndex?: number }) | undefined
|
|
964
|
-
if (!
|
|
1108
|
+
if (!this.isVirtualLayouting) {
|
|
965
1109
|
_frame = this._frame
|
|
966
1110
|
}
|
|
967
1111
|
else {
|
|
@@ -970,16 +1114,17 @@ export class UIView extends UIObject {
|
|
|
970
1114
|
|
|
971
1115
|
let result: UIRectangle
|
|
972
1116
|
if (IS_NOT(_frame)) {
|
|
973
|
-
result = new UIRectangle(
|
|
1117
|
+
result = this._frameCache ?? new UIRectangle(
|
|
974
1118
|
0,
|
|
975
1119
|
0,
|
|
976
1120
|
this._resizeObserverEntry?.contentRect.height ?? this.viewHTMLElement.offsetHeight,
|
|
977
1121
|
this._resizeObserverEntry?.contentRect.width ?? this.viewHTMLElement.offsetWidth
|
|
978
1122
|
)
|
|
1123
|
+
this._frameCache = result
|
|
979
1124
|
}
|
|
980
1125
|
else {
|
|
981
1126
|
let frame: (UIRectangle & { zIndex?: number })
|
|
982
|
-
if (!
|
|
1127
|
+
if (!this.isVirtualLayouting) {
|
|
983
1128
|
frame = this.frame
|
|
984
1129
|
}
|
|
985
1130
|
else {
|
|
@@ -989,6 +1134,10 @@ export class UIView extends UIObject {
|
|
|
989
1134
|
result.x = 0
|
|
990
1135
|
result.y = 0
|
|
991
1136
|
}
|
|
1137
|
+
|
|
1138
|
+
result.minHeight = 0
|
|
1139
|
+
result.minWidth = 0
|
|
1140
|
+
|
|
992
1141
|
return result
|
|
993
1142
|
}
|
|
994
1143
|
|
|
@@ -1009,6 +1158,7 @@ export class UIView extends UIObject {
|
|
|
1009
1158
|
didResize(entry: ResizeObserverEntry) {
|
|
1010
1159
|
|
|
1011
1160
|
this._resizeObserverEntry = entry
|
|
1161
|
+
this._frameCache = undefined
|
|
1012
1162
|
this.setNeedsLayout()
|
|
1013
1163
|
|
|
1014
1164
|
this.boundsDidChange(new UIRectangle(0, 0, entry.contentRect.height, entry.contentRect.width))
|
|
@@ -1579,17 +1729,52 @@ export class UIView extends UIObject {
|
|
|
1579
1729
|
|
|
1580
1730
|
|
|
1581
1731
|
static layoutViewsIfNeeded() {
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1732
|
+
const maxIterations = 10
|
|
1733
|
+
let iteration = 0
|
|
1734
|
+
const layoutCounts = new Map<UIView, number>() // Track how many times each view has been laid out
|
|
1735
|
+
|
|
1736
|
+
while (UIView._viewsToLayout.length > 0 && iteration < maxIterations) {
|
|
1737
|
+
const viewsToProcess = UIView._viewsToLayout
|
|
1738
|
+
UIView._viewsToLayout = []
|
|
1739
|
+
|
|
1740
|
+
const viewDepthMap = new Map<UIView, number>()
|
|
1741
|
+
|
|
1742
|
+
for (let i = 0; i < viewsToProcess.length; i++) {
|
|
1743
|
+
const view = viewsToProcess[i]
|
|
1744
|
+
const layoutCount = layoutCounts.get(view) || 0
|
|
1745
|
+
|
|
1746
|
+
// Skip if this view has been laid out too many times (cycle detection)
|
|
1747
|
+
if (layoutCount >= 5) {
|
|
1748
|
+
console.warn('View layout cycle detected:', view)
|
|
1749
|
+
continue
|
|
1750
|
+
}
|
|
1751
|
+
|
|
1752
|
+
if (!viewDepthMap.has(view)) {
|
|
1753
|
+
viewDepthMap.set(view, view.withAllSuperviews.length)
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
|
|
1757
|
+
const sortedViews = Array.from(viewDepthMap.keys()).sort((a, b) => {
|
|
1758
|
+
return viewDepthMap.get(a)! - viewDepthMap.get(b)!
|
|
1759
|
+
})
|
|
1760
|
+
|
|
1761
|
+
for (let i = 0; i < sortedViews.length; i++) {
|
|
1762
|
+
const view = sortedViews[i]
|
|
1763
|
+
view.layoutIfNeeded()
|
|
1764
|
+
layoutCounts.set(view, (layoutCounts.get(view) || 0) + 1)
|
|
1765
|
+
}
|
|
1766
|
+
|
|
1767
|
+
iteration++
|
|
1585
1768
|
}
|
|
1586
|
-
|
|
1769
|
+
|
|
1770
|
+
// console.log(iteration + " iterations to finish layout")
|
|
1771
|
+
|
|
1587
1772
|
}
|
|
1588
1773
|
|
|
1589
1774
|
|
|
1590
1775
|
setNeedsLayout() {
|
|
1591
1776
|
|
|
1592
|
-
if (this._shouldLayout) {
|
|
1777
|
+
if (this._shouldLayout && UIView._viewsToLayout.contains(this)) {
|
|
1593
1778
|
return
|
|
1594
1779
|
}
|
|
1595
1780
|
|
|
@@ -1598,7 +1783,7 @@ export class UIView extends UIObject {
|
|
|
1598
1783
|
// Register view for layout before next frame
|
|
1599
1784
|
UIView._viewsToLayout.push(this)
|
|
1600
1785
|
|
|
1601
|
-
this.
|
|
1786
|
+
this.clearIntrinsicSizeCache()
|
|
1602
1787
|
|
|
1603
1788
|
if (UIView._viewsToLayout.length == 1) {
|
|
1604
1789
|
UIView.scheduleLayoutViewsIfNeeded()
|
|
@@ -1620,7 +1805,9 @@ export class UIView extends UIObject {
|
|
|
1620
1805
|
return
|
|
1621
1806
|
}
|
|
1622
1807
|
|
|
1623
|
-
this.
|
|
1808
|
+
if (!this.isVirtualLayouting) {
|
|
1809
|
+
this._shouldLayout = NO
|
|
1810
|
+
}
|
|
1624
1811
|
|
|
1625
1812
|
try {
|
|
1626
1813
|
|
|
@@ -1639,7 +1826,9 @@ export class UIView extends UIObject {
|
|
|
1639
1826
|
|
|
1640
1827
|
this.willLayoutSubviews()
|
|
1641
1828
|
|
|
1642
|
-
this.
|
|
1829
|
+
if (!this.isVirtualLayouting) {
|
|
1830
|
+
this._shouldLayout = NO
|
|
1831
|
+
}
|
|
1643
1832
|
|
|
1644
1833
|
// Autolayout
|
|
1645
1834
|
if (this.constraints.length) {
|
|
@@ -3350,10 +3539,72 @@ export class UIView extends UIObject {
|
|
|
3350
3539
|
}
|
|
3351
3540
|
|
|
3352
3541
|
|
|
3542
|
+
get contentBounds(): UIRectangle {
|
|
3543
|
+
|
|
3544
|
+
const bounds = this.bounds
|
|
3545
|
+
const insets = this._contentInsets
|
|
3546
|
+
|
|
3547
|
+
return new UIRectangle(
|
|
3548
|
+
insets.left,
|
|
3549
|
+
insets.top,
|
|
3550
|
+
bounds.height - insets.top - insets.bottom,
|
|
3551
|
+
bounds.width - insets.left - insets.right
|
|
3552
|
+
)
|
|
3553
|
+
|
|
3554
|
+
}
|
|
3555
|
+
|
|
3556
|
+
contentBoundsWithInset(inset: number): UIRectangle {
|
|
3557
|
+
this._contentInsets = { top: inset, left: inset, bottom: inset, right: inset }
|
|
3558
|
+
const bounds = this.bounds
|
|
3559
|
+
return new UIRectangle(
|
|
3560
|
+
inset,
|
|
3561
|
+
inset,
|
|
3562
|
+
bounds.height - inset * 2,
|
|
3563
|
+
bounds.width - inset * 2
|
|
3564
|
+
)
|
|
3565
|
+
}
|
|
3566
|
+
|
|
3567
|
+
contentBoundsWithInsets(
|
|
3568
|
+
left: number,
|
|
3569
|
+
right: number,
|
|
3570
|
+
bottom: number,
|
|
3571
|
+
top: number
|
|
3572
|
+
): UIRectangle {
|
|
3573
|
+
this._contentInsets = { left, right, bottom, top }
|
|
3574
|
+
const bounds = this.bounds
|
|
3575
|
+
return new UIRectangle(
|
|
3576
|
+
left,
|
|
3577
|
+
top,
|
|
3578
|
+
bounds.height - top - bottom,
|
|
3579
|
+
bounds.width - left - right
|
|
3580
|
+
)
|
|
3581
|
+
}
|
|
3582
|
+
|
|
3583
|
+
private _getIntrinsicSizeCacheKey(constrainingHeight: number, constrainingWidth: number): string {
|
|
3584
|
+
return `h_${constrainingHeight}__w_${constrainingWidth}`
|
|
3585
|
+
}
|
|
3586
|
+
|
|
3587
|
+
private _getCachedIntrinsicSize(cacheKey: string): UIRectangle | undefined {
|
|
3588
|
+
return this._intrinsicSizesCache[cacheKey]
|
|
3589
|
+
}
|
|
3590
|
+
|
|
3591
|
+
private _setCachedIntrinsicSize(cacheKey: string, size: UIRectangle): void {
|
|
3592
|
+
this._intrinsicSizesCache[cacheKey] = size.copy()
|
|
3593
|
+
}
|
|
3594
|
+
|
|
3595
|
+
clearIntrinsicSizeCache(): void {
|
|
3596
|
+
this._intrinsicSizesCache = {}
|
|
3597
|
+
|
|
3598
|
+
// Optionally clear parent cache if this view affects parent's intrinsic size
|
|
3599
|
+
if (this.superview?.usesVirtualLayoutingForIntrinsicSizing) {
|
|
3600
|
+
this.superview.clearIntrinsicSizeCache()
|
|
3601
|
+
}
|
|
3602
|
+
}
|
|
3603
|
+
|
|
3353
3604
|
intrinsicContentSizeWithConstraints(constrainingHeight: number = 0, constrainingWidth: number = 0) {
|
|
3354
3605
|
|
|
3355
|
-
const cacheKey =
|
|
3356
|
-
const cachedResult = this.
|
|
3606
|
+
const cacheKey = this._getIntrinsicSizeCacheKey(constrainingHeight, constrainingWidth)
|
|
3607
|
+
const cachedResult = this._getCachedIntrinsicSize(cacheKey)
|
|
3357
3608
|
if (cachedResult) {
|
|
3358
3609
|
return cachedResult
|
|
3359
3610
|
}
|
|
@@ -3425,100 +3676,120 @@ export class UIView extends UIObject {
|
|
|
3425
3676
|
result.height = resultHeight
|
|
3426
3677
|
result.width = resultWidth
|
|
3427
3678
|
|
|
3428
|
-
|
|
3429
|
-
this._intrinsicSizesCache[cacheKey] = result.copy()
|
|
3679
|
+
this._setCachedIntrinsicSize(cacheKey, result)
|
|
3430
3680
|
|
|
3431
3681
|
return result
|
|
3432
3682
|
|
|
3433
3683
|
}
|
|
3434
3684
|
|
|
3685
|
+
|
|
3686
|
+
private _intrinsicFrameFromSubviewFrames() {
|
|
3687
|
+
|
|
3688
|
+
const framePoints: UIPoint[] = []
|
|
3689
|
+
this.subviews.forEach(subview => {
|
|
3690
|
+
subview.layoutIfNeeded()
|
|
3691
|
+
framePoints.push(subview.frame.min)
|
|
3692
|
+
framePoints.push(subview.frame.max)
|
|
3693
|
+
})
|
|
3694
|
+
// Since this is always called inside a virtual layouting context,
|
|
3695
|
+
// we will add padding based on the _contentInsets
|
|
3696
|
+
const resultFrame = UIRectangle.boundingBoxForPoints(framePoints)
|
|
3697
|
+
.rectangleWithInsets(
|
|
3698
|
+
-this._contentInsets?.left ?? 0,
|
|
3699
|
+
-this._contentInsets?.right ?? 0,
|
|
3700
|
+
-this._contentInsets?.bottom ?? 0,
|
|
3701
|
+
-this._contentInsets?.top ?? 0
|
|
3702
|
+
)
|
|
3703
|
+
return resultFrame
|
|
3704
|
+
}
|
|
3705
|
+
|
|
3706
|
+
|
|
3435
3707
|
intrinsicContentWidth(constrainingHeight: number = 0): number {
|
|
3436
3708
|
|
|
3709
|
+
const cacheKey = this._getIntrinsicSizeCacheKey(constrainingHeight, 0)
|
|
3710
|
+
const cached = this._getCachedIntrinsicSize(cacheKey)
|
|
3711
|
+
if (cached) {
|
|
3712
|
+
return cached.width
|
|
3713
|
+
}
|
|
3714
|
+
|
|
3437
3715
|
if (this.usesVirtualLayoutingForIntrinsicSizing) {
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
this,
|
|
3451
|
-
YES
|
|
3452
|
-
)
|
|
3453
|
-
}
|
|
3454
|
-
framePoints.push(frame.min)
|
|
3455
|
-
framePoints.push(frame.max)
|
|
3456
|
-
})
|
|
3457
|
-
const resultFrame = UIRectangle.boundingBoxForPoints(framePoints)
|
|
3458
|
-
UIView.isVirtualLayouting = NO
|
|
3716
|
+
this.startVirtualLayout()
|
|
3717
|
+
let resultFrame: UIRectangle
|
|
3718
|
+
try {
|
|
3719
|
+
this.frame = this.frame.rectangleWithHeight(constrainingHeight)
|
|
3720
|
+
this.layoutIfNeeded()
|
|
3721
|
+
resultFrame = this._intrinsicFrameFromSubviewFrames()
|
|
3722
|
+
}
|
|
3723
|
+
finally {
|
|
3724
|
+
this.finishVirtualLayout()
|
|
3725
|
+
}
|
|
3726
|
+
|
|
3727
|
+
this._setCachedIntrinsicSize(cacheKey, new UIRectangle(0, 0, resultFrame.height, resultFrame.width))
|
|
3459
3728
|
return resultFrame.width
|
|
3460
3729
|
}
|
|
3461
3730
|
|
|
3462
|
-
|
|
3731
|
+
const size = this.intrinsicContentSizeWithConstraints(constrainingHeight, 0)
|
|
3732
|
+
return size.width
|
|
3463
3733
|
|
|
3464
3734
|
}
|
|
3465
3735
|
|
|
3736
|
+
|
|
3466
3737
|
intrinsicContentHeight(constrainingWidth: number = 0): number {
|
|
3467
3738
|
|
|
3739
|
+
const cacheKey = this._getIntrinsicSizeCacheKey(0, constrainingWidth)
|
|
3740
|
+
const cached = this._getCachedIntrinsicSize(cacheKey)
|
|
3741
|
+
if (cached) {
|
|
3742
|
+
return cached.height
|
|
3743
|
+
}
|
|
3744
|
+
|
|
3468
3745
|
if (this.usesVirtualLayoutingForIntrinsicSizing) {
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
this,
|
|
3482
|
-
YES
|
|
3483
|
-
)
|
|
3484
|
-
}
|
|
3485
|
-
framePoints.push(frame.min)
|
|
3486
|
-
framePoints.push(frame.max)
|
|
3487
|
-
})
|
|
3488
|
-
const resultFrame = UIRectangle.boundingBoxForPoints(framePoints)
|
|
3489
|
-
UIView.isVirtualLayouting = NO
|
|
3746
|
+
this.startVirtualLayout()
|
|
3747
|
+
let resultFrame: UIRectangle
|
|
3748
|
+
try {
|
|
3749
|
+
this.frame = this.frame.rectangleWithWidth(constrainingWidth)
|
|
3750
|
+
this.layoutIfNeeded()
|
|
3751
|
+
resultFrame = this._intrinsicFrameFromSubviewFrames()
|
|
3752
|
+
}
|
|
3753
|
+
finally {
|
|
3754
|
+
this.finishVirtualLayout()
|
|
3755
|
+
}
|
|
3756
|
+
|
|
3757
|
+
this._setCachedIntrinsicSize(cacheKey, new UIRectangle(0, 0, resultFrame.height, resultFrame.width))
|
|
3490
3758
|
return resultFrame.height
|
|
3491
3759
|
}
|
|
3492
3760
|
|
|
3493
|
-
|
|
3761
|
+
const size = this.intrinsicContentSizeWithConstraints(0, constrainingWidth)
|
|
3494
3762
|
|
|
3763
|
+
if (isNaN(size.height)) {
|
|
3764
|
+
console.error("NaN in intrinsicContentHeight", this)
|
|
3765
|
+
var asd = 1
|
|
3766
|
+
}
|
|
3767
|
+
|
|
3768
|
+
return size.height
|
|
3495
3769
|
|
|
3496
3770
|
}
|
|
3497
3771
|
|
|
3498
3772
|
|
|
3499
3773
|
intrinsicContentSize(): UIRectangle {
|
|
3500
3774
|
|
|
3775
|
+
const cacheKey = this._getIntrinsicSizeCacheKey(0, 0)
|
|
3776
|
+
const cached = this._getCachedIntrinsicSize(cacheKey)
|
|
3777
|
+
if (cached) {
|
|
3778
|
+
return cached
|
|
3779
|
+
}
|
|
3780
|
+
|
|
3501
3781
|
if (this.usesVirtualLayoutingForIntrinsicSizing) {
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
this,
|
|
3514
|
-
YES
|
|
3515
|
-
)
|
|
3516
|
-
}
|
|
3517
|
-
framePoints.push(frame.min)
|
|
3518
|
-
framePoints.push(frame.max)
|
|
3519
|
-
})
|
|
3520
|
-
const resultFrame = UIRectangle.boundingBoxForPoints(framePoints)
|
|
3521
|
-
UIView.isVirtualLayouting = NO
|
|
3782
|
+
this.startVirtualLayout()
|
|
3783
|
+
let resultFrame: UIRectangle
|
|
3784
|
+
try {
|
|
3785
|
+
this.layoutIfNeeded()
|
|
3786
|
+
resultFrame = this._intrinsicFrameFromSubviewFrames()
|
|
3787
|
+
}
|
|
3788
|
+
finally {
|
|
3789
|
+
this.finishVirtualLayout()
|
|
3790
|
+
}
|
|
3791
|
+
|
|
3792
|
+
this._setCachedIntrinsicSize(cacheKey, resultFrame)
|
|
3522
3793
|
return resultFrame
|
|
3523
3794
|
}
|
|
3524
3795
|
|