@@ -128,10 +128,10 @@ export function usePress(props: PressProps) {
128
128
onPressStart,
129
129
} = safeProps ;
130
130
131
- const [ active , updateActive ] = React . useState ( null ) ;
131
+ const activeResponder = React . useRef ( null ) ;
132
132
133
133
const tap = useTap ( {
134
- disabled : disabled || active === 'keyboard' ,
134
+ disabled : disabled || activeResponder . current === 'keyboard' ,
135
135
preventDefault,
136
136
onAuxiliaryTap ( e ) {
137
137
if ( onPressStart != null ) {
@@ -147,56 +147,56 @@ export function usePress(props: PressProps) {
147
147
}
148
148
} ,
149
149
onTapStart ( e ) {
150
- if ( active == null ) {
151
- updateActive ( 'tap' ) ;
150
+ if ( activeResponder . current == null ) {
151
+ activeResponder . current = 'tap' ;
152
152
if ( onPressStart != null ) {
153
153
onPressStart ( createGestureState ( e , 'pressstart' ) ) ;
154
154
}
155
155
}
156
156
} ,
157
157
onTapChange : onPressChange ,
158
158
onTapUpdate ( e ) {
159
- if ( active === 'tap' ) {
159
+ if ( activeResponder . current === 'tap' ) {
160
160
if ( onPressMove != null ) {
161
161
onPressMove ( createGestureState ( e , 'pressmove' ) ) ;
162
162
}
163
163
}
164
164
} ,
165
165
onTapEnd ( e ) {
166
- if ( active === 'tap' ) {
166
+ if ( activeResponder . current === 'tap' ) {
167
167
if ( onPressEnd != null ) {
168
168
onPressEnd ( createGestureState ( e , 'pressend' ) ) ;
169
169
}
170
170
if ( onPress != null ) {
171
171
onPress ( createGestureState ( e , 'press' ) ) ;
172
172
}
173
- updateActive ( null ) ;
173
+ activeResponder . current = null ;
174
174
}
175
175
} ,
176
176
onTapCancel ( e ) {
177
- if ( active === 'tap' ) {
177
+ if ( activeResponder . current === 'tap' ) {
178
178
if ( onPressEnd != null ) {
179
179
onPressEnd ( createGestureState ( e , 'pressend' ) ) ;
180
180
}
181
- updateActive ( null ) ;
181
+ activeResponder . current = null ;
182
182
}
183
183
} ,
184
184
} ) ;
185
185
186
186
const keyboard = useKeyboard ( {
187
- disabled : disabled || active === 'tap' ,
187
+ disabled : disabled || activeResponder . current === 'tap' ,
188
188
onClick ( e ) {
189
189
if ( preventDefault !== false ) {
190
190
e . preventDefault ( ) ;
191
191
}
192
- if ( active == null && onPress != null ) {
192
+ if ( activeResponder . current == null && onPress != null ) {
193
193
onPress ( createGestureState ( e , 'press' ) ) ;
194
194
}
195
195
} ,
196
196
onKeyDown ( e ) {
197
- if ( active == null && isValidKey ( e ) ) {
197
+ if ( activeResponder . current == null && isValidKey ( e ) ) {
198
198
handlePreventDefault ( preventDefault , e ) ;
199
- updateActive ( 'keyboard' ) ;
199
+ activeResponder . current = 'keyboard' ;
200
200
201
201
if ( onPressStart != null ) {
202
202
onPressStart ( createGestureState ( e , 'pressstart' ) ) ;
@@ -207,7 +207,7 @@ export function usePress(props: PressProps) {
207
207
}
208
208
} ,
209
209
onKeyUp ( e ) {
210
- if ( active === 'keyboard' && isValidKey ( e ) ) {
210
+ if ( activeResponder . current === 'keyboard' && isValidKey ( e ) ) {
211
211
handlePreventDefault ( preventDefault , e ) ;
212
212
if ( onPressChange != null ) {
213
213
onPressChange ( false ) ;
@@ -218,7 +218,7 @@ export function usePress(props: PressProps) {
218
218
if ( onPress != null ) {
219
219
onPress ( createGestureState ( e , 'press' ) ) ;
220
220
}
221
- updateActive ( null ) ;
221
+ activeResponder . current = null ;
222
222
}
223
223
} ,
224
224
} ) ;
0 commit comments