1
- /* tslint:disable:no-console */
1
+ /* tslint:disable:no-console no-unused-expression */
2
2
3
3
import Gesture from '../src/index' ;
4
4
import React , { Component } from 'react' ;
@@ -25,23 +25,45 @@ const style = `
25
25
class Demo extends Component < any , any > {
26
26
private root : any ;
27
27
private rootNode : any ;
28
+ private _scale : number ;
29
+ private _rotation : number ;
28
30
29
31
constructor ( props ) {
30
32
super ( props ) ;
31
33
}
32
34
33
35
log = ( type : string , keys ?: string [ ] ) => ( ...args ) => {
34
- console . log ( type , ...args ) ;
36
+ this . doTapOrPress ( type , keys , ...args ) ;
37
+ this . doTransform ( type , ...args ) ;
38
+ }
39
+ doTapOrPress = ( type , keys , ...args ) => {
40
+ if ( [ 'onTap' , 'onPress' , 'onPressUp' ] . indexOf ( type ) === - 1 ) {
41
+ return ;
42
+ }
35
43
const extInfo = keys ? keys . map ( key => `${ key } = ${ args [ 0 ] [ key ] } ` ) . join ( ', ' ) : '' ;
36
44
const logEl = this . refs . log as any ;
37
45
logEl . innerHTML += `<p>${ type } ${ extInfo } </p>` ;
38
46
logEl . scrollTop = logEl . scrollHeight ;
47
+ }
48
+ doTransform = ( type , ...args ) => {
39
49
if ( type === 'onPinch' ) {
40
50
const { scale } = args [ 0 ] ;
41
- this . rootNode = ReactDOM . findDOMNode ( this . root ) ;
42
- this . rootNode . style . transform = `scale(${ scale } )` ;
51
+ this . _scale = scale ;
43
52
}
53
+ if ( type === 'onRotate' ) {
54
+ const { rotation } = args [ 0 ] ;
55
+ this . _rotation = rotation ;
56
+ }
57
+ let transform : any = [ ] ;
58
+ // console.log(type, ...args); let transform: any = [];
59
+ this . _scale && transform . push ( `scale(${ this . _scale } )` ) ;
60
+ this . _rotation && transform . push ( `rotate(${ this . _rotation } deg)` ) ;
61
+
62
+ transform = transform . join ( ' ' ) ;
63
+ this . rootNode = ReactDOM . findDOMNode ( this . root ) ;
64
+ this . rootNode . style . transform = transform ;
44
65
}
66
+
45
67
render ( ) {
46
68
return (
47
69
< div >
0 commit comments