react-native-nitro-input 0.1.0 → 0.2.0

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.
Files changed (116) hide show
  1. package/CHANGELOG.md +305 -3
  2. package/NitroInput.podspec +4 -4
  3. package/README.md +378 -53
  4. package/android/CMakeLists.txt +5 -3
  5. package/android/src/main/cpp/JOutlineGeometry.hpp +1 -1
  6. package/android/src/main/cpp/JReflowEngine.cpp +132 -0
  7. package/android/src/main/cpp/{JMorphEngine.hpp → JReflowEngine.hpp} +7 -7
  8. package/android/src/main/cpp/JRollingEngine.cpp +222 -0
  9. package/android/src/main/cpp/JRollingEngine.hpp +68 -0
  10. package/android/src/main/cpp/cpp-adapter.cpp +4 -2
  11. package/android/src/main/java/com/margelo/nitro/nitroinput/AmountFormatter.kt +1 -1
  12. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroInputView.kt +1 -1
  13. package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroNumberView.kt +471 -0
  14. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputPackage.kt +2 -1
  15. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputView.kt +38 -16
  16. package/android/src/main/java/com/margelo/nitro/nitroinput/NitroNumberView.kt +1741 -0
  17. package/android/src/main/java/com/margelo/nitro/nitroinput/{MorphEngine.kt → ReflowEngine.kt} +2 -2
  18. package/android/src/main/java/com/margelo/nitro/nitroinput/RollingEngine.kt +59 -0
  19. package/cpp/AmountFormatter.cpp +5 -0
  20. package/cpp/AmountFormatter.hpp +10 -2
  21. package/cpp/{MorphEngine.cpp → ReflowEngine.cpp} +52 -47
  22. package/cpp/{MorphEngine.hpp → ReflowEngine.hpp} +12 -4
  23. package/cpp/RollingEngine.cpp +1224 -0
  24. package/cpp/RollingEngine.hpp +468 -0
  25. package/cpp/SwiftNonCopyable.hpp +22 -0
  26. package/cpp/worklets/NitroInputWorkletsBridge.cpp +3 -3
  27. package/cpp/worklets/NitroInputWorkletsBridge.hpp +1 -1
  28. package/ios/{HybridMorphInputView.swift → HybridNitroInputView.swift} +1 -1
  29. package/ios/HybridNitroNumberView.swift +439 -0
  30. package/ios/NitroInputView.swift +69 -45
  31. package/ios/NitroNumberView.swift +1934 -0
  32. package/lib/commonjs/nitrogen/generated/shared/json/NitroNumberViewConfig.json +55 -0
  33. package/lib/commonjs/src/NitroInput.js +21 -52
  34. package/lib/commonjs/src/NitroNumber.js +139 -0
  35. package/lib/commonjs/src/index.js +4 -3
  36. package/lib/commonjs/src/specs/NitroNumber.nitro.js +2 -0
  37. package/lib/commonjs/src/styleHelpers.js +36 -0
  38. package/lib/module/nitrogen/generated/shared/json/NitroNumberViewConfig.json +55 -0
  39. package/lib/module/src/NitroInput.js +12 -43
  40. package/lib/module/src/NitroNumber.js +100 -0
  41. package/lib/module/src/index.js +1 -1
  42. package/lib/module/src/specs/NitroNumber.nitro.js +1 -0
  43. package/lib/module/src/styleHelpers.js +32 -0
  44. package/lib/typescript/src/NitroInput.d.ts +28 -21
  45. package/lib/typescript/src/NitroNumber.d.ts +211 -0
  46. package/lib/typescript/src/index.d.ts +3 -2
  47. package/lib/typescript/src/specs/NitroInput.nitro.d.ts +9 -9
  48. package/lib/typescript/src/specs/NitroNumber.nitro.d.ts +238 -0
  49. package/lib/typescript/src/styleHelpers.d.ts +3 -0
  50. package/nitro.json +10 -0
  51. package/nitrogen/generated/android/NitroInput+autolinking.cmake +4 -0
  52. package/nitrogen/generated/android/NitroInputOnLoad.cpp +20 -0
  53. package/nitrogen/generated/android/c++/JFunc_void.hpp +75 -0
  54. package/nitrogen/generated/android/c++/JFunc_void_double_double.hpp +10 -10
  55. package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.cpp +536 -0
  56. package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.hpp +156 -0
  57. package/nitrogen/generated/android/c++/JNitroNumberAffixAlign.hpp +64 -0
  58. package/nitrogen/generated/android/c++/JNitroNumberDirection.hpp +61 -0
  59. package/nitrogen/generated/android/c++/JNitroNumberEasing.hpp +67 -0
  60. package/nitrogen/generated/android/c++/JNitroNumberRevealStyle.hpp +58 -0
  61. package/nitrogen/generated/android/c++/JNitroNumberTextAlign.hpp +64 -0
  62. package/nitrogen/generated/android/c++/JNitroNumberTransition.hpp +61 -0
  63. package/nitrogen/generated/android/c++/views/JHybridNitroNumberViewStateUpdater.cpp +299 -0
  64. package/nitrogen/generated/android/c++/views/JHybridNitroNumberViewStateUpdater.hpp +54 -0
  65. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/Func_void.kt +78 -0
  66. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/Func_void_double_double.kt +9 -9
  67. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroNumberViewSpec.kt +363 -0
  68. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberAffixAlign.kt +25 -0
  69. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberDirection.kt +24 -0
  70. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberEasing.kt +26 -0
  71. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberRevealStyle.kt +23 -0
  72. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberTextAlign.kt +25 -0
  73. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberTransition.kt +24 -0
  74. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/views/HybridNitroNumberViewManager.kt +96 -0
  75. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/views/HybridNitroNumberViewStateUpdater.kt +23 -0
  76. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.cpp +25 -0
  77. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.hpp +248 -0
  78. package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Umbrella.hpp +23 -0
  79. package/nitrogen/generated/ios/NitroInputAutolinking.mm +8 -0
  80. package/nitrogen/generated/ios/NitroInputAutolinking.swift +12 -0
  81. package/nitrogen/generated/ios/c++/HybridNitroNumberViewSpecSwift.cpp +11 -0
  82. package/nitrogen/generated/ios/c++/HybridNitroNumberViewSpecSwift.hpp +432 -0
  83. package/nitrogen/generated/ios/c++/views/HybridNitroNumberViewComponent.mm +414 -0
  84. package/nitrogen/generated/ios/swift/Func_void.swift +46 -0
  85. package/nitrogen/generated/ios/swift/Func_void_double_double.swift +5 -5
  86. package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec.swift +102 -0
  87. package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec_cxx.swift +1243 -0
  88. package/nitrogen/generated/ios/swift/NitroNumberAffixAlign.swift +48 -0
  89. package/nitrogen/generated/ios/swift/NitroNumberDirection.swift +44 -0
  90. package/nitrogen/generated/ios/swift/NitroNumberEasing.swift +52 -0
  91. package/nitrogen/generated/ios/swift/NitroNumberRevealStyle.swift +40 -0
  92. package/nitrogen/generated/ios/swift/NitroNumberTextAlign.swift +48 -0
  93. package/nitrogen/generated/ios/swift/NitroNumberTransition.swift +44 -0
  94. package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.cpp +115 -0
  95. package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.hpp +175 -0
  96. package/nitrogen/generated/shared/c++/NitroNumberAffixAlign.hpp +84 -0
  97. package/nitrogen/generated/shared/c++/NitroNumberDirection.hpp +80 -0
  98. package/nitrogen/generated/shared/c++/NitroNumberEasing.hpp +88 -0
  99. package/nitrogen/generated/shared/c++/NitroNumberRevealStyle.hpp +76 -0
  100. package/nitrogen/generated/shared/c++/NitroNumberTextAlign.hpp +84 -0
  101. package/nitrogen/generated/shared/c++/NitroNumberTransition.hpp +80 -0
  102. package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.cpp +124 -0
  103. package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.hpp +227 -0
  104. package/nitrogen/generated/shared/json/NitroNumberViewConfig.json +55 -0
  105. package/package.json +15 -7
  106. package/src/NitroInput.tsx +37 -60
  107. package/src/NitroNumber.tsx +481 -0
  108. package/src/index.ts +20 -6
  109. package/src/specs/NitroInput.nitro.ts +9 -9
  110. package/src/specs/NitroNumber.nitro.ts +259 -0
  111. package/src/styleHelpers.ts +32 -0
  112. package/android/src/main/cpp/JMorphEngine.cpp +0 -132
  113. package/lib/commonjs/src/MorphInput.js +0 -42
  114. package/lib/module/src/MorphInput.js +0 -6
  115. package/lib/typescript/src/MorphInput.d.ts +0 -18
  116. package/src/MorphInput.tsx +0 -30
@@ -5,13 +5,13 @@ import com.facebook.jni.HybridData
5
5
  import com.facebook.proguard.annotations.DoNotStrip
6
6
 
7
7
  /**
8
- * Kotlin handle to the shared C++ [MorphEngine] (see `cpp/MorphEngine.hpp`).
8
+ * Kotlin handle to the shared C++ [ReflowEngine] (see `cpp/ReflowEngine.hpp`).
9
9
  * Times are in seconds, widths in whatever unit the caller lays out in (px here).
10
10
  * Roles: 0 prefix, 1 body, 2 suffix. Kinds: 0 text, 1 digit, 2 grouping, 3 decimal.
11
11
  */
12
12
  @Keep
13
13
  @DoNotStrip
14
- class MorphEngine {
14
+ class ReflowEngine {
15
15
  @DoNotStrip
16
16
  @Keep
17
17
  private val mHybridData: HybridData = initHybrid()
@@ -0,0 +1,59 @@
1
+ package com.margelo.nitro.nitroinput
2
+
3
+ import androidx.annotation.Keep
4
+ import com.facebook.jni.HybridData
5
+ import com.facebook.proguard.annotations.DoNotStrip
6
+
7
+ /**
8
+ * Kotlin handle to the shared C++ [RollingEngine] (see `cpp/RollingEngine.hpp`).
9
+ * Times are in seconds. See the C++ header for the semantics of each call.
10
+ */
11
+ @Keep
12
+ @DoNotStrip
13
+ class RollingEngine {
14
+ @DoNotStrip
15
+ @Keep
16
+ private val mHybridData: HybridData = initHybrid()
17
+
18
+ private external fun initHybrid(): HybridData
19
+
20
+ external fun setFormat(fractionDigits: Int, minimumIntegerDigits: Int)
21
+ external fun setTiming(durationSeconds: Double, easing: Int, bounce: Double, staggerSeconds: Double, direction: Int)
22
+ external fun setTransition(transition: Int)
23
+ external fun setFlash(seconds: Double)
24
+ external fun setPopOnChange(overshoot: Double)
25
+ external fun setReduceMotion(reduceMotion: Boolean)
26
+ /** A text slot (0 prefix, 1 suffix, 2 grouping, 3 decimal) changed; see `RollingEngine::changeText`. */
27
+ external fun changeText(slot: Int, now: Double)
28
+ /** `setFormat`, the change played; see `RollingEngine::changeFormat`. */
29
+ external fun changeFormat(fractionDigits: Int, minimumIntegerDigits: Int, now: Double)
30
+ external fun setValue(value: Double)
31
+ external fun animateTo(value: Double, now: Double)
32
+ external fun setLoading(loading: Boolean, now: Double)
33
+ external fun tick(now: Double): Boolean
34
+ external fun needsFrames(): Boolean
35
+ external fun isRolling(): Boolean
36
+ external fun reset()
37
+ external fun setRevealTiming(durationSeconds: Double, bounce: Double, style: Int, staggerSeconds: Double)
38
+ external fun setRevealGrow(grow: Double)
39
+ external fun holdReveal(value: Double)
40
+ external fun reveal(value: Double, now: Double)
41
+ external fun isRevealing(): Boolean
42
+ external fun clearRevealMilestones()
43
+ external fun addRevealMilestone(value: Double)
44
+ external fun setRevealMilestoneHold(holdSeconds: Double)
45
+ external fun revealMilestonesReached(): Int
46
+ external fun revealMilestoneValue(index: Int): Double
47
+ /**
48
+ * Fills [out] with the render state without allocating:
49
+ * `[signFactor, loadingProgress, revealScale, wheelCount, (position, width, linear, blankZero, fromGlyph, toGlyph, blend, fromAbove, flash, flashUp)…]`.
50
+ * Returns the number of doubles written, or -1 if [out] is too small.
51
+ */
52
+ external fun frameInto(out: DoubleArray): Int
53
+ external fun shimmerPhase(now: Double, periodSeconds: Double): Double
54
+ external fun targetValue(): Double
55
+ external fun hasShownValue(): Boolean
56
+ external fun settledPowerCount(): Int
57
+ external fun settledNegative(): Boolean
58
+ external fun targetDigit(power: Int): Int
59
+ }
@@ -44,6 +44,11 @@ bool AmountFormatter::takeSign(std::vector<uint32_t>& text) {
44
44
  }
45
45
 
46
46
  AmountFormatter::AmountFormatter() = default;
47
+ AmountFormatter::~AmountFormatter() = default;
48
+ AmountFormatter::AmountFormatter(const AmountFormatter&) = default;
49
+ AmountFormatter& AmountFormatter::operator=(const AmountFormatter&) = default;
50
+ AmountFormatter::AmountFormatter(AmountFormatter&&) noexcept = default;
51
+ AmountFormatter& AmountFormatter::operator=(AmountFormatter&&) noexcept = default;
47
52
 
48
53
  void AmountFormatter::setFormat(int fractionDigits, int maxIntegerDigits, const std::string& grouping, const std::string& decimal) {
49
54
  fractionDigits_ = std::clamp(fractionDigits, 0, 9);
@@ -17,9 +17,11 @@
17
17
  #include <string>
18
18
  #include <vector>
19
19
 
20
+ #include "SwiftNonCopyable.hpp"
21
+
20
22
  namespace margelo::nitro::nitroinput {
21
23
 
22
- class AmountFormatter final {
24
+ class SWIFT_NONCOPYABLE AmountFormatter final {
23
25
  public:
24
26
  struct Edit {
25
27
  std::string text;
@@ -29,6 +31,12 @@ public:
29
31
  };
30
32
 
31
33
  AmountFormatter();
34
+ // Defined in the .cpp (see SwiftNonCopyable.hpp).
35
+ ~AmountFormatter();
36
+ AmountFormatter(const AmountFormatter&);
37
+ AmountFormatter& operator=(const AmountFormatter&);
38
+ AmountFormatter(AmountFormatter&&) noexcept;
39
+ AmountFormatter& operator=(AmountFormatter&&) noexcept;
32
40
 
33
41
  /// `grouping` / `decimal`: one character each (UTF-8); empty grouping disables grouping.
34
42
  void setFormat(int fractionDigits, int maxIntegerDigits, const std::string& grouping, const std::string& decimal);
@@ -47,7 +55,7 @@ public:
47
55
  /// The numeric value of formatted text; NaN when there are no digits.
48
56
  double value(const std::string& formatted) const;
49
57
 
50
- /// MorphEngine::Kind of a character in formatted text.
58
+ /// ReflowEngine::Kind of a character in formatted text.
51
59
  int kindOf(uint32_t character) const;
52
60
  bool isGrouping(uint32_t character) const { return grouping_ != 0 && character == grouping_; }
53
61
  bool isDecimal(uint32_t character) const { return character == decimal_; }
@@ -1,9 +1,9 @@
1
1
  //
2
- // MorphEngine.cpp
2
+ // ReflowEngine.cpp
3
3
  // NitroInput
4
4
  //
5
5
 
6
- #include "MorphEngine.hpp"
6
+ #include "ReflowEngine.hpp"
7
7
 
8
8
  #include <algorithm>
9
9
  #include <cmath>
@@ -108,25 +108,30 @@ double ramp(double p, double from, double to) {
108
108
 
109
109
  } // namespace
110
110
 
111
- MorphEngine::MorphEngine() = default;
111
+ ReflowEngine::ReflowEngine() = default;
112
+ ReflowEngine::~ReflowEngine() = default;
113
+ ReflowEngine::ReflowEngine(const ReflowEngine&) = default;
114
+ ReflowEngine& ReflowEngine::operator=(const ReflowEngine&) = default;
115
+ ReflowEngine::ReflowEngine(ReflowEngine&&) noexcept = default;
116
+ ReflowEngine& ReflowEngine::operator=(ReflowEngine&&) noexcept = default;
112
117
 
113
118
  // MARK: - Configuration
114
119
 
115
- void MorphEngine::setTiming(double durationSeconds, int easing, double bounce) {
120
+ void ReflowEngine::setTiming(double durationSeconds, int easing, double bounce) {
116
121
  duration_ = std::max(0.0, durationSeconds);
117
122
  easing_ = easing;
118
123
  bounce_ = bounce;
119
124
  }
120
125
 
121
- void MorphEngine::setEffect(int effect) {
126
+ void ReflowEngine::setEffect(int effect) {
122
127
  effect_ = effect;
123
128
  }
124
129
 
125
- void MorphEngine::setReduceMotion(bool reduceMotion) {
130
+ void ReflowEngine::setReduceMotion(bool reduceMotion) {
126
131
  reduceMotion_ = reduceMotion;
127
132
  }
128
133
 
129
- double MorphEngine::ease(double t) const {
134
+ double ReflowEngine::ease(double t) const {
130
135
  t = clamp01(t);
131
136
  switch (easing_) {
132
137
  case 1: return 1 - std::pow(1 - t, 3);
@@ -137,18 +142,18 @@ double MorphEngine::ease(double t) const {
137
142
  }
138
143
  }
139
144
 
140
- bool MorphEngine::slides(int kind) const {
145
+ bool ReflowEngine::slides(int kind) const {
141
146
  if (effect_ == 1) return true;
142
147
  if (effect_ == 2) return false;
143
148
  return kind != Text;
144
149
  }
145
150
 
146
- bool MorphEngine::same(const Input& in, const Slot& slot) const {
151
+ bool ReflowEngine::same(const Input& in, const Slot& slot) const {
147
152
  return in.character == slot.g.character && in.kind == slot.g.kind && in.role == slot.g.role &&
148
153
  in.placeholder == slot.g.placeholder;
149
154
  }
150
155
 
151
- int MorphEngine::slotIndexOf(int64_t id) const {
156
+ int ReflowEngine::slotIndexOf(int64_t id) const {
152
157
  for (size_t i = 0; i < slots_.size(); ++i) {
153
158
  if (slots_[i].g.id == id) return static_cast<int>(i);
154
159
  }
@@ -157,15 +162,15 @@ int MorphEngine::slotIndexOf(int64_t id) const {
157
162
 
158
163
  // MARK: - Text
159
164
 
160
- void MorphEngine::beginText() {
165
+ void ReflowEngine::beginText() {
161
166
  pending_.clear();
162
167
  }
163
168
 
164
- void MorphEngine::addGlyph(uint32_t character, int role, int kind, double width, bool placeholder) {
169
+ void ReflowEngine::addGlyph(uint32_t character, int role, int kind, double width, bool placeholder) {
165
170
  pending_.push_back(Input{character, role, kind, std::max(0.0, width), placeholder});
166
171
  }
167
172
 
168
- void MorphEngine::snapTo(const std::vector<Input>& inputs) {
173
+ void ReflowEngine::snapTo(const std::vector<Input>& inputs) {
169
174
  slots_.clear();
170
175
  slots_.reserve(inputs.size());
171
176
  double x = 0;
@@ -186,11 +191,11 @@ void MorphEngine::snapTo(const std::vector<Input>& inputs) {
186
191
  /// disguise (a phone number, a date, an amount typed into a plain field: digits
187
192
  /// and punctuation, no letters) gets the number treatment instead, so its
188
193
  /// digits slide and its separators reflow like a formatted amount's.
189
- static void classifyNumericBody(std::vector<MorphEngine::Input>& inputs) {
194
+ static void classifyNumericBody(std::vector<ReflowEngine::Input>& inputs) {
190
195
  bool digits = false;
191
196
  for (const auto& in : inputs) {
192
- if (in.role != MorphEngine::Body) continue;
193
- if (in.kind != MorphEngine::Text) return; // already classified (number mode)
197
+ if (in.role != ReflowEngine::Body) continue;
198
+ if (in.kind != ReflowEngine::Text) return; // already classified (number mode)
194
199
  const uint32_t c = in.character;
195
200
  if (c >= '0' && c <= '9') {
196
201
  digits = true;
@@ -200,9 +205,9 @@ static void classifyNumericBody(std::vector<MorphEngine::Input>& inputs) {
200
205
  }
201
206
  if (!digits) return;
202
207
  for (auto& in : inputs) {
203
- if (in.role != MorphEngine::Body) continue;
208
+ if (in.role != ReflowEngine::Body) continue;
204
209
  const uint32_t c = in.character;
205
- in.kind = (c >= '0' && c <= '9') ? MorphEngine::Digit : MorphEngine::Separator;
210
+ in.kind = (c >= '0' && c <= '9') ? ReflowEngine::Digit : ReflowEngine::Separator;
206
211
  }
207
212
  // A lone '.' or ',' is the decimal point: the pivot the digits pair around,
208
213
  // part of the typed sequence like them, not a grouping separator that
@@ -214,25 +219,25 @@ static void classifyNumericBody(std::vector<MorphEngine::Input>& inputs) {
214
219
  // it occurs once: "192.168.0.1" and "21.09.2026" are structure.
215
220
  int decimal = -1;
216
221
  for (size_t i = 0; i < inputs.size(); ++i) {
217
- if (inputs[i].role != MorphEngine::Body) continue;
222
+ if (inputs[i].role != ReflowEngine::Body) continue;
218
223
  if (inputs[i].character == '.' || inputs[i].character == ',') decimal = static_cast<int>(i);
219
224
  }
220
225
  if (decimal < 0) return;
221
226
  int occurrences = 0;
222
227
  for (const auto& in : inputs) {
223
- if (in.role == MorphEngine::Body && in.character == inputs[static_cast<size_t>(decimal)].character) ++occurrences;
228
+ if (in.role == ReflowEngine::Body && in.character == inputs[static_cast<size_t>(decimal)].character) ++occurrences;
224
229
  }
225
- if (occurrences == 1) inputs[static_cast<size_t>(decimal)].kind = MorphEngine::Decimal;
230
+ if (occurrences == 1) inputs[static_cast<size_t>(decimal)].kind = ReflowEngine::Decimal;
226
231
  }
227
232
 
228
- void MorphEngine::commitText(int caretIndex, double now) {
233
+ void ReflowEngine::commitText(int caretIndex, double now) {
229
234
  now_ = now;
230
235
  std::vector<Input> inputs;
231
236
  inputs.swap(pending_);
232
237
  classifyNumericBody(inputs);
233
238
 
234
239
  // A placeholder is not a value: it is what the field shows instead of one.
235
- // Replacing it is a change of state rather than a morph, so the zero standing
240
+ // Replacing it is a change of state rather than a reflow, so the zero standing
236
241
  // in for an empty field does not roll into the digit that lands on it.
237
242
  const bool fromPlaceholder =
238
243
  std::any_of(slots_.begin(), slots_.end(), [](const Slot& s) { return !s.g.exiting && s.g.placeholder; });
@@ -468,7 +473,7 @@ void MorphEngine::commitText(int caretIndex, double now) {
468
473
 
469
474
  // MARK: - Matching
470
475
 
471
- void MorphEngine::matchBySequence(const std::vector<Input>& inputs, const std::vector<int>& oldIdx,
476
+ void ReflowEngine::matchBySequence(const std::vector<Input>& inputs, const std::vector<int>& oldIdx,
472
477
  const std::vector<int>& newIdx, std::vector<int>& matchOfNew) const {
473
478
  std::vector<std::pair<int, int>> pairs;
474
479
  lcsPairs(static_cast<int>(oldIdx.size()), static_cast<int>(newIdx.size()),
@@ -479,7 +484,7 @@ void MorphEngine::matchBySequence(const std::vector<Input>& inputs, const std::v
479
484
  }
480
485
  }
481
486
 
482
- void MorphEngine::matchBody(const std::vector<Input>& inputs, const std::vector<int>& oldBody,
487
+ void ReflowEngine::matchBody(const std::vector<Input>& inputs, const std::vector<int>& oldBody,
483
488
  const std::vector<int>& newBody, int caretIndex, std::vector<int>& matchOfNew) const {
484
489
  if (caretIndex >= 0) {
485
490
  matchByCaret(inputs, oldBody, newBody, caretIndex, matchOfNew);
@@ -499,7 +504,7 @@ void MorphEngine::matchBody(const std::vector<Input>& inputs, const std::vector<
499
504
  /// across by position. Grouping separators are left out of that walk (they
500
505
  /// reflow with the magnitude, not with the keystroke) and pair from the units
501
506
  /// end instead, so the thousands comma stays the thousands comma.
502
- void MorphEngine::matchByCaret(const std::vector<Input>& inputs, const std::vector<int>& oldBody,
507
+ void ReflowEngine::matchByCaret(const std::vector<Input>& inputs, const std::vector<int>& oldBody,
503
508
  const std::vector<int>& newBody, int caretIndex, std::vector<int>& matchOfNew) const {
504
509
  std::vector<int> keptOld, keptNew, sepOld, sepNew; // positions within the body lists
505
510
  for (size_t p = 0; p < oldBody.size(); ++p) {
@@ -588,7 +593,7 @@ void MorphEngine::matchByCaret(const std::vector<Input>& inputs, const std::vect
588
593
  /// identity is its column. When the integer part gained or lost columns the
589
594
  /// digits pair by subsequence from the units end instead, and the separators,
590
595
  /// which would have to cross them, leave.
591
- void MorphEngine::matchByPlace(const std::vector<Input>& inputs, const std::vector<int>& oldBody,
596
+ void ReflowEngine::matchByPlace(const std::vector<Input>& inputs, const std::vector<int>& oldBody,
592
597
  const std::vector<int>& newBody, std::vector<int>& matchOfNew) const {
593
598
  const int n = static_cast<int>(oldBody.size());
594
599
  const int m = static_cast<int>(newBody.size());
@@ -666,7 +671,7 @@ void MorphEngine::matchByPlace(const std::vector<Input>& inputs, const std::vect
666
671
 
667
672
  // MARK: - Frames
668
673
 
669
- bool MorphEngine::tick(double now) {
674
+ bool ReflowEngine::tick(double now) {
670
675
  now_ = now;
671
676
  if (!animating_) return false;
672
677
  bool moving = false;
@@ -720,13 +725,13 @@ bool MorphEngine::tick(double now) {
720
725
  return moving;
721
726
  }
722
727
 
723
- bool MorphEngine::needsFrames() const {
728
+ bool ReflowEngine::needsFrames() const {
724
729
  return animating_;
725
730
  }
726
731
 
727
732
  // MARK: - Render state
728
733
 
729
- int MorphEngine::bodyCount() const {
734
+ int ReflowEngine::bodyCount() const {
730
735
  int count = 0;
731
736
  for (const auto& s : slots_) {
732
737
  if (!s.g.exiting && s.g.role == Body) ++count;
@@ -771,34 +776,34 @@ struct Blocks {
771
776
  /// Right edge of the prefix's last ink, left edge of the suffix's first.
772
777
  double prefixInkEnd = 0;
773
778
  double suffixInkStart = 0;
774
- bool aheadOfPrefix(const MorphEngine::Glyph& g) const {
779
+ bool aheadOfPrefix(const ReflowEngine::Glyph& g) const {
775
780
  return wholePrefix.any && g.x + g.width <= wholePrefix.start + 1e-6;
776
781
  }
777
- bool prefixGapGlyph(const MorphEngine::Glyph& g) const {
778
- return g.role == MorphEngine::Prefix && isSpace(g.character) && g.x >= prefixInkEnd - 1e-6;
782
+ bool prefixGapGlyph(const ReflowEngine::Glyph& g) const {
783
+ return g.role == ReflowEngine::Prefix && isSpace(g.character) && g.x >= prefixInkEnd - 1e-6;
779
784
  }
780
- bool suffixGapGlyph(const MorphEngine::Glyph& g) const {
781
- return g.role == MorphEngine::Suffix && isSpace(g.character) && g.x + g.width <= suffixInkStart + 1e-6;
785
+ bool suffixGapGlyph(const ReflowEngine::Glyph& g) const {
786
+ return g.role == ReflowEngine::Suffix && isSpace(g.character) && g.x + g.width <= suffixInkStart + 1e-6;
782
787
  }
783
- const Block& of(const MorphEngine::Glyph& g) const {
784
- if (g.role == MorphEngine::Prefix) return prefixGapGlyph(g) ? prefixGap : prefix;
785
- if (g.role == MorphEngine::Suffix) return suffixGapGlyph(g) ? suffixGap : suffix;
788
+ const Block& of(const ReflowEngine::Glyph& g) const {
789
+ if (g.role == ReflowEngine::Prefix) return prefixGapGlyph(g) ? prefixGap : prefix;
790
+ if (g.role == ReflowEngine::Suffix) return suffixGapGlyph(g) ? suffixGap : suffix;
786
791
  return aheadOfPrefix(g) ? sign : rest;
787
792
  }
788
793
  };
789
794
 
790
- Blocks blocksOf(const std::vector<MorphEngine::Glyph>& glyphs) {
795
+ Blocks blocksOf(const std::vector<ReflowEngine::Glyph>& glyphs) {
791
796
  Blocks b;
792
797
  bool prefixInk = false;
793
798
  bool suffixInk = false;
794
799
  for (const auto& g : glyphs) {
795
- if (g.role == MorphEngine::Prefix) {
800
+ if (g.role == ReflowEngine::Prefix) {
796
801
  b.wholePrefix.add(g.x, g.width);
797
802
  if (!isSpace(g.character)) {
798
803
  b.prefixInkEnd = prefixInk ? std::max(b.prefixInkEnd, g.x + g.width) : g.x + g.width;
799
804
  prefixInk = true;
800
805
  }
801
- } else if (g.role == MorphEngine::Suffix && !isSpace(g.character)) {
806
+ } else if (g.role == ReflowEngine::Suffix && !isSpace(g.character)) {
802
807
  b.suffixInkStart = suffixInk ? std::min(b.suffixInkStart, g.x) : g.x;
803
808
  suffixInk = true;
804
809
  }
@@ -807,9 +812,9 @@ Blocks blocksOf(const std::vector<MorphEngine::Glyph>& glyphs) {
807
812
  if (!prefixInk) b.prefixInkEnd = b.wholePrefix.any ? b.wholePrefix.end : 0;
808
813
  if (!suffixInk) b.suffixInkStart = -1;
809
814
  for (const auto& g : glyphs) {
810
- if (g.role == MorphEngine::Prefix) {
815
+ if (g.role == ReflowEngine::Prefix) {
811
816
  (b.prefixGapGlyph(g) ? b.prefixGap : b.prefix).add(g.x, g.width);
812
- } else if (g.role == MorphEngine::Suffix) {
817
+ } else if (g.role == ReflowEngine::Suffix) {
813
818
  (b.suffixGapGlyph(g) ? b.suffixGap : b.suffix).add(g.x, g.width);
814
819
  } else if (b.aheadOfPrefix(g)) {
815
820
  b.sign.add(g.x, g.width);
@@ -834,7 +839,7 @@ double mirrored(double x, const Block& block, double total) {
834
839
  // mirror image would be and keeps its own order inside. `slots_` stay
835
840
  // left-to-right - the matching, the caret and the animation all reason there -
836
841
  // and only the published frames move.
837
- void MorphEngine::publish() {
842
+ void ReflowEngine::publish() {
838
843
  glyphs_.clear();
839
844
  glyphs_.reserve(slots_.size());
840
845
  for (const auto& s : slots_) glyphs_.push_back(s.g);
@@ -855,13 +860,13 @@ void MorphEngine::publish() {
855
860
  caretBlocks_.rest = Extent{live.rest.start, live.rest.end, live.rest.any};
856
861
  }
857
862
 
858
- void MorphEngine::setRightToLeft(bool rightToLeft) {
863
+ void ReflowEngine::setRightToLeft(bool rightToLeft) {
859
864
  if (rightToLeft_ == rightToLeft) return;
860
865
  rightToLeft_ = rightToLeft;
861
866
  publish();
862
867
  }
863
868
 
864
- double MorphEngine::caretX(int index) const {
869
+ double ReflowEngine::caretX(int index) const {
865
870
  int seen = 0;
866
871
  double afterPrefix = 0;
867
872
  double afterLast = -1;
@@ -887,7 +892,7 @@ double MorphEngine::caretX(int index) const {
887
892
  return contentWidth_ - block.end + (x - block.start);
888
893
  }
889
894
 
890
- void MorphEngine::reset() {
895
+ void ReflowEngine::reset() {
891
896
  duration_ = 0.4;
892
897
  easing_ = 0;
893
898
  bounce_ = 0.15;
@@ -1,8 +1,8 @@
1
1
  //
2
- // MorphEngine.hpp
2
+ // ReflowEngine.hpp
3
3
  // NitroInput
4
4
  //
5
- // The platform-independent text-morph state machine behind the input view.
5
+ // The platform-independent text-reflow state machine behind the input view.
6
6
  // Both native views (NitroInputView.swift, NitroInputView.kt) hand it the new
7
7
  // text as a list of glyphs (character, role, kind, advance width) plus where
8
8
  // the edit happened, and draw whatever it reports: one glyph per character
@@ -26,9 +26,11 @@
26
26
  #include <cstdint>
27
27
  #include <vector>
28
28
 
29
+ #include "SwiftNonCopyable.hpp"
30
+
29
31
  namespace margelo::nitro::nitroinput {
30
32
 
31
- class MorphEngine final {
33
+ class SWIFT_NONCOPYABLE ReflowEngine final {
32
34
  public:
33
35
  /// What a character is; decides how it enters, leaves and is matched.
34
36
  enum Kind : int {
@@ -76,7 +78,13 @@ public:
76
78
  bool placeholder;
77
79
  };
78
80
 
79
- MorphEngine();
81
+ ReflowEngine();
82
+ // Defined in the .cpp (see SwiftNonCopyable.hpp).
83
+ ~ReflowEngine();
84
+ ReflowEngine(const ReflowEngine&);
85
+ ReflowEngine& operator=(const ReflowEngine&);
86
+ ReflowEngine(ReflowEngine&&) noexcept;
87
+ ReflowEngine& operator=(ReflowEngine&&) noexcept;
80
88
 
81
89
  // MARK: Configuration
82
90