Skip to content

Commit

Permalink
Two Performance Optimizations (#1449)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronmgdr authored and celo-ci-bot-user committed Nov 8, 2019
1 parent c7a1ada commit d8cfac1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
Binary file modified packages/web/src/home/merchant.jpg
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions packages/web/src/join/Rise.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const COLORS = [
interface State {
width: number
height: number
willAnimate: boolean
}

interface RisingCoinProps {
Expand All @@ -32,6 +33,7 @@ interface RisingCoinProps {
duration: number
delay: number
willFall?: boolean
willAnimate: boolean
}

interface StateVectors {
Expand Down Expand Up @@ -94,8 +96,15 @@ export default class Rise extends React.PureComponent<Props, State> {
state = {
width: 0,
height: 0,
willAnimate: false,
}

componentDidMount() {
// deviceMemory is only supported by chrome / android + opera
if (!window.navigator.deviceMemory || window.navigator.deviceMemory > 2) {
this.setState({ willAnimate: true })
}

this.windowResize({ window: Dimensions.get('window') })
Dimensions.addEventListener('change', this.windowResize)
}
Expand Down Expand Up @@ -134,6 +143,7 @@ export default class Rise extends React.PureComponent<Props, State> {
return (
<RisingCoin
key={i}
willAnimate={this.state.willAnimate}
willFall={this.props.willFall}
windowHeight={height}
windowWidth={width}
Expand Down Expand Up @@ -179,6 +189,14 @@ class RisingCoin extends React.PureComponent<RisingCoinProps, StateVectors> {
}

getStyleAndPosition = () => {
if (!this.props.willAnimate) {
return {
opacity: 0.7,
animationPlaystate: 'paused',
transform: this.getTransformStart({ x: this.state.x, y: this.state.y }),
}
}

const secondXPosition =
getPosition(this.state.radius, this.props.windowWidth * BIAS_START_DOWN_RATIO) -
HORIZONTAL_DISTANCE_MIN
Expand Down Expand Up @@ -212,6 +230,7 @@ class RisingCoin extends React.PureComponent<RisingCoinProps, StateVectors> {
],
}
}

keyframes = (firstCoord: Coord, secondCoord: Coord, thirdCoord: Coord) => {
return this.props.willFall
? this.fallFrames(firstCoord)
Expand Down
3 changes: 3 additions & 0 deletions packages/web/src/lib.dom.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface Navigator {
deviceMemory?: number
}

0 comments on commit d8cfac1

Please sign in to comment.