NSCollectionView Liquid Glass Section Headers Don't Show After Fading Out on Scroll Sometimes

I'm noticing some weird glitches with my collection view headers on macOS Tahoe.

The sections headers are pinned to the visible region. I headers fade out when scrolling and are supposed to fade back in but sometimes they don't fade back in and the header remains but the header text doesn't come back (until I scroll again).

How can I turn off this scroll animation thingy?

Anyway so I can do the following to basically "disable it":

  1. Continue drawing my section header background color in -drawRect: (windowBackgroundColor works for me)
  2. Instead of using NSColor +headerTextColor: for the text In the header view use colors that aren't dynamic like:

+NSColor.whiteColor for the text color in a dark NSAppearance +NSColor.blackColor for the text color in a light appearance.

So either make a custom color in an Asset catalog for the above or just override -viewDidChangeEffectiveAppearance: and change the NSTextFields textColor directly based on the current appearance.

I'm just drawing over the scroll edge effect rather than disabling it. But that'll have to do.

so it looks like my NSView subclass which is my <NSCollectionViewSectionHeaderView> overrides draw rect. I wrote this like 7 or 8 years ago and forgot..

And in -drawRect I used NSColor +windowBackgroundGroundColor to fill the section header background. I must've added this because text in the section header was probably really blurry on non-retina displays.

The NSTextField inside the section header is using the headerTextColor FWIW.

So it appears Liquid Glass animation thing changes the top header text from black to white at certain points in the scroll. Not sure why, seems to be when section 0 scrolls on screen (even if we are not really even close to the top of it). Looks like maybe it's misinterpreting the background. Only a little bit of a collection view icon overlaps the section header (but the background is mostly white). The text should only turn white if it was overlapping a truly dark background. Not just like a partial overlap with a small icon in the collection view.

Anyway if I remove my fill code in draw rect I see the Liquid Glass thingy draw a glass/shadow blur behind it so you can see the white text a bit. With windowBackgroundColor it was completely blending in.

But even after removing my background fill...when the text turns white it still seems like a glitch. Sometimes the text doesn't reappear at all (when I scroll all the way to the top for instance and the header is completely behind white background, the text stays white) so I'd still like to disable.

Is there good reliable override point for glass state so I can change the text color? I was unable to find any API in NSCollectionView header, NSSCrollView header to detect the scroll edge effect state?

just watched the "Build an appkit app with the new design" video. There is a section on the scroll edge effect but there is no mention how to deal with it. How can I customize my drawing when my view is inside the "scroll edge effect"

There was stuff about Split View, toolbar items, but nothing about collection view.


Accepted Answer

Anyway so I can do the following to basically "disable it":

  1. Continue drawing my section header background color in -drawRect: (windowBackgroundColor works for me)
  2. Instead of using NSColor +headerTextColor: for the text In the header view use colors that aren't dynamic like:

+NSColor.whiteColor for the text color in a dark NSAppearance +NSColor.blackColor for the text color in a light appearance.

So either make a custom color in an Asset catalog for the above or just override -viewDidChangeEffectiveAppearance: and change the NSTextFields textColor directly based on the current appearance.

I'm just drawing over the scroll edge effect rather than disabling it. But that'll have to do.

Just to add:

Continue drawing my section header background color in -drawRect: (windowBackgroundColor works for me)

Oh right NSColor header file says not to use windowBackgroundColor for drawing so I'll pick something else. But avoiding the dynamic system colors in the collection view header view and adapting to light/dark mode manually does the trick.

NSCollectionView Liquid Glass Section Headers Don't Show After Fading Out on Scroll Sometimes
 
 
Q