Henrique Sosa - Gorgeous apps with React Motion and Animations

22

Transcript of Henrique Sosa - Gorgeous apps with React Motion and Animations

Page 1: Henrique Sosa - Gorgeous apps with React Motion and Animations
Page 2: Henrique Sosa - Gorgeous apps with React Motion and Animations

Henrique Sosa@HiPlatform / São PauloGorgeous Apps with React Motion and Animations

Page 3: Henrique Sosa - Gorgeous apps with React Motion and Animations

Question to the audience quota

Page 4: Henrique Sosa - Gorgeous apps with React Motion and Animations

CSS AnimationsJavaScript Animations

Animated & Velocity-ReactReact Motion

Page 5: Henrique Sosa - Gorgeous apps with React Motion and Animations

CSS Animationsback to basics

Page 6: Henrique Sosa - Gorgeous apps with React Motion and Animations

class Input extends Component { state = { focused: false }

focus = () => { this.setState((state) => ({ focused: !state.focused })) }

render() { const { focused } = this.state return ( <input onFocus={this.focus} onBlur={this.focus} className={['input', focused && 'input-focused'].join(' ')} /> ); }}

Page 7: Henrique Sosa - Gorgeous apps with React Motion and Animations

performance

smooth transitions

CSS Classes

few state changes

Pros

Page 8: Henrique Sosa - Gorgeous apps with React Motion and Animations

not cross-platform

CSS

Cons

Page 9: Henrique Sosa - Gorgeous apps with React Motion and Animations

JavaScript Animationsspicing things up

Page 10: Henrique Sosa - Gorgeous apps with React Motion and Animations

class App extends Component {

state = {

disabled: true,

}

onChange = (e) => {

// control the state based on input length

}

render() {

const label = this.state.disabled ? 'Disabled' : 'Submit';

return (

<div className="App">

<button

style={...styles.button, !this.state.disabled && styles.buttonEnabled)}

disabled={this.state.disabled}

>{label}</button>

<input

style={styles.input}

onChange={this.onChange}

/>

</div>

);

}

}

Page 11: Henrique Sosa - Gorgeous apps with React Motion and Animations

const styles = {

input: {

width: 200,

outline: 'none',

fontSize: 20,

padding: 10,

border: 'none',

backgroundColor: '#ddd',

marginTop: 10,

},

button: {

width: 180,

height: 50,

border: 'none',

borderRadius: 4,

fontSize: 20,

cursor: 'pointer',

transition: '.25s all',

},

buttonEnabled: {

backgroundColor: '#ffc107',

width: 220,

}

}

Page 12: Henrique Sosa - Gorgeous apps with React Motion and Animations

performance

doesn’t need CSS

Pros

Page 13: Henrique Sosa - Gorgeous apps with React Motion and Animations

not cross-platform

adds complexity

Cons

Page 14: Henrique Sosa - Gorgeous apps with React Motion and Animations

Animations LibsAnimated & Velocity React

Page 15: Henrique Sosa - Gorgeous apps with React Motion and Animations

React-Native friendly ( Animated )

Flexibility

Easy implementation ( Velocity React )

Pros

Page 16: Henrique Sosa - Gorgeous apps with React Motion and Animations

Not 100% stable on the Web ( Animated )

It is another thing to learn

Performance issues ( Animated )

Auto-prefixing issues ( Animated )

not cross-platform ( Velocity React )

Cons

Page 17: Henrique Sosa - Gorgeous apps with React Motion and Animations

React MotionA spring that solves your animations

problems

Page 18: Henrique Sosa - Gorgeous apps with React Motion and Animations

class App extends Component {

state = {

height: 38

}

animate = () => {

this.setState((state) => ({ height: state.height === 233 ? 38 : 233 }))

}

render() {

return (

<div className="App">

<div style={styles.button} onClick={this.animate}>Animate</div>

<Motion style={{ height: spring(this.state.height) }}>

{

({ height }) => <div style={...styles.menu, { height } )}>

<p style={styles.selection}>Selection 1</p>

<p style={styles.selection}>Selection 2</p>

</div>

}

</Motion>

</div>

);

}

}

Page 19: Henrique Sosa - Gorgeous apps with React Motion and Animations

React Native and React Web friendly

Spring concept

Pros

Page 20: Henrique Sosa - Gorgeous apps with React Motion and Animations

Performance

It is another thing to learn

Cons

Page 21: Henrique Sosa - Gorgeous apps with React Motion and Animations

Reference Linksmedium.com/dabit3

@chenglou

Page 22: Henrique Sosa - Gorgeous apps with React Motion and Animations

Thank You(GIF quota)