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

Commit b19bc94

Browse files
authored
Merge pull request #41 from skellock/enter-animations
Adds an entrance animation component for nicer startup.
2 parents 650bb8b + 60b1bcd commit b19bc94

File tree

6 files changed

+91
-9
lines changed

6 files changed

+91
-9
lines changed

src/main/main-window/main-window.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ export function createMainWindow(appPath: string) {
3333
autoHideMenuBar: true,
3434
backgroundColor: '#fff',
3535
title: app.getName(),
36+
webPreferences: {
37+
backgroundThrottling: false,
38+
textAreasAreResizable: false,
39+
},
3640
})
3741

3842
// maximize if we did before

src/renderer/features/example-using-tabs/welcome-screen/sample-tabs.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
styles,
99
cssProps,
1010
commandOrControlKey,
11+
EnterAnimation,
1112
} from '../../../platform'
1213
import { css, compose } from 'glamor'
1314

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

25-
const ROOT = compose(
26-
styles.windowDrag,
26+
// an extra layer just for the drag style due to electron bug
27+
const ROOT = styles.windowDrag
28+
29+
const BAR = compose(
2730
styles.row,
2831
cssProps({
2932
paddingLeft: spacing.medium,
@@ -57,11 +60,16 @@ export class SampleTabs extends React.PureComponent<SampleTabsProps, {}> {
5760

5861
render() {
5962
const { tab } = this.props
63+
6064
return (
6165
<div {...css(ROOT)}>
62-
<Tab onClick={this.changeTab1} active={tab === 'one'} text='doggo' />
63-
<Tab onClick={this.changeTab2} active={tab === 'two'} text='paragraphs' />
64-
<Tab onClick={this.changeTab3} active={tab === 'three'} text='empty' />
66+
<EnterAnimation animation='slide' delay={100} y={-60}>
67+
<div {...BAR}>
68+
<Tab onClick={this.changeTab1} active={tab === 'one'} text='doggo' />
69+
<Tab onClick={this.changeTab2} active={tab === 'two'} text='paragraphs' />
70+
<Tab onClick={this.changeTab3} active={tab === 'three'} text='empty' />
71+
</div>
72+
</EnterAnimation>
6573
</div>
6674
)
6775
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import * as React from 'react'
2+
import { cssProps } from '../..'
3+
import { css } from 'glamor'
4+
5+
interface EnterAnimationState {
6+
mounted?: boolean
7+
}
8+
9+
export interface EnterAnimationProps {
10+
children?: React.ReactNode
11+
/** the type of animation */
12+
animation: 'grow' | 'slide'
13+
/** how long to wait in milliseconds before starting */
14+
delay?: number
15+
/** how fast to complete the animation in milliseconds */
16+
speed?: number
17+
/** how far vertically to slide */
18+
y?: number
19+
}
20+
21+
const DEFAULT_SPEED = 250
22+
const DEFAULT_DELAY = 0
23+
24+
const SCALE_FROM = `scale(0.01, 0.01)`
25+
26+
const FINISH = cssProps({ transform: `translate(0, 0) scale(1, 1)` })
27+
28+
export class EnterAnimation extends React.PureComponent<EnterAnimationProps, EnterAnimationState> {
29+
state: EnterAnimationState = {}
30+
31+
componentDidMount() {
32+
setTimeout(() => this.setState({ mounted: true }), 1)
33+
}
34+
35+
render() {
36+
// values
37+
const { mounted } = this.state
38+
const { speed = DEFAULT_SPEED, delay = DEFAULT_DELAY, animation, y = 0 } = this.props
39+
40+
// css properties
41+
let transform: string
42+
43+
switch (animation) {
44+
case 'slide':
45+
transform = `translate(0, ${y}px)`
46+
break
47+
48+
// grow
49+
default:
50+
transform = SCALE_FROM
51+
break
52+
}
53+
54+
const transition = `transform ${speed || DEFAULT_SPEED}ms ${delay || DEFAULT_DELAY}ms`
55+
56+
// style props
57+
const starting = css(cssProps({ transform, transition }))
58+
const finishing = css(mounted && FINISH)
59+
60+
return (
61+
<div {...starting} {...finishing}>
62+
{this.props.children}
63+
</div>
64+
)
65+
}
66+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './enter-animation'

src/renderer/platform/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from './text'
22
export * from './scrollable-content'
33
export * from './centered-content'
44
export * from './tab'
5+
export * from './enter-animation'

src/renderer/platform/components/tab/tab.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react'
22
import { CSSProperties } from 'react'
3-
import { colors, spacing, fontSizes, Text, styles, cssProps } from '../..'
3+
import { colors, spacing, fontSizes, Text, styles, cssProps, EnterAnimation } from '../..'
44
import { css, compose } from 'glamor'
55

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

4141
return (
42-
<div {...styleProps} onClick={props.onClick}>
43-
<Text style={textStyle} text={props.text} />
44-
</div>
42+
<EnterAnimation animation='grow' speed={100} delay={400}>
43+
<div {...styleProps} onClick={props.onClick}>
44+
<Text style={textStyle} text={props.text} />
45+
</div>
46+
</EnterAnimation>
4547
)
4648
}

0 commit comments

Comments
 (0)