Correcting scrollbar after app state restoration


Steve Mills
 

I've noticed that the vertical scrollbar in the scroll view for my collection view is wrong after app restoration. This happens if the full collection (via CoreData) has, say 1000 items in it, then I do a filtered fetch to limit the collection to, say, 100 items. When showing all 1k items, the scrollbar thumb is small. When showing 100 items, the thumb is much larger.

I save and quit. The next time I launch, it restores the previously opened doc and restores the window state, including the collection view, scroll view, and scrollbar, including restoring the scrollbar state, which means the thumb is large like it was during save and quit, yet the collection view contains all 1k items, not just 100 items.

I can *not* figure out a good way to tell the collection view, scroll view, or what that it needs to recalc the size of the thumb. It's driving me bonkers. Any ideas?

All the restoration crap is just being handled by the OS - I'm not overriding any method to do the state restoration.

--
Steve Mills
Drummer, Mac geek


Glenn L. Austin
 

You need to save and restore the state of the data being shown as well.  If you use an IndexSet for your sub-collection, you could use, save and restore that.

-- 
Glenn L. Austin, Computer Wizard and Race Car Driver         <><
<http://www.austinsoft.com>

On May 13, 2020, at 9:00 PM, Steve Mills via groups.io <sjmills@...> wrote:

I've noticed that the vertical scrollbar in the scroll view for my collection view is wrong after app restoration. This happens if the full collection (via CoreData) has, say 1000 items in it, then I do a filtered fetch to limit the collection to, say, 100 items. When showing all 1k items, the scrollbar thumb is small. When showing 100 items, the thumb is much larger.

I save and quit. The next time I launch, it restores the previously opened doc and restores the window state, including the collection view, scroll view, and scrollbar, including restoring the scrollbar state, which means the thumb is large like it was during save and quit, yet the collection view contains all 1k items, not just 100 items.

I can *not* figure out a good way to tell the collection view, scroll view, or what that it needs to recalc the size of the thumb. It's driving me bonkers. Any ideas?

All the restoration crap is just being handled by the OS - I'm not overriding any method to do the state restoration.

--
Steve Mills
Drummer, Mac geek






Steve Mills
 

On May 14, 2020, at 10:13:15, Glenn L. Austin <glenn@austinsoft.com> wrote:

You need to save and restore the state of the data being shown as well. If you use an IndexSet for your sub-collection, you could use, save and restore that.
Hmm. I'd have to restore the search predicate. That should be doable, but it rubs me the wrong way that a document, when restored, only shows the last subset of items instead of showing everything. Photos doesn't restore the find term and show the find results, it shows everything. Neither does Mail. I'd much rather find a way to kick the scrollbar in the ass and tell it to be correct. It's extremely strange that document restoration remembers and restores a scrollbar's thumb size and scroll position. It should be set based on the scrollview's contents.

--
Steve Mills
Drummer, Mac geek


Allan Odgaard
 

You can send reflectScrolledClipView: to the NSScrollView instance after state restoration.
 
But it should basically never be necessary to call this method manually, so even if it fixes it, something may still be wrong / broken.
 
https://developer.apple.com/documentation/appkit/nsscrollview/1403534-reflectscrolledclipview


Allan Odgaard
 

On 14 May 2020, at 11:00, Steve Mills via groups.io wrote:

I can *not* figure out a good way to tell the collection view, scroll view, or what that it needs to recalc the size of the thumb. It's driving me bonkers. Any ideas?
You can send reflectScrolledClipView: to the NSScrollView instance after state restoration.

But it should basically never be necessary to call this method manually, so even if it fixes it, something may still be wrong / broken.

https://developer.apple.com/documentation/appkit/nsscrollview/1403534-reflectscrolledclipview


Steve Mills
 

On May 14, 2020, at 01:56:27, Allan Odgaard <groups-io@simplit.com> wrote:

You can send reflectScrolledClipView: to the NSScrollView instance after state restoration.

But it should basically never be necessary to call this method manually, so even if it fixes it, something may still be wrong / broken.

https://developer.apple.com/documentation/appkit/nsscrollview/1403534-reflectscrolledclipview
Thanks for pointing out that method. I tried it, but it didn't work. Not sure when the scrollbar is being restored to a stupid value. But, I've added predicate restoration, and that solves it. I also added a small icon that indicates when the collection view is showing some or all items, which lets the user see at a glance after re-open that they might not be seeing everything.

--
Steve Mills
Drummer, Mac geek