Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Add settings to store initial scene position #1686
Add settings to store initial scene position #1686
Changes from all commits
5eaae73
8a85918
d990c83
caed671
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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 think this function is not properly named, and doing too much.
Think of how the class is used:
The parent,
InstancesEditor
, must createPinchHandler
by passing it a viewPosition. This means that InstancesEditor knows, and actually ownsviewPosition
.Now it must also pass it something called "setViewPosition" used to... set a new ViewPosition? But why it would need to do that, because
InstancesEditor
is actually the owner ofViewPosition
.You probably did this because you observed that
onViewPositionChanged
is passing the ViewPosition as argument. This is right... butonViewPositionChanged
is a prop of InstancesEditor! This means that it needs to pass ViewPosition because the parent of InstancesEditor does not have access to ViewPosition - because it's owned by InstancesEditor.Here, it does not really make sense to pass to PinchHandler a function that takes a ViewPosition. Think like the parent (InstancesEditor): "why are you passing my a ViewPosition? I know ViewPosition, it's mine! It's me that passed it to you, why are you giving it back in your callback? I don't even need it, leave me in peace!" ;)
Or think like the child (PinchHandler): "why are you asking me for the ViewPosition? It's you that passed it to me!".
Instead, what you want is to get notified when the view is moved. And PinchHandler is moving the position, by calling scrollBy.
The solution:
onViewPositionChanged
to PinchHandler, which is called (as the name implies) "when the view position is changed". But without argument:_onViewPositionChanged: () => void
.Then it's the responsibility of the parent to react accordingly, providing more info if needed to it's parent. In other words, in InstancesEditor, you do:
Actually there is maybe a better solution. Why is InstancesEditor having to call manually onViewPositionChanged, and now why is PinchHandler having to call its own onViewPositionChanged every time we call
scrollBy
(andscrollToInstance
)?It's manual and error-prone, we could forget it in the future... instead why not give this responsibility to... ViewPosition.
and then you can call
onViewPositionChanged
insidescrollBy
andscrollToInstance
.And you remove all the other calls to
this.props.onViewPositionChanged
- they are now redundant because ViewPosition is doing the job of notifying after any change.Hope this make sense. :)