1010
1111'use strict' ;
1212
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 ;
1616
17- var AnExSet = require ( 'AnExSet' ) ;
17+ const AnExSet = require ( 'AnExSet' ) ;
1818
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 ;
2222
2323class Circle extends React . Component < any , any > {
2424 longTimer : number ;
@@ -37,7 +37,7 @@ class Circle extends React.Component<any, any> {
3737 }
3838
3939 _onLongPress ( ) : void {
40- var config = { tension : 40 , friction : 3 } ;
40+ const config = { tension : 40 , friction : 3 } ;
4141 this . state . pan . addListener ( value => {
4242 // Async listener for state changes (step1: uncomment)
4343 this . props . onMove && this . props . onMove ( value ) ;
@@ -77,9 +77,11 @@ class Circle extends React.Component<any, any> {
7777 }
7878
7979 render ( ) : React . Node {
80+ let handlers ;
81+ let dragStyle = null ;
8082 if ( this . state . panResponder ) {
81- var handlers = this . state . panResponder . panHandlers ;
82- var dragStyle = {
83+ handlers = this . state . panResponder . panHandlers ;
84+ dragStyle = {
8385 // Used to position while dragging
8486 position : 'absolute' , // Hoist out of layout (step1: uncomment)
8587 ...this . state . pan . getLayout ( ) , // Convenience converter (step1: uncomment)
@@ -106,7 +108,7 @@ class Circle extends React.Component<any, any> {
106108 } ,
107109 } ;
108110 }
109- var animatedStyle : Object = {
111+ const animatedStyle : Object = {
110112 shadowOpacity : this . state . pop , // no need for interpolation (step2d: uncomment)
111113 transform : [
112114 {
@@ -117,11 +119,12 @@ class Circle extends React.Component<any, any> {
117119 } ,
118120 ] ,
119121 } ;
120- var openVal = this . props . openVal ;
122+ const openVal = this . props . openVal ;
123+ let innerOpenStyle = null ;
121124 if ( this . props . dummy ) {
122125 animatedStyle . opacity = 0 ;
123126 } else if ( this . state . isActive ) {
124- var innerOpenStyle = [
127+ innerOpenStyle = [
125128 styles . open ,
126129 {
127130 // (step4: uncomment)
@@ -175,7 +178,7 @@ class Circle extends React.Component<any, any> {
175178 ) ;
176179 }
177180 _toggleIsActive ( velocity ) {
178- var config = { tension : 30 , friction : 7 } ;
181+ const config = { tension : 30 , friction : 7 } ;
179182 if ( this . state . isActive ) {
180183 Animated . spring ( this . props . openVal , { toValue : 0 , ...config } ) . start ( ( ) => {
181184 // (step4: uncomment)
@@ -200,8 +203,8 @@ class AnExApp extends React.Component<any, any> {
200203 _onMove : ( position : Point ) => void ;
201204 constructor ( props : any ) : void {
202205 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 ++ ) {
205208 keys . push ( 'E' + idx ) ;
206209 }
207210 this . state = {
@@ -213,13 +216,14 @@ class AnExApp extends React.Component<any, any> {
213216 }
214217
215218 render ( ) : React . Node {
216- var circles = this . state . keys . map ( ( key , idx ) => {
219+ const circles = this . state . keys . map ( ( key , idx ) => {
217220 if ( key === this . state . activeKey ) {
218221 return < Circle key = { key + 'd' } dummy = { true } /> ;
219222 } else {
223+ let onLayout = null ;
220224 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 ;
223227 this . setState ( state => {
224228 state . restLayouts [ index ] = layout ;
225229 return state ;
@@ -274,7 +278,7 @@ class AnExApp extends React.Component<any, any> {
274278 }
275279
276280 _onMove ( position : Point ) : void {
277- var newKeys = moveToClosest ( this . state , position ) ;
281+ const newKeys = moveToClosest ( this . state , position ) ;
278282 if ( newKeys !== this . state . keys ) {
279283 LayoutAnimation . easeInEaseOut ( ) ; // animates layout update as one batch (step3: uncomment)
280284 this . setState ( { keys : newKeys } ) ;
@@ -284,18 +288,18 @@ class AnExApp extends React.Component<any, any> {
284288
285289type Point = { x : number , y : number } ;
286290function 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 ;
289293 return dx * dx + dy * dy ;
290294}
291295
292296function 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 = [ ] ;
297301 keys . forEach ( ( key , idx ) => {
298- var dist = distance ( position , restLayouts [ idx ] ) ;
302+ const dist = distance ( position , restLayouts [ idx ] ) ;
299303 if ( key === activeKey ) {
300304 idx = activeIdx ;
301305 } else {
@@ -314,7 +318,7 @@ function moveToClosest({activeKey, keys, restLayouts}, position) {
314318 }
315319}
316320
317- var styles = StyleSheet . create ( {
321+ const styles = StyleSheet . create ( {
318322 container : {
319323 flex : 1 ,
320324 } ,
0 commit comments