react-native-nitro-input 0.3.5 → 0.3.7

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 CHANGED
@@ -1,5 +1,29 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.7
4
+
5
+ - **Android: no longer breaks VisionCamera frame processors.** NitroInput
6
+ linked `libworklets.so` although it uses only worklets' header-inline API,
7
+ and as a Nitro package it loads at app start, so it became the first library
8
+ to load `libworklets.so`. On Android that changes which copy of worklets'
9
+ weak RTTI each library binds to; `react-native-vision-camera-worklets`'
10
+ frame-processor queue then failed worklets' `dynamic_cast`, the runtime got a
11
+ null queue, and opening any frame-processor camera crashed with SIGSEGV in
12
+ `worklets::WorkletRuntime::scheduleImpl`. Worklets is now used headers-only
13
+ (no `DT_NEEDED`), and `installRuntime` checks the UI runtime holder by type
14
+ name instead of `dynamic_cast`, which is not reliable across shared libraries
15
+ on Android.
16
+
17
+ ## 0.3.6
18
+
19
+ - **A controlled `selection` rendered before the latest keystrokes is
20
+ dropped**, as `value` already was and as React Native's `TextInput` does.
21
+ Typed faster than JS renders (a slow Android phone, a busy JS thread), a
22
+ caret computed for an earlier text landed in a field that already had more
23
+ in it, and the next characters went in behind the first ones: a code field
24
+ driven by `selection` took "123456" as "156234". Uncontrolled fields are
25
+ unchanged.
26
+
3
27
  ## 0.3.5
4
28
 
5
29
  - **`focusedValue`**: pass a shared value (Reanimated's `useSharedValue(false)`)
@@ -39,10 +39,23 @@ include_directories(
39
39
 
40
40
  # Worklets are optional: with react-native-worklets installed the views can
41
41
  # run `transform` / `onChangeText` worklets synchronously on the UI thread.
42
+ #
43
+ # Headers only, deliberately NOT linked: the bridge uses worklets' header-inline
44
+ # API and imports no symbol from libworklets.so (NDK links with --no-undefined,
45
+ # so if that ever changes the build fails here instead of misbehaving).
46
+ # Linking would add a DT_NEEDED on libworklets.so, and since NitroInput is a
47
+ # Nitro package (loaded at app start, ahead of most libraries) it would become
48
+ # the first library to load libworklets.so. On Android that changes which copy
49
+ # of worklets' weak RTTI (e.g. worklets::AsyncQueue) each library binds to, and
50
+ # react-native-vision-camera-worklets' frame-processor queue then fails worklets'
51
+ # dynamic_cast: null queue, SIGSEGV in WorkletRuntime::scheduleImpl.
42
52
  find_package(react-native-worklets CONFIG QUIET)
43
53
  if(react-native-worklets_FOUND)
44
54
  target_compile_definitions(${PACKAGE_NAME} PRIVATE NITRO_INPUT_WORKLETS=1)
45
- target_link_libraries(${PACKAGE_NAME} react-native-worklets::worklets)
55
+ target_include_directories(${PACKAGE_NAME} PRIVATE
56
+ $<TARGET_PROPERTY:react-native-worklets::worklets,INTERFACE_INCLUDE_DIRECTORIES>)
57
+ target_compile_definitions(${PACKAGE_NAME} PRIVATE
58
+ $<TARGET_PROPERTY:react-native-worklets::worklets,INTERFACE_COMPILE_DEFINITIONS>)
46
59
  message(STATUS "NitroInput: react-native-worklets found, worklet support enabled")
47
60
  else()
48
61
  message(STATUS "NitroInput: react-native-worklets not found, worklet support disabled")
@@ -532,12 +532,18 @@ class HybridNitroInputView(private val context: ThemedReactContext) : HybridNitr
532
532
  }
533
533
 
534
534
  /// A controlled `selection`; -1 on either end means "leave the caret alone".
535
+ /// Like `text`, dropped when it was rendered before JS saw the latest native
536
+ /// edits (React Native's `TextInput` does the same): typed faster than JS
537
+ /// renders, a caret computed for "1" landed in a field already showing
538
+ /// "1234", and the next digits went in behind the first one. An uncontrolled
539
+ /// field sends a count of 0 and is applied as before.
535
540
  private fun flushSelectionIfNeeded() {
536
541
  if (!selectionDirty) return
537
542
  selectionDirty = false
538
543
  val start = clampInt(selectionStart, -1, Int.MAX_VALUE, -1)
539
544
  val end = clampInt(selectionEnd, -1, Int.MAX_VALUE, -1)
540
545
  if (start < 0 || end < 0) return
546
+ if (mostRecentEventCount > 0 && mostRecentEventCount < eventCount) return
541
547
  inputView.setSelection(start, end)
542
548
  }
543
549
 
@@ -12,8 +12,10 @@
12
12
  #include <worklets/Compat/Holders.h>
13
13
  #include <worklets/WorkletRuntime/WorkletRuntime.h>
14
14
 
15
+ #include <cstring>
15
16
  #include <memory>
16
17
  #include <mutex>
18
+ #include <typeinfo>
17
19
 
18
20
  namespace margelo::nitro::nitroinput::nitroinputworklets {
19
21
 
@@ -72,8 +74,18 @@ bool installRuntime(Runtime& rt, const Value& holder) {
72
74
  if (!holder.isObject()) return false;
73
75
  Object object = holder.asObject(rt);
74
76
  if (!object.hasNativeState(rt)) return false;
75
- auto state = std::dynamic_pointer_cast<worklets::WorkletRuntimeHolder>(object.getNativeState(rt));
76
- if (!state || !state->runtime_) return false;
77
+ auto nativeState = object.getNativeState(rt);
78
+ // Not dynamic_cast: on Android each shared library can carry its own copy of
79
+ // an inline class's type_info, and libc++ compares them by address, so the
80
+ // cast fails whenever this library and libworklets.so bind different copies.
81
+ // Compare the mangled names instead (what worklets' own
82
+ // getWorkletRuntimeFromHolder trusts with a static cast).
83
+ if (!nativeState ||
84
+ std::strcmp(typeid(*nativeState).name(), typeid(worklets::WorkletRuntimeHolder).name()) != 0) {
85
+ return false;
86
+ }
87
+ auto state = std::static_pointer_cast<worklets::WorkletRuntimeHolder>(nativeState);
88
+ if (!state->runtime_) return false;
77
89
  std::lock_guard<std::mutex> lock(gMutex);
78
90
  gRuntime = state->runtime_;
79
91
  return true;
@@ -434,13 +434,21 @@ final class HybridNitroInputView: HybridNitroInputViewSpec, RecyclableView {
434
434
  }
435
435
 
436
436
  /// A controlled `selection`: `-1` on either end means "leave the caret alone",
437
- /// which is what an uncontrolled field sends on every render.
437
+ /// which is what an uncontrolled field sends on every render. Like `text`,
438
+ /// dropped when it was rendered before JS saw the latest native edits (React
439
+ /// Native's `TextInput` does the same): typed faster than JS renders, a caret
440
+ /// computed for "1" landed in a field already showing "1234". An
441
+ /// uncontrolled field sends a count of 0 and is applied as before.
438
442
  private func applySelectionIfNeeded() {
439
443
  guard selectionDirty else { return }
440
444
  selectionDirty = false
441
445
  let start = Self.clampInt(selectionStart, -1, Int(Int32.max), fallback: -1)
442
446
  let end = Self.clampInt(selectionEnd, -1, Int(Int32.max), fallback: -1)
443
447
  guard start >= 0, end >= 0 else { return }
448
+ snapshotLock.lock()
449
+ let nativeCount = snapshot.eventCount
450
+ snapshotLock.unlock()
451
+ if mostRecentEventCount.isFinite, mostRecentEventCount > 0, Int(mostRecentEventCount) < nativeCount { return }
444
452
  inputView.setSelection(start: start, end: end)
445
453
  }
446
454
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nitro-input",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
4
4
  "description": "Native text for React Native, built with Nitro: a text and amount input with native formatting, masks and a Torph-style reflow, and an animated number (odometer, SwiftUI-style numeric text, ticker) whose digits roll or swap natively, with currency layouts and animated currency switches, shrink-to-fit, a loading shimmer and a jackpot reveal.",
5
5
  "main": "lib/commonjs/src/index.js",
6
6
  "module": "lib/module/src/index.js",