react-native-nitro-input 0.4.1 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -0
- package/NitroInput.podspec +2 -2
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroNumberView.kt +24 -1
- package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputView.kt +60 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/NitroNumberView.kt +290 -137
- package/ios/CodePointOffsets.swift +35 -0
- package/ios/NitroInputView.swift +2 -10
- package/ios/__tests__/CodePointOffsetsTest.swift +77 -0
- package/lib/commonjs/src/NitroNumber.js +94 -29
- package/lib/module/src/NitroNumber.js +94 -29
- package/package.json +2 -1
- package/src/NitroNumber.tsx +121 -54
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.4
|
|
4
|
+
|
|
5
|
+
- **iOS: no more crash editing next to an emoji.** UIKit can hand
|
|
6
|
+
`textField(_:shouldChangeCharactersIn:)` a range whose offset falls inside a
|
|
7
|
+
surrogate pair (an emoji, or another character outside the Basic
|
|
8
|
+
Multilingual Plane). Converting it to code points stepped back from an
|
|
9
|
+
unaligned index: that trapped (`EXC_BREAKPOINT`, "String index is out of
|
|
10
|
+
bounds") when the pair was the first character, and counted one code point
|
|
11
|
+
too few anywhere else, so number, mask and `transform` edits and the
|
|
12
|
+
reported selection landed one character early. Such an offset now counts as
|
|
13
|
+
the start of its code point, as `String.replaceSubrange` rounds it. Covered
|
|
14
|
+
by `bun run test:swift`.
|
|
15
|
+
|
|
16
|
+
## 0.4.3
|
|
17
|
+
|
|
18
|
+
0.4.2 was never published; its change is part of this release, with the
|
|
19
|
+
selection-drag regression it brought fixed before it shipped.
|
|
20
|
+
|
|
21
|
+
- **Android: a long-press selection drag or cursor drag inside a scroll view
|
|
22
|
+
or pager stays with the field (#73).** The field's edit text never asked
|
|
23
|
+
its parent not to intercept, so a `ScrollView` (or `KeyboardAwareScrollView`,
|
|
24
|
+
or a pager) could take the touch on the first move and cancel the selection
|
|
25
|
+
or cursor drag. The field now holds the touch from the start, keeps it once
|
|
26
|
+
a long-press has started a drag, and otherwise hands it back once the finger
|
|
27
|
+
has moved past the touch slop, unless the field can scroll its own text in
|
|
28
|
+
that direction. A vertical swipe that starts on a field still scrolls the
|
|
29
|
+
page, and a horizontal one still pages a pager, read-only fields included.
|
|
30
|
+
- **Android: a vertical swipe that starts on a field with more text than fits
|
|
31
|
+
scrolls the page.** A single-line field holding a long value can scroll its
|
|
32
|
+
text sideways, and that no longer makes it keep vertical swipes.
|
|
33
|
+
|
|
34
|
+
React Native's own `TextInput` (`ReactEditText`) has both bugs; NitroInput
|
|
35
|
+
has neither.
|
|
36
|
+
- **Android: `NitroNumber` no longer leaks views or hybrids**, behind the
|
|
37
|
+
out-of-memory crashes on low-end phones. The glyph-mask warm-up queue held
|
|
38
|
+
each dropped view until its tasks ran and grew without bound when the
|
|
39
|
+
typography changed often; its tasks are now plain data, owned and cancelled
|
|
40
|
+
per view, and capped. Callback props rooted the component that held them, so
|
|
41
|
+
Hermes never collected an unmounted `NitroNumber`'s hybrid; they now reach the
|
|
42
|
+
component through a `WeakRef`, and the hybrid drops them when its view goes.
|
|
43
|
+
|
|
3
44
|
## 0.4.1
|
|
4
45
|
|
|
5
46
|
- **`NitroInput`'s `tabularNums` prop: tabular digits in any font.** Digits
|
package/NitroInput.podspec
CHANGED
|
@@ -25,8 +25,8 @@ Pod::Spec.new do |s|
|
|
|
25
25
|
# The shared C++ engines and formatter are public headers so the pod's Swift
|
|
26
26
|
# sources can call them directly through Swift/C++ interop (enabled by Nitro below).
|
|
27
27
|
s.public_header_files = ["cpp/**/*.hpp"]
|
|
28
|
-
# The engines' unit tests build as
|
|
29
|
-
s.exclude_files = ["cpp/__tests__/**"]
|
|
28
|
+
# The engines' unit tests build as host executables (`bun run test:cpp`, `bun run test:swift`).
|
|
29
|
+
s.exclude_files = ["cpp/__tests__/**", "ios/__tests__/**"]
|
|
30
30
|
|
|
31
31
|
# Worklets are optional: with react-native-worklets in the app, `transform`
|
|
32
32
|
# and worklet callbacks run synchronously on the UI thread.
|
|
@@ -214,7 +214,8 @@ class HybridNitroNumberView(private val context: ThemedReactContext) : HybridNit
|
|
|
214
214
|
override var onSizeChange: ((width: Double, height: Double) -> Unit)? = null
|
|
215
215
|
set(v) {
|
|
216
216
|
field = v
|
|
217
|
-
|
|
217
|
+
// Not `rollingView`: on a dropped hybrid that would make a fresh view to send nothing.
|
|
218
|
+
onMain { attachedView?.resendIntrinsicSize() }
|
|
218
219
|
}
|
|
219
220
|
|
|
220
221
|
// endregion
|
|
@@ -294,6 +295,7 @@ class HybridNitroNumberView(private val context: ThemedReactContext) : HybridNit
|
|
|
294
295
|
*/
|
|
295
296
|
override fun onDropView() {
|
|
296
297
|
recycled = false
|
|
298
|
+
releaseCallbacks()
|
|
297
299
|
onMain {
|
|
298
300
|
attachedView?.release()
|
|
299
301
|
// With view recycling on, Fabric asks for prepareForRecycle right after
|
|
@@ -305,9 +307,30 @@ class HybridNitroNumberView(private val context: ThemedReactContext) : HybridNit
|
|
|
305
307
|
|
|
306
308
|
/** JS called `dispose()` on the ref: same as a drop. */
|
|
307
309
|
override fun dispose() {
|
|
310
|
+
releaseCallbacks()
|
|
308
311
|
onMain { attachedView?.release() }
|
|
309
312
|
}
|
|
310
313
|
|
|
314
|
+
/**
|
|
315
|
+
* Lets go of the JS functions this hybrid holds (`onSizeChange` and the
|
|
316
|
+
* animation and reveal events). Each is a JS function kept alive from
|
|
317
|
+
* native, so Hermes counts it as a root; its closure reaches the
|
|
318
|
+
* component's refs, one of which holds the JS handle to this hybrid, and
|
|
319
|
+
* that handle keeps this hybrid. Held past the drop, that loop is one
|
|
320
|
+
* Hermes can never collect, however large `memorySize` says it is: every
|
|
321
|
+
* dropped NitroNumber stayed (its hybrid, Nitro's C++ part and the
|
|
322
|
+
* function wrappers), ~7,000 of them after a few minutes of a scrolling
|
|
323
|
+
* list. Dropped, the handle is ordinary garbage. A recycled view gets
|
|
324
|
+
* its callbacks back with its new element's props.
|
|
325
|
+
*/
|
|
326
|
+
private fun releaseCallbacks() {
|
|
327
|
+
onSizeChange = null
|
|
328
|
+
onRevealEnd = null
|
|
329
|
+
onRevealMilestone = null
|
|
330
|
+
onAnimationStart = null
|
|
331
|
+
onAnimationEnd = null
|
|
332
|
+
}
|
|
333
|
+
|
|
311
334
|
/**
|
|
312
335
|
* Reported to the JS garbage collector so a dropped view's handle counts as
|
|
313
336
|
* the memory it holds rather than as an empty object; that is what makes
|
|
@@ -24,7 +24,9 @@ import android.util.TypedValue
|
|
|
24
24
|
import android.view.Choreographer
|
|
25
25
|
import android.view.Gravity
|
|
26
26
|
import android.view.KeyEvent
|
|
27
|
+
import android.view.MotionEvent
|
|
27
28
|
import android.view.View
|
|
29
|
+
import android.view.ViewConfiguration
|
|
28
30
|
import android.view.animation.PathInterpolator
|
|
29
31
|
import android.view.inputmethod.EditorInfo
|
|
30
32
|
import android.view.inputmethod.InputConnection
|
|
@@ -416,6 +418,64 @@ class NitroInputView(context: Context) : FrameLayout(context) {
|
|
|
416
418
|
private inner class HiddenEditText(context: Context) : AppCompatEditText(context) {
|
|
417
419
|
var ready = false
|
|
418
420
|
|
|
421
|
+
// Touch hand-off to scrolling parents (#73). The parent may not intercept
|
|
422
|
+
// until the finger has moved past the touch slop; the touch then goes back
|
|
423
|
+
// to it unless the field can scroll its own text in the direction the
|
|
424
|
+
// finger moves. Holding the whole touch instead (any move but a vertical
|
|
425
|
+
// one) broke paging a horizontal pager from a field.
|
|
426
|
+
//
|
|
427
|
+
// React Native's ReactEditText decides on the first move and keeps the
|
|
428
|
+
// touch whenever the field can scroll in any direction. Two of its bugs
|
|
429
|
+
// stay out of here:
|
|
430
|
+
// - A long-press that fired before the decision keeps the touch: the
|
|
431
|
+
// Editor then runs a selection drag (and has already disallowed
|
|
432
|
+
// intercepting) or has just placed the cursor. Handing the touch back
|
|
433
|
+
// let a ScrollView take a selection drag that drifts a little down, or a
|
|
434
|
+
// pager one that runs sideways, and the selection stuck on the first
|
|
435
|
+
// word. A long-press after the hand-back disallows intercepting again
|
|
436
|
+
// by itself, as does a cursor drag in a focused field.
|
|
437
|
+
// - A field whose single line of text is longer than the field can scroll
|
|
438
|
+
// only sideways, so a vertical swipe that starts on it is the page's.
|
|
439
|
+
private var detectScrollMovement = false
|
|
440
|
+
private var longPressed = false
|
|
441
|
+
private var downX = 0f
|
|
442
|
+
private var downY = 0f
|
|
443
|
+
private val touchSlop = ViewConfiguration.get(context).scaledTouchSlop
|
|
444
|
+
|
|
445
|
+
override fun onTouchEvent(event: MotionEvent): Boolean {
|
|
446
|
+
when (event.actionMasked) {
|
|
447
|
+
MotionEvent.ACTION_DOWN -> {
|
|
448
|
+
detectScrollMovement = true
|
|
449
|
+
longPressed = false
|
|
450
|
+
downX = event.x
|
|
451
|
+
downY = event.y
|
|
452
|
+
parent?.requestDisallowInterceptTouchEvent(true)
|
|
453
|
+
}
|
|
454
|
+
MotionEvent.ACTION_MOVE -> if (detectScrollMovement) {
|
|
455
|
+
val dx = abs(event.x - downX)
|
|
456
|
+
val dy = abs(event.y - downY)
|
|
457
|
+
if (longPressed) {
|
|
458
|
+
detectScrollMovement = false
|
|
459
|
+
} else if (dx > touchSlop || dy > touchSlop) {
|
|
460
|
+
val scrollsItself = if (dy > dx) {
|
|
461
|
+
canScrollVertically(-1) || canScrollVertically(1)
|
|
462
|
+
} else {
|
|
463
|
+
canScrollHorizontally(-1) || canScrollHorizontally(1)
|
|
464
|
+
}
|
|
465
|
+
if (!scrollsItself) parent?.requestDisallowInterceptTouchEvent(false)
|
|
466
|
+
detectScrollMovement = false
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
return super.onTouchEvent(event)
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
override fun performLongClick(): Boolean {
|
|
474
|
+
val handled = super.performLongClick()
|
|
475
|
+
if (handled) longPressed = true
|
|
476
|
+
return handled
|
|
477
|
+
}
|
|
478
|
+
|
|
419
479
|
override fun getOffsetForPosition(x: Float, y: Float): Int {
|
|
420
480
|
// A plain field draws its own text and the engine holds no glyphs for
|
|
421
481
|
// it, so the EditText's own mapping is the right one. (Going through the
|