Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two Performance Optimizations #1449

Merged
merged 5 commits into from
Nov 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}