-
Notifications
You must be signed in to change notification settings - Fork 0
Fix ContentView Width property not available to children in Android CollectionView #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
55b08c4
9a64379
d7343f5
51a1d77
d0f54ab
4606b44
12b684d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,6 +90,19 @@ protected override void OnLayout(bool changed, int l, int t, int r, int b) | |
| { | ||
| handler.LayoutVirtualView(l, t, r, b); | ||
| } | ||
|
|
||
| // Ensure the ContentView's Frame is updated with the final layout bounds | ||
| // This is especially important during scrolling scenarios in CollectionView | ||
| if (View is ContentView contentView) | ||
| { | ||
| var currentFrame = contentView.Frame; | ||
| var newFrame = new Graphics.Rect(this.FromPixels(l), this.FromPixels(t), | ||
| this.FromPixels(r - l), this.FromPixels(b - t)); | ||
| if (currentFrame != newFrame) | ||
| { | ||
| contentView.Frame = newFrame; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) | ||
|
|
@@ -204,6 +217,18 @@ _pixelSize is not null && | |
|
|
||
| ReportMeasure?.Invoke(new Size(pixelWidth, pixelHeight)); | ||
|
|
||
| // Update the ContentView's Frame so that Width and Height properties are available | ||
| // to child elements during layout calculations in CollectionView scenarios | ||
|
||
| if (View is ContentView contentView) | ||
| { | ||
| var currentFrame = contentView.Frame; | ||
| var newFrame = new Graphics.Rect(currentFrame.X, currentFrame.Y, width, height); | ||
| if (currentFrame != newFrame) | ||
| { | ||
| contentView.Frame = newFrame; | ||
| } | ||
| } | ||
|
|
||
| SetMeasuredDimension(pixelWidth, pixelHeight); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This issue isn't specific to ContentView — it's caused by the hierarchical structure of the item templates. CollectionView does not measure all the nested elements within each item, which leads to incorrect sizing or layout behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're absolutely right. I've updated the fix to address the broader hierarchical structure issue rather than targeting just ContentView. The fix now ensures that any View in the item template hierarchy has its Frame properly updated before child measurements, addressing the root cause where CollectionView doesn't properly measure all nested elements. Commit 7a36e18 makes this change.