-
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 4 commits
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 |
|---|---|---|
|
|
@@ -84,6 +84,18 @@ protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) | |
| platformWidth = Math.Max(MinimumWidth, platformWidth); | ||
| platformHeight = Math.Max(MinimumHeight, platformHeight); | ||
|
|
||
| // Update the ContentView's Frame so that Width and Height properties are available | ||
| // to child elements during layout calculations, especially in CollectionView scenarios | ||
| if (CrossPlatformLayout is IView contentView) | ||
| { | ||
| var currentFrame = contentView.Frame; | ||
| var newFrame = new Graphics.Rect(currentFrame.X, currentFrame.Y, width, height); | ||
| if (currentFrame != newFrame) | ||
| { | ||
| contentView.Frame = newFrame; | ||
| } | ||
| } | ||
|
|
||
| SetMeasuredDimension((int)platformWidth, (int)platformHeight); | ||
| } | ||
|
|
||
|
|
@@ -97,6 +109,19 @@ protected override void OnLayout(bool changed, int left, int top, int right, int | |
| var destination = _context.ToCrossPlatformRectInReferenceFrame(left, top, right, bottom); | ||
|
|
||
| CrossPlatformArrange(destination); | ||
|
|
||
|
||
| // Ensure the ContentView's Frame is updated with the final layout bounds | ||
| // This is especially important during scrolling scenarios where the Frame | ||
| // might be reset or updated after the measure pass | ||
| if (CrossPlatformLayout is IView contentView) | ||
| { | ||
| var currentFrame = contentView.Frame; | ||
| var newFrame = destination; | ||
| if (currentFrame != newFrame) | ||
| { | ||
| contentView.Frame = newFrame; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| internal IBorderStroke? Clip | ||
|
|
||
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.
The progress bars still render incorrectly when you scroll.
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.
I've identified and fixed the scrolling issue. The problem was that during CollectionView scrolling, the ContentView's Frame was being updated multiple times through different code paths, and my original fix in OnMeasure wasn't sufficient.
I've now enhanced the fix to also update the Frame in OnLayout (after CrossPlatformArrange), ensuring that child elements have consistent access to the parent's Width property even during scrolling scenarios. The fix maintains the Frame with the correct layout bounds throughout the entire layout cycle.
Changes in commit 51a1d77:
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.
After Refreshing the ItemsSource , the contentview is updated width is properly updated
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.
Great to hear that refreshing the ItemsSource works correctly! This confirms the fix is working in that scenario. I've now made the implementation more targeted to address your feedback about the fix location (commit d0f54ab).