-
Notifications
You must be signed in to change notification settings - Fork 314
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
fix(StackViewport): weird interaction between scroll() and setImageIdIndex() #1208
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for cornerstone-3d-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
@sedghi Could you review this? Sorry that I can't provide more for the testing part. If something is unclear I'm happy to provide further explanation. |
I don't think that is the correct behavior. The scroll should not depend on the state (where it was jumped) and should only scroll in the requested direction. It seems like you are injecting your app-level logic into the library, which is usually not a good idea. I recommend implementing that logic in your app:
Does this make sense? |
Thank you for you response. What you describe in your implementation recommendation makes sense and is basically the behavior I expected from this module. However when I adjust Please let me know if I misunderstood anything in your recommendation. In my opinion my solution is not very pretty, but it is the best I could come up with given that the |
@jobunk can you please provide a minimum example to show case the issue? |
Context
I had encountered an issue in the StackViewport class, where the user would scroll, afterwards use the public method "setImageIdIndex()" to jump to a specific image and then continue scrolling. The expected behavior in this situation would be to that the viewport continues scrolling from the image that the user just jumped to. However the actual behavior was that the scrolling would pick up back where the user had last scrolled and completely ignore the "setImageIdIndex()" that had happened.
Changes & Results
This happens because "this.targetImageIdIndex", which is used during scrolling, was never updated. My workaround was to just use the "setStack()" method instead, since it actually updates "this.targetImageIdIndex" correctly. However I believe that that is not the intended use of the method, so here is my suggested fix. It adds an optional boolean that tells the viewport to also move the scrolling position to the given index. This boolean is optional, because the method is also called from within scroll(), in which case we don't want to adjust the targetImageIdIndex.
Testing
I only tested it locally in the context of my project. The idea is to scroll to an image, then jump to another image far away using "setImageIdIndex(, true)" and then continue scrolling. If the scrolling picks up from the position that you jumped to, the error has been fixed. I also didn't see any weird behavior with other functions, which makes sense, since it's an optional input parameter that was added.
Checklist
PR
semantic-release format and guidelines.
Code
My code has been well-documented (function documentation, inline comments,
etc.)
I have run the
yarn build:update-api
to update the API documentation, and havecommitted the changes to this PR. (Read more here https://www.cornerstonejs.org/docs/contribute/update-api)
Public Documentation Updates
additions or removals.
Sorry I'm not sure if this is needed here.
Tested Environment