@@ -73,6 +73,21 @@ class Pickroll extends Component {
73
73
} ;
74
74
}
75
75
76
+ /**
77
+ * 组件需要渲染前,对手势事件处理进行初始化
78
+ */
79
+ componentWillMount ( ) {
80
+ this . _panResponder = PanResponder . create ( {
81
+ onStartShouldSetPanResponder : this . _handleStartShouldSetPanResponder . bind ( this ) ,
82
+ onMoveShouldSetPanResponder : this . _handleStartShouldSetPanResponder . bind ( this ) ,
83
+ onPanResponderGrant : this . _handlePanResponderGrant . bind ( this ) ,
84
+ onPanResponderRelease : this . _handlePanResponderRelease . bind ( this ) ,
85
+ onPanResponderMove : this . _handlePanResponderMove . bind ( this )
86
+ } ) ;
87
+ this . isMoving = false ;
88
+ this . index = this . state . selectedIndex ;
89
+ }
90
+
76
91
/**
77
92
* 根据移动的距离重新布局
78
93
* @param dy {number} 移动的距离
@@ -103,6 +118,7 @@ class Pickroll extends Component {
103
118
marginValue = diff * 36 ;
104
119
this . _move ( marginValue ) ;
105
120
this . index = index ;
121
+ this . moveDy = 0 ;
106
122
this . _onValueChange ( ) ;
107
123
} else { return 'you are moving' ; }
108
124
}
@@ -135,6 +151,7 @@ class Pickroll extends Component {
135
151
*/
136
152
_handlePanResponderRelease ( evt , gestureState ) {
137
153
let diff ;
154
+ console . debug ( gestureState . vy ) ;
138
155
diff = Math . abs ( this . moveDy ) % 36 >= 18 ? Math . ceil ( Math . abs ( this . moveDy / 36 ) ) : Math . floor ( Math . abs ( this . moveDy / 36 ) ) ;
139
156
if ( this . moveDy >= 0 ) { this . index = this . index - diff } else { this . index = this . index + diff ; }
140
157
this . middle && this . middle . setNativeProps ( {
@@ -146,20 +163,6 @@ class Pickroll extends Component {
146
163
this . _onValueChange ( ) ;
147
164
}
148
165
149
- /**
150
- * 组件需要渲染前,对手势事件处理进行初始化
151
- */
152
- componentWillMount ( ) {
153
- this . _panResponder = PanResponder . create ( {
154
- onStartShouldSetPanResponder : this . _handleStartShouldSetPanResponder . bind ( this ) ,
155
- onMoveShouldSetPanResponder : this . _handleStartShouldSetPanResponder . bind ( this ) ,
156
- onPanResponderGrant : this . _handlePanResponderGrant . bind ( this ) ,
157
- onPanResponderRelease : this . _handlePanResponderRelease . bind ( this ) ,
158
- onPanResponderMove : this . _handlePanResponderMove . bind ( this )
159
- } ) ;
160
- this . isMoving = false ;
161
- this . index = this . state . selectedIndex ;
162
- }
163
166
164
167
_handleStartShouldSetPanResponder ( e , gestureState ) {
165
168
return true ;
@@ -177,10 +180,10 @@ class Pickroll extends Component {
177
180
_renderItems ( items , init ) {
178
181
let upItems = [ ] , middleItems = [ ] , downItems = [ ] ;
179
182
items . forEach ( ( item , index ) => {
180
- console . debug ( ( 1 - Math . abs ( ( index - this . index ) * 36 + this . moveDy ) / 36 * 0.05 ) * 22 ) ;
181
183
middleItems [ index ] = < Text
182
184
key = { 'mid' + index }
183
185
className = { 'mid' + index }
186
+ onPress = { ( ) => { this . _moveTo ( index ) } }
184
187
style = { [ rollStyles . middleText , this . state . itemStyle , { fontSize : ( 1 - Math . abs ( ( index - this . index ) * 36 + this . moveDy ) / 36 * 0.07 ) * 22 , opacity : 1 - Math . abs ( ( index - this . index ) * 36 + this . moveDy ) / 36 * 0.4 } ] } > { item . label }
185
188
</ Text > ;
186
189
} ) ;
0 commit comments