|
import React, {Component} from 'react' |
|
import Force from './force.jsx' |
|
|
|
export default class Main extends Component { |
|
constructor (props) { |
|
super(props) |
|
this.state = {forcePct: 0, forceRaw: 0} |
|
} |
|
render () { |
|
return ( |
|
<Force onForceWillBegin={this.handleForceWillBegin} |
|
onForceChanged={this.handleForceChanged.bind(this)} |
|
onForceDown={this.handleForceDown} |
|
onForceUp={this.handleForceUp.bind(this)} |
|
onTouchStart={this.handleTouchStart.bind(this)} |
|
onTouchMove={this.handleTouchMove.bind(this)} |
|
onClick={this.handleClick} |
|
onMouseUp={this.handleMouseUp.bind(this)} |
|
> |
|
<StatusBar pct={this.state.forcePct} raw={this.state.forceRaw} /> |
|
</Force> |
|
) |
|
} |
|
|
|
handleClick (evt) { |
|
console.log('clicky!') |
|
} |
|
handleMouseUp (evt) { |
|
this.setState({forcePct: 0, forceRaw: 0}) |
|
} |
|
|
|
handleForceWillBegin (evt) { |
|
// evt.preventDefault() |
|
console.log('force beginning!') |
|
} |
|
|
|
handleForceChanged (evt) { |
|
if ('webkitForce' in evt) { |
|
let forceLevel = evt.webkitForce |
|
let clickForce = window.MouseEvent.WEBKIT_FORCE_AT_MOUSE_DOWN |
|
let forceClickForce = window.MouseEvent.WEBKIT_FORCE_AT_FORCE_MOUSE_DOWN |
|
|
|
if (forceLevel >= clickForce && forceLevel < forceClickForce) { |
|
// normal click stuff here |
|
let pct = forceLevel / forceClickForce |
|
this.setState({forcePct: pct, forceRaw: forceLevel}) |
|
// console.log(this.state) |
|
} else if (forceLevel >= forceClickForce) { |
|
// Perform operations in response to a force click |
|
this.setState({forcePct: (forceLevel / forceClickForce)}) |
|
} |
|
} |
|
} |
|
|
|
handleForceDown (evt) { |
|
console.log('cliiiiiick') |
|
} |
|
|
|
handleForceUp (evt) { |
|
console.log('ahhhhhhhhh') |
|
this.setState({forcePct: 0, forceRaw: 0}) |
|
} |
|
|
|
handleTouchStart (evt) { |
|
var force = evt.touches[0].force |
|
console.log(force) |
|
this.setState({forcePct: force, forceRaw: force}) |
|
} |
|
handleTouchMove (evt) { |
|
var force = evt.touches[0].force |
|
console.log(force) |
|
this.setState({forcePct: force, forceRaw: force}) |
|
} |
|
} |
|
|
|
let StatusBar = (props) => { |
|
let parentStyle = {height: 10} |
|
let childStyle = {height: '100%', width: `${props.pct * 100}%`, backgroundColor: 'red'} |
|
return <div style={parentStyle}> |
|
<div style={childStyle}></div> |
|
</div> |
|
} |