|
1 |
| -import React, { useRef, useMemo } from 'react' |
2 |
| -import type { FC, TouchEvent, MouseEvent } from 'react' |
3 |
| -import classNames from 'classnames' |
| 1 | +import { useMemoizedFn } from 'ahooks' |
4 | 2 | import { DownOutline, TextDeletionOutline } from 'antd-mobile-icons'
|
5 |
| -import { mergeProps } from '../../utils/with-default-props' |
| 3 | +import classNames from 'classnames' |
| 4 | +import type { FC, MouseEvent, TouchEvent } from 'react' |
| 5 | +import React, { useMemo, useRef } from 'react' |
| 6 | +import { NativeProps, withNativeProps } from '../../utils/native-props' |
6 | 7 | import { shuffle } from '../../utils/shuffle'
|
| 8 | +import { mergeProps } from '../../utils/with-default-props' |
| 9 | +import { useConfig } from '../config-provider' |
7 | 10 | import Popup, { PopupProps } from '../popup'
|
8 |
| -import { NativeProps, withNativeProps } from '../../utils/native-props' |
9 | 11 | import SafeArea from '../safe-area'
|
10 |
| -import { useMemoizedFn } from 'ahooks' |
11 |
| -import { useConfig } from '../config-provider' |
12 | 12 |
|
13 | 13 | const classPrefix = 'adm-number-keyboard'
|
14 | 14 |
|
@@ -88,13 +88,13 @@ export const NumberKeyboard: FC<NumberKeyboardProps> = p => {
|
88 | 88 | props.onDelete?.()
|
89 | 89 | })
|
90 | 90 |
|
91 |
| - const onBackspacePressStart = () => { |
| 91 | + const startContinueClear = () => { |
92 | 92 | timeoutRef.current = window.setTimeout(() => {
|
93 | 93 | onDelete()
|
94 | 94 | intervalRef.current = window.setInterval(onDelete, 150)
|
95 | 95 | }, 700)
|
96 | 96 | }
|
97 |
| - const onBackspacePressEnd = () => { |
| 97 | + const stopContinueClear = () => { |
98 | 98 | clearTimeout(timeoutRef.current)
|
99 | 99 | clearInterval(intervalRef.current)
|
100 | 100 | }
|
@@ -174,14 +174,16 @@ export const NumberKeyboard: FC<NumberKeyboardProps> = p => {
|
174 | 174 | key={key}
|
175 | 175 | className={className}
|
176 | 176 | onTouchStart={() => {
|
| 177 | + stopContinueClear() |
| 178 | + |
177 | 179 | if (key === 'BACKSPACE') {
|
178 |
| - onBackspacePressStart() |
| 180 | + startContinueClear() |
179 | 181 | }
|
180 | 182 | }}
|
181 | 183 | onTouchEnd={e => {
|
182 | 184 | onKeyPress(e, key)
|
183 | 185 | if (key === 'BACKSPACE') {
|
184 |
| - onBackspacePressEnd() |
| 186 | + stopContinueClear() |
185 | 187 | }
|
186 | 188 | }}
|
187 | 189 | {...ariaProps}
|
@@ -226,11 +228,11 @@ export const NumberKeyboard: FC<NumberKeyboardProps> = p => {
|
226 | 228 | <div
|
227 | 229 | className={`${classPrefix}-key ${classPrefix}-key-extra ${classPrefix}-key-bs`}
|
228 | 230 | onTouchStart={() => {
|
229 |
| - onBackspacePressStart() |
| 231 | + startContinueClear() |
230 | 232 | }}
|
231 | 233 | onTouchEnd={e => {
|
232 | 234 | onKeyPress(e, 'BACKSPACE')
|
233 |
| - onBackspacePressEnd() |
| 235 | + stopContinueClear() |
234 | 236 | }}
|
235 | 237 | onContextMenu={e => {
|
236 | 238 | // Long press should not trigger native context menu
|
|
0 commit comments