-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
211 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# See https://help.github.com/ignore-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
.env | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Basic Example | ||
|
||
```bash | ||
# in this directory | ||
npm install | ||
npm start | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "mobile-backend", | ||
"version": "0.1.0", | ||
"private": true, | ||
"devDependencies": { | ||
"react-scripts": "0.9.5" | ||
}, | ||
"dependencies": { | ||
"prop-types": "^15.5.9", | ||
"react": "^15.5.4", | ||
"react-dnd": "^2.4.0", | ||
"react-dnd-scrollzone": "^3.1.0", | ||
"react-dnd-touch-backend": "^0.3.10", | ||
"react-dom": "^15.5.4" | ||
}, | ||
"scripts": { | ||
"start": "react-scripts start", | ||
"build": "react-scripts build", | ||
"test": "react-scripts test --env=jsdom", | ||
"eject": "react-scripts eject" | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico"> | ||
<!-- | ||
Notice the use of %PUBLIC_URL% in the tag above. | ||
It will be replaced with the URL of the `public` folder during the build. | ||
Only files inside the `public` folder can be referenced from the HTML. | ||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will | ||
work correctly both with client-side routing and a non-root public URL. | ||
Learn how to configure a non-root public URL by running `npm run build`. | ||
--> | ||
<title>React App</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<!-- | ||
This HTML file is a template. | ||
If you open it directly in the browser, you will see an empty page. | ||
You can add webfonts, meta tags, or analytics to this file. | ||
The build step will place the bundled scripts into the <body> tag. | ||
To begin the development, run `npm start`. | ||
To create a production bundle, use `npm run build`. | ||
--> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.App { | ||
width: 500px; | ||
height: 500px; | ||
overflow: scroll; | ||
border: solid 2px black; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React, { Component } from 'react'; | ||
import TouchBackend from 'react-dnd-touch-backend'; | ||
import { DragDropContextProvider } from 'react-dnd'; | ||
import withScrolling from 'react-dnd-scrollzone'; | ||
import DragItem from './DragItem'; | ||
import DragPreview from './DragPreview'; | ||
import './App.css'; | ||
|
||
const ScrollingComponent = withScrolling('div'); | ||
|
||
const ITEMS = [1,2,3,4,5,6,7,8,9,10]; | ||
|
||
export default class App extends Component { | ||
render() { | ||
return ( | ||
<DragDropContextProvider backend={TouchBackend({ enableMouseEvents: true })}> | ||
<ScrollingComponent className="App"> | ||
{ITEMS.map(n => ( | ||
<DragItem key={n} label={`Item ${n}`} /> | ||
))} | ||
<DragPreview /> | ||
</ScrollingComponent> | ||
</DragDropContextProvider> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.DragItem { | ||
width: 100%; | ||
border: solid 1px black; | ||
padding: 30px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React, { PureComponent } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { DragSource } from 'react-dnd'; | ||
import './DragItem.css'; | ||
|
||
class DragItem extends PureComponent { | ||
|
||
static propTypes = { | ||
label: PropTypes.string.isRequired, | ||
}; | ||
|
||
render() { | ||
return this.props.dragSource( | ||
<div className="DragItem"> | ||
{this.props.label} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default DragSource( | ||
'foo', | ||
{ | ||
beginDrag() { | ||
return {} | ||
} | ||
}, | ||
(connect) => ({ | ||
dragSource: connect.dragSource(), | ||
}) | ||
)(DragItem); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.DragPreview { | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
height: 100vh; | ||
width: 100vw; | ||
pointer-events: none; | ||
z-index: 1000; | ||
} | ||
|
||
.DragPreview__item { | ||
width: 100px; | ||
height: 100px; | ||
background: white; | ||
border: solid 1px black; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React, { PureComponent } from 'react'; | ||
import { DragLayer } from 'react-dnd'; | ||
import './DragPreview.css'; | ||
|
||
class DragPreview extends PureComponent { | ||
|
||
render() { | ||
const { | ||
item, | ||
offset, | ||
} = this.props; | ||
|
||
return ( | ||
<div className="DragPreview"> | ||
{item && ( | ||
<div | ||
className="DragPreview__item" | ||
style={{ | ||
position: 'absolute', | ||
top: offset.y, | ||
left: offset.x, | ||
}} | ||
/> | ||
)} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default DragLayer( | ||
monitor => ({ | ||
item: monitor.getItem(), | ||
offset: monitor.getClientOffset(), | ||
}) | ||
)(DragPreview); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
body { | ||
margin: 0; | ||
padding: 0; | ||
font-family: sans-serif; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import App from './App'; | ||
import './index.css'; | ||
|
||
ReactDOM.render( | ||
<App />, | ||
document.getElementById('root') | ||
); |