-
-
Notifications
You must be signed in to change notification settings - Fork 326
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: don't update based on parent offset on mount #920
base: master
Are you sure you want to change the base?
fix: don't update based on parent offset on mount #920
Conversation
* I'm not sure if this will work for all use cases, but for me it is workig much better, before this fix there was an issue when the component position was stored externally and the component is remounted with a defaultPos - it will jump by the parent offset pixels, which just isn't right. In my eyes it should just use the exact position passed to it from consumers as the starting position, if a consumer wants to use the absolute value they can pass that, otherwise the position they use `lastX` `lastY` for example is relative to the parent anyway. So whats the point of applying this offset to those values?
@dan-cooke Thanks! I'll check it. |
src/index.tsx
Outdated
@@ -636,6 +662,8 @@ export class Rnd extends React.PureComponent<Props, State> { | |||
const pos = this.state.resizing ? undefined : draggablePosition; | |||
const dragAxisOrUndefined = this.state.resizing ? "both" : dragAxis; | |||
|
|||
console.log(defaultValue, pos); |
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.
@dan-cooke Please remove this line.
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.
Removed
…ect-offset-calculation
@dan-cooke Thanks. I fixed #910, It was due to a different cause.so I don't understand your issue. Could you provide a reproduction in CodeSandbox if possible?" If the following actions are taken, will the problem be resolved? componentDidMount() {
if (this.props.position) return; // <- skip if position passed.
this.updateOffsetFromParent();
const { left, top } = this.offsetFromParent;
const { x, y } = this.getDraggablePosition();
this.draggable.setState({
x: x - left,
y: y - top,
});
// HACK: Apply position adjustment
this.forceUpdate();
} |
Let me check out the fix for 910 to see if it also fixes my issue, I’ll get
back to you as soon as I can
Thanks!
…On Sun, 21 Apr 2024 at 01:09, bokuweb ***@***.***> wrote:
@dan-cooke <https://github.com/dan-cooke> Thanks. I fixed #910
<#910>, It was due to a
different cause.so I don't understand your issue. Could you provide a
reproduction in CodeSandbox if possible?"
—
Reply to this email directly, view it on GitHub
<#920 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFOCQ5YBBKQK2URVAV6YJRLY6L7S3AVCNFSM6AAAAABFPPU6D2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANRXHAZDANJYGA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@bokuweb I landed here while implemented the following use case => I want to render the component within a Portal and pass as I landed on this PR after some search on the repo issues and PRs, and I can confirm adding However, it doesn't solve my use case. After some research and patching of the library (using |
lastX
lastY
for example is relative to the parent anyway. So whats the point of applying this offset to those values?Proposed solution
Tradeoffs
Testing Done