Force update when props update

master
Torjus 2018-07-17 11:12:08 +02:00
parent 9447883fd9
commit 3cb77188be
3 changed files with 6705 additions and 5 deletions

View File

@ -7,6 +7,8 @@ import { Appear } from './transitions';
import Peer from './Peer'; import Peer from './Peer';
import ResizeObserver from 'resize-observer-polyfill'; import ResizeObserver from 'resize-observer-polyfill';
const RATIO = 1.334;
class Peers extends React.Component class Peers extends React.Component
{ {
constructor(props) constructor(props)
@ -14,8 +16,7 @@ class Peers extends React.Component
super(props); super(props);
this.state = { this.state = {
peerWidth : 400, peerWidth : 400,
peerHeight : 300, peerHeight : 300
ratio : 1.334
}; };
} }
@ -31,11 +32,11 @@ class Peers extends React.Component
for (let rows = 1; rows < 100; rows = rows + 1) for (let rows = 1; rows < 100; rows = rows + 1)
{ {
x = width / Math.ceil(n / rows); x = width / Math.ceil(n / rows);
y = x / this.state.ratio; y = x / RATIO;
if (height < (y * rows)) if (height < (y * rows))
{ {
y = height / rows; y = height / rows;
x = this.state.ratio * y; x = RATIO * y;
break; break;
} }
space = height - (y * (rows)); space = height - (y * (rows));
@ -56,9 +57,15 @@ class Peers extends React.Component
componentDidMount() componentDidMount()
{ {
const observer = new ResizeObserver(this.updateDimensions); const observer = new ResizeObserver(this.updateDimensions);
observer.observe(this.refs.peers); observer.observe(this.refs.peers);
} }
componentDidUpdate()
{
this.updateDimensions();
}
render() render()
{ {
const { const {

6693
app/yarn.lock 100644

File diff suppressed because it is too large Load Diff