Skip to content
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

sourceOffset wanky #799

Closed
didair opened this issue Jun 15, 2017 · 2 comments
Closed

sourceOffset wanky #799

didair opened this issue Jun 15, 2017 · 2 comments
Labels

Comments

@didair
Copy link

didair commented Jun 15, 2017

Hi

I've been having problems with the monitor.getClientOffset() over in the custom dragPreview function. It seems to be returning values that isn't at all where it should be. Anyone else experiencing this issue? Using the react-dnd-touch-backend package. If anyone has any idea of how to solve this that would be amazing.

This is my item component (render method)

<div onMouseDown={this.onMouseDown} key={randomKey} style={{ 'opacity': opacity }} className="list-item">
<DragPreview {...this.props}>{ firstname } { lastname }</DragPreview>
	{ firstname } { lastname }
</div>

And the dragPreview.js component is really basic, i think the whole thing is from the react-dnd tutorials. Attaching it below

import React, { Component, PropTypes } from 'react';
import DragLayer from 'react-dnd/lib/DragLayer';

function collect (monitor) {
    return {
        sourceOffset: monitor.getClientOffset(),
		initialOffset: monitor.getInitialClientOffset()
    };
}

class DragPreview extends Component {
    getLayerStyles() {
        const { sourceOffset, initialOffset } = this.props;
		
        return {
            transform: sourceOffset ? `translate( ${sourceOffset.x}px, ${sourceOffset.y}px )` : ''
        };
    }

    render () {
        const { isDragging, children } = this.props;
        if (!isDragging) { return null; };

        return (
            <div className="source-preview" style={this.getLayerStyles()}>
                { children }
            </div>
        );
    }
}

DragPreview.propTypes = {
    isDragging: PropTypes.bool,
    sourceOffset: PropTypes.shape({
        x: PropTypes.number.isRequired,
        y: PropTypes.number.isRequired
    })
};

export default DragLayer(collect)(DragPreview);
@didair
Copy link
Author

didair commented Jun 15, 2017

Seems related to #793

darthtrevino added a commit that referenced this issue Jul 25, 2017
… after dragstart instead of depending on dragend to be trigger (#799)"

This reverts commit 8a3eb74.
darthtrevino added a commit that referenced this issue Jul 25, 2017
… after dragstart instead of depending on dragend to be trigger (#799)" (#835)

This reverts commit 8a3eb74.
@stale
Copy link

stale bot commented Jul 6, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jul 6, 2019
@didair didair closed this as completed Jul 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant