Skip to content

Commit 81fb799

Browse files
committed
added flipmove animation
1 parent 3a541a8 commit 81fb799

6 files changed

Lines changed: 38 additions & 8 deletions

File tree

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,17 @@ I have implemented a total of `14 algorithms` so far. And will try to add more l
4141

4242
I am not sure if anyone would like to contribute to this project or not. But any kind of contributions are welcomes. Also if you like this please star this repo. It keeps me motivated.
4343

44-
Note to self:
44+
### Special Features addition timeline
45+
46+
- Commit 16: Added Flip Move animation to inplace sorting components
47+
48+
49+
### Note to self:
50+
51+
To deploy recent changes to page
52+
53+
```
54+
npm run build
55+
npm run deploy
56+
```
57+

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"fontsource-roboto": "^3.0.3",
1414
"react": "^17.0.1",
1515
"react-dom": "^17.0.1",
16+
"react-flip-move": "^3.0.4",
1617
"react-github-btn": "^1.2.0",
1718
"react-router-dom": "^5.2.0",
1819
"react-scripts": "4.0.0",

src/sortComponents/rect.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ class Rect extends Component {
88
className='rect'
99
style={{height:this.props.rect.width,
1010
background:this.checkColor(),
11-
margin:this.props.marg
11+
margin:this.props.marg,
12+
// float:'left',
13+
'vertical-align': 'middle'
1214
}}
1315
>
1416

src/sortComponents/rects.jsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, {Component} from 'react';
22
import Rect from "./rect";
3+
import FlipMove from 'react-flip-move';
34

45
class Rects extends Component {
56
render() {
@@ -8,16 +9,22 @@ class Rects extends Component {
89
margin=1;
910
}
1011
return (
11-
<div className="d-flex justify-content-center align-items-end">
12+
<div>
13+
<FlipMove
14+
className="d-flex justify-content-center align-items-end"
15+
duration={this.props.speed}
16+
// easing="cubic-bezier(.12,.36,.14,1.2)"
17+
>
1218
{this.props.rects.map( (rect,rectidx)=>{
1319
return (
1420
<Rect
1521
marg={margin}
16-
key={rectidx}
22+
key={rect.kk}
1723
rect={rect}
1824
/>
1925
);
2026
} )}
27+
</FlipMove>
2128
</div>
2229
);
2330
}

src/sortComponents/sort.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class Sort extends Component {
4545
<div className=' justify-content-center'>
4646

4747
<Rects
48+
speed={this.state.speed*10}
4849
rects={this.state.rects}
4950
/>
5051
{ this.state.doubles && <hr style={{width:"90%"}}/>}
@@ -223,20 +224,21 @@ class Sort extends Component {
223224

224225
}
225226
function sleep(ms) {
226-
return new Promise(resolve => setTimeout(resolve, ms));
227+
return new Promise(resolve => setTimeout(resolve, ms*10));
227228
}
228229
const getInitialRects = (tot) => {
229230
const rects = [];
230231
for(let i = 0;i<tot;i++){
231-
rects.push(getRect());
232+
rects.push(getRect(i));
232233
}
233234
return rects;
234235
}
235-
const getRect = () => {
236+
const getRect = (kk) => {
236237
return {
237238
width: Math.floor(Math.random() * 200)+50,
238239
isSorted:false,
239-
isSorting:false
240+
isSorting:false,
241+
kk:kk
240242
}
241243
}
242244
export default Sort;

0 commit comments

Comments
 (0)