Skip to content
This repository was archived by the owner on Jun 5, 2019. It is now read-only.

Adds an entrance animation component for nicer startup. #41

Merged
merged 1 commit into from
Aug 6, 2017
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
4 changes: 4 additions & 0 deletions src/main/main-window/main-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export function createMainWindow(appPath: string) {
autoHideMenuBar: true,
backgroundColor: '#fff',
title: app.getName(),
webPreferences: {
backgroundThrottling: false,
textAreasAreResizable: false,
},
})

// maximize if we did before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
styles,
cssProps,
commandOrControlKey,
EnterAnimation,
} from '../../../platform'
import { css, compose } from 'glamor'

Expand All @@ -22,8 +23,10 @@ const KEY_1 = `${commandOrControlKey}+1`
const KEY_2 = `${commandOrControlKey}+2`
const KEY_3 = `${commandOrControlKey}+3`

const ROOT = compose(
styles.windowDrag,
// an extra layer just for the drag style due to electron bug
const ROOT = styles.windowDrag

const BAR = compose(
styles.row,
cssProps({
paddingLeft: spacing.medium,
Expand Down Expand Up @@ -57,11 +60,16 @@ export class SampleTabs extends React.PureComponent<SampleTabsProps, {}> {

render() {
const { tab } = this.props

return (
<div {...css(ROOT)}>
<Tab onClick={this.changeTab1} active={tab === 'one'} text='doggo' />
<Tab onClick={this.changeTab2} active={tab === 'two'} text='paragraphs' />
<Tab onClick={this.changeTab3} active={tab === 'three'} text='empty' />
<EnterAnimation animation='slide' delay={100} y={-60}>
<div {...BAR}>
<Tab onClick={this.changeTab1} active={tab === 'one'} text='doggo' />
<Tab onClick={this.changeTab2} active={tab === 'two'} text='paragraphs' />
<Tab onClick={this.changeTab3} active={tab === 'three'} text='empty' />
</div>
</EnterAnimation>
</div>
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import * as React from 'react'
import { cssProps } from '../..'
import { css } from 'glamor'

interface EnterAnimationState {
mounted?: boolean
}

export interface EnterAnimationProps {
children?: React.ReactNode
/** the type of animation */
animation: 'grow' | 'slide'
/** how long to wait in milliseconds before starting */
delay?: number
/** how fast to complete the animation in milliseconds */
speed?: number
/** how far vertically to slide */
y?: number
}

const DEFAULT_SPEED = 250
const DEFAULT_DELAY = 0

const SCALE_FROM = `scale(0.01, 0.01)`

const FINISH = cssProps({ transform: `translate(0, 0) scale(1, 1)` })

export class EnterAnimation extends React.PureComponent<EnterAnimationProps, EnterAnimationState> {
state: EnterAnimationState = {}

componentDidMount() {
setTimeout(() => this.setState({ mounted: true }), 1)
}

render() {
// values
const { mounted } = this.state
const { speed = DEFAULT_SPEED, delay = DEFAULT_DELAY, animation, y = 0 } = this.props

// css properties
let transform: string

switch (animation) {
case 'slide':
transform = `translate(0, ${y}px)`
break

// grow
default:
transform = SCALE_FROM
break
}

const transition = `transform ${speed || DEFAULT_SPEED}ms ${delay || DEFAULT_DELAY}ms`

// style props
const starting = css(cssProps({ transform, transition }))
const finishing = css(mounted && FINISH)

return (
<div {...starting} {...finishing}>
{this.props.children}
</div>
)
}
}
1 change: 1 addition & 0 deletions src/renderer/platform/components/enter-animation/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './enter-animation'
1 change: 1 addition & 0 deletions src/renderer/platform/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './text'
export * from './scrollable-content'
export * from './centered-content'
export * from './tab'
export * from './enter-animation'
10 changes: 6 additions & 4 deletions src/renderer/platform/components/tab/tab.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react'
import { CSSProperties } from 'react'
import { colors, spacing, fontSizes, Text, styles, cssProps } from '../..'
import { colors, spacing, fontSizes, Text, styles, cssProps, EnterAnimation } from '../..'
import { css, compose } from 'glamor'

export interface TabProps {
Expand Down Expand Up @@ -39,8 +39,10 @@ export function Tab(props: TabProps) {
const textStyle = css(BASE_TEXT, props.active && ACTIVE_TEXT)

return (
<div {...styleProps} onClick={props.onClick}>
<Text style={textStyle} text={props.text} />
</div>
<EnterAnimation animation='grow' speed={100} delay={400}>
<div {...styleProps} onClick={props.onClick}>
<Text style={textStyle} text={props.text} />
</div>
</EnterAnimation>
)
}