-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat(ui): locate in gallery image context menu #8434
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
feat(ui): locate in gallery image context menu #8434
Conversation
This is a simple and naive implementation, as To provide better user experience, state could be shared via Redux, but I'm not sure it is within the scope of this change. |
Three changes needed to make scrollIntoView and "Locate in Gallery" work reliably. 1. Use setTimeout to work around race condition with scrollIntoView in gallery. It was possible to call scrollIntoView before react-virtuoso was ready. I think react-virtuoso was initialized but hadn't rendered/measured its items yet, so when we scroll to e.g. index 742, the items have a zero height, so it doesn't actually scroll down. Then the items render. Setting a timeout here defers the scroll until after the next event loop cycle, by which time we expect react-virutoso to be ready. 2. Ensure the scollIntoView effect in gallery triggers any time the selection is touched by making its dependency the array of selected images, not just the last selected image name. The "locate in gallery" functionality works by selecting an image. There's a reactive effect in the gallery that runs when the last selected image changes and scrolls it into view. But if you already have an image selected, selecting it again will not change the image name bc it is a string primitive. The useEffect ignores the selection. So, if you clicked "locate in gallery" on an image that was already selected, it wouldn't be scrolled into view - even if you had already scrolled away from it. To work around this, the effect now uses the whole selection array as its dependency. Whenever the selection changes, we get a new array, which triggers the effect. 3. Gallery slice had some checks to avoid creating a new array of selected image names in state when the selected images didn't change. For example, if image "abc" was selected, and we selected "abc" again, instead of creating a new array with the same "abc" image, we bailed early. IIRC this optimization addressed a rerender issue long ago. This optimization needs to be removed in order for fix invoke-ai#2 above to work. We now _want_ a new array whenever selection is set - even if it didn't actually change.
… locate e.g. when on a tab that doesn't have a gallery, or the image is intermediate
6329c5f
to
d070b27
Compare
… finish before selecting image
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.
Thanks!
I made a number of changes to ensure the panels activate and the image gets scrolled-to reliably. See commits for more detail. Had to fight react a bit to make it work.
Summary
A new feature was implemented to locate any images in the gallery via the image context menu.
NavigationApi
was extended by two new functions,expandLeftPanel
andexpandRightPanel
, to expand the right panel on which the image gallery locatedcollapse
andexpand
, were extended inuseCollapsibleGridviewPanel
to check the status of the panel and only collapse/expand when it is required in order to avoid unnecessary resizing of the paneluseGalleryPanel
custom hook was created to encapsulate gallery related configuration ofuseCollapsibleGridviewPanel
GalleryPanel
was refactored to useuseGalleryPanel
custom hookImageMenuItemLocateInGalery
image context menu item was created to locate any images in the gallerySingleSelectionMenuItems
was extended by the newImageMenuItemLocateInGalery
menu itemsentToCanvas
andsentToUpscale
, was added toen.json
Related Issues / Discussions
Closes #7867
Checklist
What's New
copy (if doing a release after this PR)