CustomDragLayerã®ããã©ãŒãã³ã¹ãæªãçç±ã¯ãããŸããïŒ fpsãäœãããã«ããŸãã¯ãããããã©ãã°ããŠããä»»æã®ãªããžã§ã¯ããé ããŠãããã¹ã ãŒãºã«èŠããŸããã
ç§ããããçµéšããŸããã ããã§ã®åé¡ã¯ããã©ãã°ã¬ã€ã€ãŒã§å€æŽãããªãçŽç²ãªã³ã³ããŒãã³ããã¬ã³ããªã³ã°ããå Žåã§ãããªãã»ããã®å€æŽã«ãããããŠã¹ã1ååãããã³ã«å°ãªããšãåå¿èª¿æŽãããªã¬ãŒãããããšã§ãã ãã©ãã°ã¬ã€ã€ãŒãå€æŽãããªãã«ã¹ã¿ã ãã¬ãã¥ãŒèŠçŽ ã衚瀺ããã ãã®äžè¬çãªã±ãŒã¹ãããå Žåãããã¯éåžžã«éå¹ççã§ãã
ãããåé¿ããããã«ããªãã»ããã¬ã³ããªã³ã°ãè¡ãDragLayer.js
ãé«ããã©ãŒãã³ã¹ã§è€è£œããŸãããã€ãŸãããã¬ãã¥ãŒå
ãçŽæ¥ç§»åããã³ã³ããã®ã¹ã¿ã€ã«ãå€æŽããŸããã
// PerformantDragLayer.js
/* eslint-disable */
import React, { Component, PropTypes } from 'react';
import shallowEqual from 'react-dnd/lib/utils/shallowEqual';
import shallowEqualScalar from 'react-dnd/lib/utils/shallowEqualScalar';
import isPlainObject from 'lodash/isPlainObject';
import invariant from 'invariant';
import checkDecoratorArguments from 'react-dnd/lib/utils/checkDecoratorArguments';
import hoistStatics from 'hoist-non-react-statics';
function layerStyles(isDragging) {
return {
position: 'fixed',
pointerEvents: 'none',
zIndex: 1,
left: 0,
top: 0,
width: isDragging ? '100%' : 0,
height: isDragging ? '100%' : 0,
opacity: isDragging ? 1 : 0
};
}
export default function DragLayer(collect, options = {}) {
checkDecoratorArguments('DragLayer', 'collect[, options]', ...arguments);
invariant(
typeof collect === 'function',
'Expected "collect" provided as the first argument to DragLayer ' +
'to be a function that collects props to inject into the component. ',
'Instead, received %s. ' +
'Read more: http://gaearon.github.io/react-dnd/docs-drag-layer.html',
collect
);
invariant(
isPlainObject(options),
'Expected "options" provided as the second argument to DragLayer to be ' +
'a plain object when specified. ' +
'Instead, received %s. ' +
'Read more: http://gaearon.github.io/react-dnd/docs-drag-layer.html',
options
);
return function decorateLayer(DecoratedComponent) {
const { arePropsEqual = shallowEqualScalar } = options;
const displayName =
DecoratedComponent.displayName ||
DecoratedComponent.name ||
'Component';
class DragLayerContainer extends Component {
static DecoratedComponent = DecoratedComponent;
static displayName = `DragLayer(${displayName})`;
static contextTypes = {
dragDropManager: PropTypes.object.isRequired
}
getDecoratedComponentInstance() {
return this.refs.child;
}
shouldComponentUpdate(nextProps, nextState) {
return !arePropsEqual(nextProps, this.props) ||
!shallowEqual(nextState, this.state);
}
constructor(props, context) {
super(props);
this.handleOffsetChange = this.handleOffsetChange.bind(this);
this.handleStateChange = this.handleStateChange.bind(this);
this.manager = context.dragDropManager;
invariant(
typeof this.manager === 'object',
'Could not find the drag and drop manager in the context of %s. ' +
'Make sure to wrap the top-level component of your app with DragDropContext. ' +
'Read more: http://gaearon.github.io/react-dnd/docs-troubleshooting.html#could-not-find-the-drag-and-drop-manager-in-the-context',
displayName,
displayName
);
this.state = this.getCurrentState();
}
componentDidMount() {
this.isCurrentlyMounted = true;
const monitor = this.manager.getMonitor();
this.unsubscribeFromOffsetChange = monitor.subscribeToOffsetChange(
this.handleOffsetChange
);
this.unsubscribeFromStateChange = monitor.subscribeToStateChange(
this.handleStateChange
);
this.handleStateChange();
}
componentWillUnmount() {
this.isCurrentlyMounted = false;
this.unsubscribeFromOffsetChange();
this.unsubscribeFromStateChange();
}
handleOffsetChange() {
if (!this.isCurrentlyMounted) {
return;
}
const monitor = this.manager.getMonitor();
const offset = monitor.getSourceClientOffset();
const offsetDiv = this.refs.offset;
if (offset && offsetDiv) {
offsetDiv.style.transform = `translate(${offset.x}px, ${offset.y}px)`;
}
}
handleStateChange() {
if (!this.isCurrentlyMounted) {
return;
}
const nextState = this.getCurrentState();
if (!shallowEqual(nextState, this.state)) {
this.setState(nextState);
}
}
getCurrentState() {
const monitor = this.manager.getMonitor();
return {
collected: collect(monitor),
isDragging: monitor.isDragging()
};
}
render() {
return (
<div style={layerStyles(this.state.isDragging)}>
<div ref='offset'>
{this.state.isDragging && <DecoratedComponent {...this.props} {...this.state.collected} ref='child' />}
</div>
</div>
);
}
}
return hoistStatics(DragLayerContainer, DecoratedComponent);
};
}
ããã¯ã次ã®ããã«äœ¿çšã§ããŸãã
// MyCustomDragLayer.js
import PerformantDragLayer from './PerformantDragLayer'
import React, {PropTypes} from 'react'
class CustomDragLayerRaw extends React.Component {
static propTypes = {
item: PropTypes.any,
itemType: PropTypes.string
}
render () {
const {item, itemType} = this.props
return <div>{itemType}</div>
}
}
export default PerformantDragLayer((monitor) => ({
item: monitor.getItem(),
itemType: monitor.getItemType()
})(CustomDragLayerRaw)
ããã©ãŒãã³ã¹ã®åäžã¯éåžžã«æ³šç®ã«å€ããŸãã
ãã¡ãããããã©ã«ãã®DragLayer
ã¯ããã«æè»æ§ããããŸãã ç§ã®ããããã©ãŒãã³ã¹ã®é«ãå®è£
ã¯ãç¹æ®ãªã±ãŒã¹ãåŠçãããããããé«éã§ãã ãããããã®ç¹æ®ãªã±ãŒã¹ã¯éåžžã«äžè¬çã ãšæããŸãã
@gaearonãã®ãããªç¹æ®ãªå®è£ ã§ãããreact-dndã®ä»£æ¿ãšããŠçµ±åããããšã§ãããã©ãŒãã³ã¹ãå€§å¹ ã«åäžããŸããïŒ
@choffmeisterããã«ã¡ã¯ã æçš¿ããããšãããããŸãã ç§ã¯åæ¥ã«ãããç°¡åã«èŠãŸãããããã®æã ããããæ·±ãèŠãŸããã ããªããæçš¿ããã³ãŒãã¯ãå®è£ å ã§éåžžã«ç¹æ®åãããŠããããã§ãããããã«å¿ èŠãªéèŠãªåŽé¢ãææããŠããã ããŸããïŒ ãããŠããã®CustomDragLayerRawãã©ã®ããã«äœ¿çšãããããéåžžã«æçã§ãã
ããªããæã£ãŠãããããã®ãã©ã°ã€ã³ãã©ã€ãã©ãªããã®ä»ã®ã³ãŒãã®ãã¹ãŠããœãªã¥ãŒã·ã§ã³ã®äžéšã§ãããã©ããã¯ããããŸããã
ããããšã
ç§ã¯ãããããšå®éšããŠããããæ©èœãããããšãã§ããŸããã ããã©ãã°ãŽãŒã¹ãã·ã³ã°ãã«å¿ èŠãªã³ã³ãã³ãã¯ãããªãã»ãããdivã«ããå¿ èŠãããããã§ãã ãããè¡ãããã®æé©ãªæ¹æ³ã¯ããããŸããããç§ã®ãã¹ãã§ã¯ããã©ãã°ããã³ã³ãã³ãã«åæ§ã®divãé 眮ããŸããã ãã©ãã°ã¬ã€ã€ãŒã¢ã€ãã ããã©ãã°ã¢ã€ãã ãšåãã«ããããšã¯ãŸã ã§ããŠããŸããããããŒã¿ãæž¡ããŠãã©ãã°ã¬ã€ã€ãŒã¢ã€ãã ã®ç¶æ ãå€æŽããã®ã¯ããã»ã©é£ãããããŸããã
ããã©ãŒãã³ã¹ã¯éåžžã«è¯å¥œã§ãããã³ã³ããã®å€åŽã«ãã©ãã°ããå Žåã«ã®ã¿æ©èœããŸãã ã¢ã€ãã ã®åšããåã§ãã©ãã°ãããšãããã©ãŒãã³ã¹ãåã®å Žåãšåãããã«å®ç§ã«ãªããŸãïŒã€ãŸãã4ã€ã®ã¢ã€ãã ã®ãªã¹ããããã4çªç®ã®ã¢ã€ãã ã®é åã«ããŠã¹ããã©ãã°ããŠä¿æããŸãïŒã ãã ããããŠã¹ã§4ã€ã®èŠçŽ ãã¹ãŠããã©ãã°ããŠåãæããšã以åãšåãããã«é ããŸãããfpsããããã«åäžããŸãïŒããã§ããŸã é ããŠããŸãïŒã ãããããã®å®è£ ã¯è¯ãã¹ã¿ãŒãã§ãã å°ãªããšããããã³ã³ããããå¥ã®ã³ã³ããã«ãã©ãã°ããå Žåã®æãäžè¬çãªã±ãŒã¹ã§ã¯ãããã«ããUXã確å®ã«è¯å¥œã«ä¿ãããŸãã
ã©ã°ãšã¯ã©ãããæå³ã§ããïŒ
ç§ã¯äž¡æ¹ãèšãã ãã
ããã«äœ¿çšããŠã¿ããšããã®ãœãªã¥ãŒã·ã§ã³ã§ã¯ã©ã°ãå®å šã«è§£æ¶ãããããã§ã¯ãªãããšãããããŸããã éããªæ©èœãåããã«ãŒãdivããããŸãã ããªãã®ãœãªã¥ãŒã·ã§ã³ã¯ãæåã¯ããã¥ã¡ã³ãã®äŸãšæ¯èŒããŠå€§å¹ ãªfpsããŒã¹ããæäŸããŸããããdivãããè€éã«ãããšãããããªãã£ãããã«é ãå§ããŸãã
ãã®ã»ãã³ãã£ãã¯UIããããåŒãèµ·ãããŠããã®ããdndã«åå¿ããã®ãããããŸããã ãã©ãã°ã¬ã€ã€ãŒã®ããã©ãŒãã³ã¹ãåäžãããããã®ããæé©ãªæ¹æ³ãä»ã«ãããã©ãããç§ã¯æ¬åœã«ç¥ãããã§ãã
ãŸãã誰ããããã圌ãã«ãšã£ãŠãé ããŠãããã©ãããè©ŠããŠã¿ããå Žåã¯ãç§ã¯ã»ãã³ãã£ãã¯UIã«ãŒãã䜿çšãããã®äžã«å€ãã®èŠçŽ ãå«ãŸããŠããŸããã ç§ã®ãã¬ãŒã¹ãã«ããŒã«ãŒãã«ã¯ã2ã€ã®ã¿ã€ãã«ã5ã€ã®ã»ãã³ãã£ãã¯ãã©ãã«ãã3ã€ã®ã»ãã³ãã£ãã¯ãã¢ã€ã³ã³ããããã³ã¢ãã¿ãŒç»åããããŸããã
http://react-trello-board.web-pal.com/ã§ãã®å¥ã®äŸã䜿çšããŠããã«ãã¹ãããåŸïŒãã®å®è£ ã¯choffmeisterã以åã«æçš¿ãããã®ãšéåžžã«äŒŒãŠããŸãïŒãè€éãªdivããã©ãã°ããããšãããšãŸã ã©ã°ãçºçããŸãã ã³ãŒããããã«å®éšããå¿ èŠããªãã®ã§ããããç§ãå°éããçµè«ã§ããããšãå¬ããæããŸãã åé¡ã¯ç§ã®divã«ãããç°¡åã«ä¿®æ£ã§ããŸãã
ããã¥ã¡ã³ãã®äŸãšéåžžã«ãã䌌ãã³ãŒãã䜿çšããŠããããããªãã²ã©ãçµéšããŠããŸãã ããã¯ããã¹ãŠã®å°ããªããŠã¹ãåããå€æèšç®ã§ãªããã°ãªããŸãããïŒ
ä»ã®èª°ããããã«å¯Ÿãã解決çãèŠã€ããŸãããïŒ
PureComponentsã䜿çšããŠããããã©ãŒãã³ã¹ã®åé¡ãçºçããŸããã Chrome React Devãã©ã°ã€ã³ã®ãæŽæ°ã®ãã€ã©ã€ããæ©èœã䜿çšããŠèšºæãããšã currentOffset
ãããããå€æŽããããšãã«ãã¹ãŠã®ã³ã³ããŒãã³ããæŽæ°ãããŠããããã§ãã 軜æžããããã«ããã©ãã°ãããŠããã¢ã€ãã ã远跡ããããã«ã¢ããªã®ãããã¬ãã«ã«ãã§ã«DragLayerããã£ããšããŠãããã®å°éå
·ãæž¡ãDragLayerã«ã¯ãã©ãã°ãã¬ãã¥ãŒèªäœã®ã¿ãå«ãŸããããã«ããŸããã
@choffmeisterã®ãœãªã¥ãŒã·ã§ã³ãæ¡çšããããšã¯ããŠããŸããããåé¡ã解決ããããã§ãã ãã©ãã°ãã¬ãã¥ãŒãå®è£ ãã人ã«ãšã£ãŠããã¯äžè¬çãªåé¡ã§ãããšããæ³åã§ããªãã®ã§ãã³ã¢ã©ã€ãã©ãªã§ã¯ãããããã®ãããªããšãæ€èšããå¿ èŠããããšæããŸãã
ã¢ããªã®ãããã¬ãã«ã«ãã§ã«DragLayerããã£ããšããŠãããã®å°éå ·ãæž¡ãDragLayerã«ã¯ãã©ãã°ãã¬ãã¥ãŒèªäœã ããå«ãŸããŠããããšã確èªããŸãã
ã€ããŠãããããããªãïŒ ç§ã®ã¢ããªã«ã¯ã«ã¹ã¿ã ãã©ãã°ã¬ã€ã€ãŒã1ã€ãããªãããšç§ã¯ä¿¡ããŠããŸãïŒ
ããã¯ç§ã®ãŠãŒã¹ã±ãŒã¹ã«åºæã®åé¡ã§ãããã©ãã°ãããŠããã¢ã€ãã ã远跡ããããã«ãã«ã¹ã¿ã ãã©ãã°ãã¬ãã¥ãŒãå¿ èŠã«ãªãåã«ãã©ãã°ã¬ã€ã€ãŒããã§ã«äœ¿çšãããŠããŸããã è¿œå ãããšããæåã¯åããã©ãã°ã¬ã€ã€ãŒã䜿çšããŠã«ã¹ã¿ã ãã©ãã°ãã¬ãã¥ãŒãå®è¡ããã®ãçã«ããªã£ãŠãããšæã£ãŠããŸããããããã¯ã¢ããªã±ãŒã·ã§ã³ã®ãããã¬ãã«ã§ãã£ããããããããªåãããšã«ãã®ãããããå€æŽãããšãå€ãã®ããšãçºçããŸãããè¿œå ã®ã³ã³ããŒãã³ãã®æŽæ°ã
ã奚ããããããšãã
ãã©ãã°ã¬ã€ã€ãŒãåäžã®ãã ã³ã³ããŒãã³ãã«åçŽåããã®ã§ãã©ã°ã®åå ãšãªã£ãŠããã®ã¯äžå®ã®x/yèšç®ã§ããããšãããããŸãã
@choffmeisterãäžèšã§è¡ã£ãŠããããšããŸã å®å šã«ã¯ãã©ããŒããŠããŸãããã詳ãã調ã¹ãå¿ èŠãããããã§ãã
@gaearonããã¯libã«ãšã£ãŠããªããŸãšããªåé¡ã®ããã§ãããé©åãªä¿®æ£ãäœã§ãããã«ã€ããŠã®ææ¡ã¯ãããŸããïŒ
react-dnd-html5-backendã®ããã©ãŒãã³ã¹ã¯ã«ã¹ã¿ã DragLayerã§ã²ã©ãã®ã«å¯Ÿããreact-dnd-touch-backendã®ããã©ãŒãã³ã¹ã¯OKã®ããã§ãã
ã¡ãã£ãšæããã§ãããããã¯åœ¹ç«ã¡ãŸãïŒ
let updates = 0;
@DragLayer(monitor => {
if (updates++ % 2 === 0) {
return {
currentOffset: monitor.getSourceClientOffset()
}
}
else {
return {}
}
})
ãã1ã€ã®åé¿çã¯ã react-throttle-render
ããã±ãŒãžã䜿çšããŠãDragLayerã®ã¬ã³ããªã³ã°ã¡ãœããã調æŽããããšã§ãã
ããããšã@aks427ç§ã¯ãããè©ŠããŠããããããã«æ¹åããããã©ããã確èªããŸãïŒäžèšã®ãããªã«ã¹ã¿ã ãã©ãã°ã¬ã€ã€ãŒã䜿çšããŠããã»ãšãã©ã®å Žåã«å€§ãã«åœ¹ç«ã¡ãŸãããããã¹ãŠã§ã¯ãããŸããïŒ
@dobesvãreact-dnd-touch-backendã«å€æŽãããšãåé¡ã解決ããŸããã ç§ãreact-throttle-renderãè©ŠããŸããããããã§ãè¯ããªãããã§ãã
ãããç§ã¯ã¿ããããã¯ãšã³ããæ©èœããããšãç¥ã£ãŠããŸãããããã¯ç§ã䜿çšããããã©ãã°ã¢ã³ããããããã¡ã€ã«ã®ã¢ããããŒãããµããŒãããŠããŸããã
@dobesvãã¡ã€ã«ã®ãã©ãã°ã¢ã³ãããããã«ã¯https://react-dropzone.js.org/ã䜿çšããŸã:)å€åããã¯ããªãã«ãè¯ãã§ãããã
@dobesvã¯ç§ã®ã³ã¡ã³ããç¡èŠããŸãã react-dropzoneã¯ãããããã¡ã€ã«ã®ã¿ããµããŒãããŸãã
ãã ããããäžè¬çãªã·ããªãªã§ã¯ããã¡ã€ã«ãã¢ããããŒãããå¿ èŠãããå Žåã¯ããã¡ã€ã«ããã©ãŠã¶ãŒã®å€ã«çœ®ãå¿ èŠããããŸãã ãããããã¡ã€ã«ã ããå¿ èŠã§ãã
ç°¡åãªããšã§ã¯ãããŸããããããã©ãŒãã³ã¹ã®é«ããã©ãã°ã¬ã€ã€ãŒã®ä¿®æ£ã䜿çšããŠã
ã¬ã³ããªã³ã°ã®æ°ãå¶éããããã«ç§ã®ã³ãŒããèŠãã®ã«å€ãã®æéãããããŸãã
ã¢ããªã«ãã£ãŠåŒã³åºããïŒå€ãã®åãæ¿ãã³ã³ããŒãã³ã-> PureComponentïŒã
çµå±ãreact-throttle-renderã䜿çšããå¿
èŠãããããŸããã§ããã
PureComponentã®äœ¿çšãæ€èšãã
ãã®ã¹ã¬ããã§ç°¡åãªä¿®æ£ãæ¢ã代ããã«ãã³ãŒããæ倧åããŸãã
ã¬ã³ããªã³ã°ãé
ãã§ãïŒ ããã©ãŒãã³ã¹ã¢ãã«ãæ¹åããããã£ãšæçš¿ããŸã
ã§ããã¹ãŠïŒ
>>
@framerate PureComponentsã䜿çšããŠããå Žåã§ãã調æŽã¢ã«ãŽãªãºã ã¯ããŠã¹ãåãããã³ã«å®è¡ããã®ã«ã³ã¹ããããããããåé¡ã«ãªããŸãã Chrome DevToolsãšCPUã¹ããããªã³ã°ã䜿çšããŠã¢ããªã4Xã«ãããã¡ã€ãªã³ã°ããã ãã§ããããã¯ãããããšã³ãã¢ãã€ã«ããã€ã¹ã®çŸå®çãªé床äœäžã§ãã
åŸäžããã©ãã°ããã©ãŒãã³ã¹ã«èŠåŽããŠããŠã @choffmeisterãœãªã¥ãŒã·ã§ã³ã®ããã«å€ãã®ã³ãŒãããã«ããããªã人ã®ããã«ïŒ
let subscribedToOffsetChange = false;
let dragPreviewRef = null;
const onOffsetChange = monitor => () => {
if (!dragPreviewRef) return;
const offset = monitor.getSourceClientOffset();
if (!offset) return;
const transform = `translate(${offset.x}px, ${offset.y}px)`;
dragPreviewRef.style["transform"] = transform;
dragPreviewRef.style["-webkit-transform"] = transform;
};
export default DragLayer(monitor => {
if (!subscribedToOffsetChange) {
monitor.subscribeToOffsetChange(onOffsetChange(monitor));
subscribedToOffsetChange = true;
}
return {
itemBeingDragged: monitor.getItem(),
componentType: monitor.getItemType(),
beingDragged: monitor.isDragging()
};
})(
class CustomDragLayer extends React.PureComponent {
componentDidUpdate(prevProps) {
dragPreviewRef = this.rootNode;
}
render() {
if (!this.props.beingDragged) return null;
return (
<div
role="presentation"
ref={el => (this.rootNode = el)}
style={{
position: "fixed",
pointerEvents: "none",
top: 0,
left: 0
}}
>
{renderComponent(
this.props.componentType,
this.props.itemBeingDragged
)}
</div>
);
}
}
);
@stellarhoofçŽ æŽãããçããããããšãïŒ æ®å¿µãªããããã®ãœãªã¥ãŒã·ã§ã³ã¯IE11ã§ã¯æ©èœããŸããã subscribeToOffsetChange
ã¯ãæž¡ããã³ãŒã«ããã¯ãåŒã³åºããªãããã§ãã 幞ãã subscribeToOffsetChange
ã䜿çšããã«ãã³ã¬ã¯ã¿ãŒå
ã§æ¬¡ã®ããã«ç¿»èš³ãèšå®ããã ãã§ä¿®æ£ã§ããŸããã
let dragLayerRef: HTMLElement = null;
const layerStyles: React.CSSProperties = {
position: 'fixed',
pointerEvents: 'none',
zIndex: 100,
left: 0,
top: 0,
width: '100%',
height: '100%',
};
const dragLayerCollector = (monitor: DragLayerMonitor) => {
if (dragLayerRef) {
const offset = monitor.getSourceClientOffset() || monitor.getInitialClientOffset();
if (offset) {
dragLayerRef.style["transform"] = `translate(${offset.x}px, ${offset.y}px)`;
} else {
dragLayerRef.style["display"] = `none`;
}
}
return {
item: monitor.getItem(),
isDragging: monitor.isDragging(),
};
};
export default DragLayer(dragLayerCollector)(
(props): JSX.Element => {
if (!props.isDragging) {
return null;
}
return (
<div style={layerStyles}>
<div ref={ (ref) => dragLayerRef = ref }>test</div>
</div>
);
}
);
@stellarhoof renderComponent
ãå®çŸ©ãããŠããªãããšã«æ°ã¥ããŸããã ããã¯å€§ããªãã¡ã€ã«ã®äžéšã§ãããïŒ ïŒReactãã€ã³ããŒããããŸããïŒ
@choffmeister dndã®æ°ããããŒãžã§ã³çšã«æŽæ°ããŸãããïŒ ã³ã³ããã¹ãã®å€æŽã«ãã£ãŠå®è£ ãå£ããããã«èŠããã®ã§ãè©ŠããŠã¿ãŠã @stellarhoofãè¡ã£ãŠãããã®ãšæ¯èŒããããšæããŸããã
@stellarhoofçŽ æŽãããçããããããšãïŒ æ®å¿µãªããããã®ãœãªã¥ãŒã·ã§ã³ã¯IE11ã§ã¯æ©èœããŸããã
subscribeToOffsetChange
ã¯ãæž¡ããã³ãŒã«ããã¯ãåŒã³åºããªãããã§ãã 幞ããsubscribeToOffsetChange
ã䜿çšããã«ãã³ã¬ã¯ã¿ãŒå ã§æ¬¡ã®ããã«ç¿»èš³ãèšå®ããã ãã§ä¿®æ£ã§ããŸãããlet dragLayerRef: HTMLElement = null; const layerStyles: React.CSSProperties = { position: 'fixed', pointerEvents: 'none', zIndex: 100, left: 0, top: 0, width: '100%', height: '100%', }; const dragLayerCollector = (monitor: DragLayerMonitor) => { if (dragLayerRef) { const offset = monitor.getSourceClientOffset() || monitor.getInitialClientOffset(); if (offset) { dragLayerRef.style["transform"] = `translate(${offset.x}px, ${offset.y}px)`; } else { dragLayerRef.style["display"] = `none`; } } return { item: monitor.getItem(), isDragging: monitor.isDragging(), }; }; export default DragLayer(dragLayerCollector)( (props): JSX.Element => { if (!props.isDragging) { return null; } return ( <div style={layerStyles}> <div ref={ (ref) => dragLayerRef = ref }>test</div> </div> ); } );
ããã¯ç§ã®ããã«åããïŒ
ç§ã¯ãã®ããŒãžã§ã³ã䜿çšããŠããŸãïŒ9.4.0
ä»ã®ãœãªã¥ãŒã·ã§ã³ã¯ãå€ãããŒãžã§ã³ã§ã®ã¿æ©èœããããã§ãã
ããã¿ããªã
ç¶è¡ããåã«ãcssã¢ãã¡ãŒã·ã§ã³ã³ã³ããŒãã³ãããã©ãã°å¯èœã«ããããšããããå°ãªããšããã©ã³ãžã·ã§ã³ããããã£ãåé€ãããããªãã§ãã ããã
é·ç§»ããããã£onStartãåé€ããonEndã«è¿œå ãçŽããåŸããã¹ãŠãæ£ããæ©èœããŸãã
ããã¯ïŒuseDragLayerããã¯ïŒã䜿çšããŠããã«å°éãã人ã®ããã«ïŒç§ã¯ããã§åé¿çã®ææ¡ãšãšãã«ãããã¯ã®å®è£ ã«ã€ããŠå ·äœçã«ãã±ãããéããŸããïŒ https ://github.com/react-dnd/react-dnd/issues/2414
æãåèã«ãªãã³ã¡ã³ã
react-dnd-html5-backendã®ããã©ãŒãã³ã¹ã¯ã«ã¹ã¿ã DragLayerã§ã²ã©ãã®ã«å¯Ÿããreact-dnd-touch-backendã®ããã©ãŒãã³ã¹ã¯OKã®ããã§ãã