10
10
11
11
'use strict' ;
12
12
13
- var React = require ( 'react' ) ;
14
- var ReactNative = require ( 'react-native' ) ;
15
- var { Animated, LayoutAnimation, PanResponder, StyleSheet, View} = ReactNative ;
13
+ const React = require ( 'react' ) ;
14
+ const ReactNative = require ( 'react-native' ) ;
15
+ const { Animated, LayoutAnimation, PanResponder, StyleSheet, View} = ReactNative ;
16
16
17
- var AnExSet = require ( 'AnExSet' ) ;
17
+ const AnExSet = require ( 'AnExSet' ) ;
18
18
19
- var CIRCLE_SIZE = 80 ;
20
- var CIRCLE_MARGIN = 18 ;
21
- var NUM_CIRCLES = 30 ;
19
+ const CIRCLE_SIZE = 80 ;
20
+ const CIRCLE_MARGIN = 18 ;
21
+ const NUM_CIRCLES = 30 ;
22
22
23
23
class Circle extends React . Component < any , any > {
24
24
longTimer : number ;
@@ -37,7 +37,7 @@ class Circle extends React.Component<any, any> {
37
37
}
38
38
39
39
_onLongPress ( ) : void {
40
- var config = { tension : 40 , friction : 3 } ;
40
+ const config = { tension : 40 , friction : 3 } ;
41
41
this . state . pan . addListener ( value => {
42
42
// Async listener for state changes (step1: uncomment)
43
43
this . props . onMove && this . props . onMove ( value ) ;
@@ -77,9 +77,11 @@ class Circle extends React.Component<any, any> {
77
77
}
78
78
79
79
render ( ) : React . Node {
80
+ let handlers ;
81
+ let dragStyle = null ;
80
82
if ( this . state . panResponder ) {
81
- var handlers = this . state . panResponder . panHandlers ;
82
- var dragStyle = {
83
+ handlers = this . state . panResponder . panHandlers ;
84
+ dragStyle = {
83
85
// Used to position while dragging
84
86
position : 'absolute' , // Hoist out of layout (step1: uncomment)
85
87
...this . state . pan . getLayout ( ) , // Convenience converter (step1: uncomment)
@@ -106,7 +108,7 @@ class Circle extends React.Component<any, any> {
106
108
} ,
107
109
} ;
108
110
}
109
- var animatedStyle : Object = {
111
+ const animatedStyle : Object = {
110
112
shadowOpacity : this . state . pop , // no need for interpolation (step2d: uncomment)
111
113
transform : [
112
114
{
@@ -117,11 +119,12 @@ class Circle extends React.Component<any, any> {
117
119
} ,
118
120
] ,
119
121
} ;
120
- var openVal = this . props . openVal ;
122
+ const openVal = this . props . openVal ;
123
+ let innerOpenStyle = null ;
121
124
if ( this . props . dummy ) {
122
125
animatedStyle . opacity = 0 ;
123
126
} else if ( this . state . isActive ) {
124
- var innerOpenStyle = [
127
+ innerOpenStyle = [
125
128
styles . open ,
126
129
{
127
130
// (step4: uncomment)
@@ -175,7 +178,7 @@ class Circle extends React.Component<any, any> {
175
178
) ;
176
179
}
177
180
_toggleIsActive ( velocity ) {
178
- var config = { tension : 30 , friction : 7 } ;
181
+ const config = { tension : 30 , friction : 7 } ;
179
182
if ( this . state . isActive ) {
180
183
Animated . spring ( this . props . openVal , { toValue : 0 , ...config } ) . start ( ( ) => {
181
184
// (step4: uncomment)
@@ -200,8 +203,8 @@ class AnExApp extends React.Component<any, any> {
200
203
_onMove : ( position : Point ) => void ;
201
204
constructor ( props : any ) : void {
202
205
super ( props ) ;
203
- var keys = [ ] ;
204
- for ( var idx = 0 ; idx < NUM_CIRCLES ; idx ++ ) {
206
+ const keys = [ ] ;
207
+ for ( let idx = 0 ; idx < NUM_CIRCLES ; idx ++ ) {
205
208
keys . push ( 'E' + idx ) ;
206
209
}
207
210
this . state = {
@@ -213,13 +216,14 @@ class AnExApp extends React.Component<any, any> {
213
216
}
214
217
215
218
render ( ) : React . Node {
216
- var circles = this . state . keys . map ( ( key , idx ) => {
219
+ const circles = this . state . keys . map ( ( key , idx ) => {
217
220
if ( key === this . state . activeKey ) {
218
221
return < Circle key = { key + 'd' } dummy = { true } /> ;
219
222
} else {
223
+ let onLayout = null ;
220
224
if ( ! this . state . restLayouts [ idx ] ) {
221
- var onLayout = function ( index , e ) {
222
- var layout = e . nativeEvent . layout ;
225
+ onLayout = function ( index , e ) {
226
+ const layout = e . nativeEvent . layout ;
223
227
this . setState ( state => {
224
228
state . restLayouts [ index ] = layout ;
225
229
return state ;
@@ -274,7 +278,7 @@ class AnExApp extends React.Component<any, any> {
274
278
}
275
279
276
280
_onMove ( position : Point ) : void {
277
- var newKeys = moveToClosest ( this . state , position ) ;
281
+ const newKeys = moveToClosest ( this . state , position ) ;
278
282
if ( newKeys !== this . state . keys ) {
279
283
LayoutAnimation . easeInEaseOut ( ) ; // animates layout update as one batch (step3: uncomment)
280
284
this . setState ( { keys : newKeys } ) ;
@@ -284,18 +288,18 @@ class AnExApp extends React.Component<any, any> {
284
288
285
289
type Point = { x : number , y : number } ;
286
290
function distance ( p1 : Point , p2 : Point ) : number {
287
- var dx = p1 . x - p2 . x ;
288
- var dy = p1 . y - p2 . y ;
291
+ const dx = p1 . x - p2 . x ;
292
+ const dy = p1 . y - p2 . y ;
289
293
return dx * dx + dy * dy ;
290
294
}
291
295
292
296
function moveToClosest ( { activeKey, keys, restLayouts} , position ) {
293
- var activeIdx = - 1 ;
294
- var closestIdx = activeIdx ;
295
- var minDist = Infinity ;
296
- var newKeys = [ ] ;
297
+ const activeIdx = - 1 ;
298
+ let closestIdx = activeIdx ;
299
+ let minDist = Infinity ;
300
+ const newKeys = [ ] ;
297
301
keys . forEach ( ( key , idx ) => {
298
- var dist = distance ( position , restLayouts [ idx ] ) ;
302
+ const dist = distance ( position , restLayouts [ idx ] ) ;
299
303
if ( key === activeKey ) {
300
304
idx = activeIdx ;
301
305
} else {
@@ -314,7 +318,7 @@ function moveToClosest({activeKey, keys, restLayouts}, position) {
314
318
}
315
319
}
316
320
317
- var styles = StyleSheet . create ( {
321
+ const styles = StyleSheet . create ( {
318
322
container : {
319
323
flex : 1 ,
320
324
} ,
0 commit comments