react-native-nitro-input 0.3.0 → 0.3.2
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 +80 -0
- package/README.md +120 -5
- package/android/src/main/cpp/JMaskEngine.cpp +45 -0
- package/android/src/main/cpp/JMaskEngine.hpp +9 -0
- package/android/src/main/cpp/JReflowEngine.cpp +32 -0
- package/android/src/main/cpp/JReflowEngine.hpp +13 -0
- package/android/src/main/cpp/JRollingEngine.cpp +42 -2
- package/android/src/main/cpp/JRollingEngine.hpp +9 -1
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroInputView.kt +24 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroNumberFormatPlatform.kt +76 -1
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroNumberView.kt +88 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroTextMeasure.kt +25 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroTextView.kt +140 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/MaskEngine.kt +16 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputPackage.kt +2 -1
- package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputView.kt +96 -6
- package/android/src/main/java/com/margelo/nitro/nitroinput/NitroNumberView.kt +388 -136
- package/android/src/main/java/com/margelo/nitro/nitroinput/NitroTextView.kt +868 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/ReflowEngine.kt +21 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/RollingEngine.kt +13 -2
- package/cpp/MaskEngine.cpp +294 -33
- package/cpp/MaskEngine.hpp +68 -0
- package/cpp/RollingEngine.cpp +92 -8
- package/cpp/RollingEngine.hpp +36 -2
- package/ios/HybridNitroInputView.swift +18 -0
- package/ios/HybridNitroNumberFormatPlatform.swift +87 -9
- package/ios/HybridNitroNumberView.swift +82 -1
- package/ios/HybridNitroTextView.swift +134 -0
- package/ios/NitroInputView.swift +125 -7
- package/ios/NitroNumberView.swift +368 -135
- package/ios/NitroTextView.swift +583 -0
- package/lib/commonjs/nitrogen/generated/shared/json/NitroInputViewConfig.json +6 -0
- package/lib/commonjs/nitrogen/generated/shared/json/NitroNumberViewConfig.json +20 -0
- package/lib/commonjs/nitrogen/generated/shared/json/NitroTextViewConfig.json +30 -0
- package/lib/commonjs/src/NitroInput.js +15 -2
- package/lib/commonjs/src/NitroNumber.js +52 -3
- package/lib/commonjs/src/NitroText.js +138 -0
- package/lib/commonjs/src/NitroTime.js +65 -0
- package/lib/commonjs/src/formatProps.js +76 -16
- package/lib/commonjs/src/index.js +6 -1
- package/lib/commonjs/src/specs/NitroText.nitro.js +2 -0
- package/lib/module/nitrogen/generated/shared/json/NitroInputViewConfig.json +6 -0
- package/lib/module/nitrogen/generated/shared/json/NitroNumberViewConfig.json +20 -0
- package/lib/module/nitrogen/generated/shared/json/NitroTextViewConfig.json +30 -0
- package/lib/module/src/NitroInput.js +15 -2
- package/lib/module/src/NitroNumber.js +53 -4
- package/lib/module/src/NitroText.js +98 -0
- package/lib/module/src/NitroTime.js +29 -0
- package/lib/module/src/formatProps.js +76 -17
- package/lib/module/src/index.js +2 -0
- package/lib/module/src/specs/NitroText.nitro.js +1 -0
- package/lib/typescript/src/NitroInput.d.ts +39 -1
- package/lib/typescript/src/NitroNumber.d.ts +79 -1
- package/lib/typescript/src/NitroText.d.ts +67 -0
- package/lib/typescript/src/NitroTime.d.ts +19 -0
- package/lib/typescript/src/formatProps.d.ts +30 -4
- package/lib/typescript/src/index.d.ts +5 -2
- package/lib/typescript/src/specs/NitroInput.nitro.d.ts +43 -0
- package/lib/typescript/src/specs/NitroNumber.nitro.d.ts +67 -0
- package/lib/typescript/src/specs/NitroText.nitro.d.ts +60 -0
- package/nitro.json +20 -0
- package/nitrogen/generated/android/NitroInput+autolinking.cmake +6 -0
- package/nitrogen/generated/android/NitroInputOnLoad.cpp +34 -0
- package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.cpp +102 -0
- package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.hpp +12 -0
- package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.cpp +243 -0
- package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.hpp +40 -0
- package/nitrogen/generated/android/c++/JHybridNitroTextMeasureSpec.cpp +58 -0
- package/nitrogen/generated/android/c++/JHybridNitroTextMeasureSpec.hpp +64 -0
- package/nitrogen/generated/android/c++/JHybridNitroTextViewSpec.cpp +253 -0
- package/nitrogen/generated/android/c++/JHybridNitroTextViewSpec.hpp +104 -0
- package/nitrogen/generated/android/c++/JNitroInputCharacterMapping.hpp +61 -0
- package/nitrogen/generated/android/c++/JNitroInputMaskAffinity.hpp +64 -0
- package/nitrogen/generated/android/c++/JNitroInputTextCase.hpp +61 -0
- package/nitrogen/generated/android/c++/JNitroNumberShimmerDirection.hpp +61 -0
- package/nitrogen/generated/android/c++/JNitroNumberSignDisplay.hpp +67 -0
- package/nitrogen/generated/android/c++/views/JHybridNitroInputViewStateUpdater.cpp +30 -0
- package/nitrogen/generated/android/c++/views/JHybridNitroNumberViewStateUpdater.cpp +100 -0
- package/nitrogen/generated/android/c++/views/JHybridNitroTextViewStateUpdater.cpp +174 -0
- package/nitrogen/generated/android/c++/views/JHybridNitroTextViewStateUpdater.hpp +54 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroInputViewSpec.kt +36 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroNumberViewSpec.kt +136 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroTextMeasureSpec.kt +60 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroTextViewSpec.kt +179 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputCharacterMapping.kt +56 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputMaskAffinity.kt +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroInputTextCase.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberShimmerDirection.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberSignDisplay.kt +26 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/views/HybridNitroTextViewManager.kt +96 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/views/HybridNitroTextViewStateUpdater.kt +23 -0
- package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.cpp +34 -0
- package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.hpp +146 -11
- package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Umbrella.hpp +25 -0
- package/nitrogen/generated/ios/NitroInputAutolinking.mm +16 -0
- package/nitrogen/generated/ios/NitroInputAutolinking.swift +24 -0
- package/nitrogen/generated/ios/c++/HybridNitroInputViewSpecSwift.hpp +50 -0
- package/nitrogen/generated/ios/c++/HybridNitroNumberViewSpecSwift.hpp +146 -0
- package/nitrogen/generated/ios/c++/HybridNitroTextMeasureSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNitroTextMeasureSpecSwift.hpp +90 -0
- package/nitrogen/generated/ios/c++/HybridNitroTextViewSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNitroTextViewSpecSwift.hpp +233 -0
- package/nitrogen/generated/ios/c++/views/HybridNitroInputViewComponent.mm +36 -0
- package/nitrogen/generated/ios/c++/views/HybridNitroNumberViewComponent.mm +120 -0
- package/nitrogen/generated/ios/c++/views/HybridNitroTextViewComponent.mm +264 -0
- package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec.swift +6 -0
- package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec_cxx.swift +78 -0
- package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec.swift +20 -0
- package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec_cxx.swift +493 -0
- package/nitrogen/generated/ios/swift/HybridNitroTextMeasureSpec.swift +56 -0
- package/nitrogen/generated/ios/swift/HybridNitroTextMeasureSpec_cxx.swift +150 -0
- package/nitrogen/generated/ios/swift/HybridNitroTextViewSpec.swift +75 -0
- package/nitrogen/generated/ios/swift/HybridNitroTextViewSpec_cxx.swift +608 -0
- package/nitrogen/generated/ios/swift/NitroInputCharacterMapping.swift +34 -0
- package/nitrogen/generated/ios/swift/NitroInputMaskAffinity.swift +48 -0
- package/nitrogen/generated/ios/swift/NitroInputTextCase.swift +44 -0
- package/nitrogen/generated/ios/swift/NitroNumberShimmerDirection.swift +44 -0
- package/nitrogen/generated/ios/swift/NitroNumberSignDisplay.swift +52 -0
- package/nitrogen/generated/shared/c++/HybridNitroInputViewSpec.cpp +12 -0
- package/nitrogen/generated/shared/c++/HybridNitroInputViewSpec.hpp +21 -0
- package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.cpp +40 -0
- package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.hpp +46 -0
- package/nitrogen/generated/shared/c++/HybridNitroTextMeasureSpec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridNitroTextMeasureSpec.hpp +63 -0
- package/nitrogen/generated/shared/c++/HybridNitroTextViewSpec.cpp +62 -0
- package/nitrogen/generated/shared/c++/HybridNitroTextViewSpec.hpp +115 -0
- package/nitrogen/generated/shared/c++/NitroInputCharacterMapping.hpp +87 -0
- package/nitrogen/generated/shared/c++/NitroInputMaskAffinity.hpp +84 -0
- package/nitrogen/generated/shared/c++/NitroInputTextCase.hpp +80 -0
- package/nitrogen/generated/shared/c++/NitroNumberShimmerDirection.hpp +80 -0
- package/nitrogen/generated/shared/c++/NitroNumberSignDisplay.hpp +88 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.cpp +12 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.hpp +21 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.cpp +40 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.hpp +62 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroTextViewComponent.cpp +74 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroTextViewComponent.hpp +149 -0
- package/nitrogen/generated/shared/json/NitroInputViewConfig.json +6 -0
- package/nitrogen/generated/shared/json/NitroNumberViewConfig.json +20 -0
- package/nitrogen/generated/shared/json/NitroTextViewConfig.json +30 -0
- package/package.json +2 -2
- package/src/NitroInput.tsx +73 -0
- package/src/NitroNumber.tsx +183 -9
- package/src/NitroText.tsx +166 -0
- package/src/NitroTime.tsx +68 -0
- package/src/formatProps.ts +108 -18
- package/src/index.ts +8 -0
- package/src/specs/NitroInput.nitro.ts +46 -0
- package/src/specs/NitroNumber.nitro.ts +69 -0
- package/src/specs/NitroText.nitro.ts +65 -0
package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroNumberFormatPlatform.kt
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
package com.margelo.nitro.nitroinput
|
|
2
2
|
|
|
3
|
+
import android.icu.number.LocalizedNumberFormatter
|
|
4
|
+
import android.icu.number.Notation
|
|
5
|
+
import android.icu.number.NumberFormatter
|
|
6
|
+
import android.icu.number.Precision
|
|
7
|
+
import android.icu.number.Scale
|
|
3
8
|
import android.icu.text.CompactDecimalFormat
|
|
4
9
|
import android.icu.text.DecimalFormat
|
|
5
10
|
import android.icu.text.DecimalFormatSymbols
|
|
@@ -71,6 +76,13 @@ class HybridNitroPlatformNumberFormatter(o: NumberFormatPlatformOptions) : Hybri
|
|
|
71
76
|
private val measureFormat: MeasureFormat?
|
|
72
77
|
/** `unit: 'percent'`, which MeasureFormat prints without its sign: a percent formatter that does not multiply. */
|
|
73
78
|
private val percentUnit: NumberFormat?
|
|
79
|
+
/**
|
|
80
|
+
* Compact notation with a currency or a percent, or a signDisplay plus:
|
|
81
|
+
* CompactDecimalFormat prints bare numbers ("1.5K" for "$1.5K"). Android 11+
|
|
82
|
+
* has ICU's number formatter, which prints the locale's compact patterns;
|
|
83
|
+
* before it, the compact number goes inside the style's own affixes.
|
|
84
|
+
*/
|
|
85
|
+
private val compact: ((BigDecimal) -> String)?
|
|
74
86
|
override val symbols: NumberFormatPlatformSymbols
|
|
75
87
|
|
|
76
88
|
init {
|
|
@@ -84,7 +96,7 @@ class HybridNitroPlatformNumberFormatter(o: NumberFormatPlatformOptions) : Hybri
|
|
|
84
96
|
else -> if (o.currencySign == NumberFormatCurrencySign.ACCOUNTING) NumberFormat.ACCOUNTINGCURRENCYSTYLE else NumberFormat.CURRENCYSTYLE
|
|
85
97
|
}
|
|
86
98
|
format = when {
|
|
87
|
-
o.notation == NumberFormatNotation.COMPACT
|
|
99
|
+
o.notation == NumberFormatNotation.COMPACT -> CompactDecimalFormat.getInstance(
|
|
88
100
|
locale,
|
|
89
101
|
if (o.compactDisplay == NumberFormatCompactDisplay.LONG) CompactDecimalFormat.CompactStyle.LONG else CompactDecimalFormat.CompactStyle.SHORT,
|
|
90
102
|
)
|
|
@@ -141,6 +153,26 @@ class HybridNitroPlatformNumberFormatter(o: NumberFormatPlatformOptions) : Hybri
|
|
|
141
153
|
}
|
|
142
154
|
}
|
|
143
155
|
|
|
156
|
+
compact = if (o.notation != NumberFormatNotation.COMPACT) {
|
|
157
|
+
null
|
|
158
|
+
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
159
|
+
modernCompact(o, locale)
|
|
160
|
+
} else if (o.style == NumberFormatStyle.CURRENCY || o.style == NumberFormatStyle.PERCENT) {
|
|
161
|
+
// The style's own pattern around the compact number: "$" + "1.5K", "1.2M" + "%".
|
|
162
|
+
val pattern = NumberFormat.getInstance(locale, if (o.style == NumberFormatStyle.PERCENT) NumberFormat.PERCENTSTYLE else currencyStyle) as DecimalFormat
|
|
163
|
+
if (o.style == NumberFormatStyle.CURRENCY && code != null) pattern.currency = Currency.getInstance(code)
|
|
164
|
+
val plus = o.signDisplay == NumberFormatSignDisplay.ALWAYS || o.signDisplay == NumberFormatSignDisplay.EXCEPTZERO
|
|
165
|
+
val positivePrefix = (if (plus) pattern.decimalFormatSymbols.plusSign.toString() else "") + pattern.positivePrefix
|
|
166
|
+
val scale = if (o.style == NumberFormatStyle.PERCENT) 100 else 1
|
|
167
|
+
val number = format
|
|
168
|
+
{ value ->
|
|
169
|
+
val body = number.format(value.abs().multiply(BigDecimal(scale)))
|
|
170
|
+
if (value.signum() < 0) pattern.negativePrefix + body + pattern.negativeSuffix else positivePrefix + body + pattern.positiveSuffix
|
|
171
|
+
}
|
|
172
|
+
} else {
|
|
173
|
+
null
|
|
174
|
+
}
|
|
175
|
+
|
|
144
176
|
if (o.style == NumberFormatStyle.UNIT && o.unit == "percent") {
|
|
145
177
|
percentUnit = (NumberFormat.getInstance(locale, NumberFormat.PERCENTSTYLE) as DecimalFormat).also { p ->
|
|
146
178
|
p.multiplier = 1
|
|
@@ -192,6 +224,7 @@ class HybridNitroPlatformNumberFormatter(o: NumberFormatPlatformOptions) : Hybri
|
|
|
192
224
|
|
|
193
225
|
@Synchronized
|
|
194
226
|
override fun format(value: Double): String {
|
|
227
|
+
compact?.let { if (value.isFinite()) return it(BigDecimal(value)) }
|
|
195
228
|
percentUnit?.let { return it.format(value) }
|
|
196
229
|
val measure = measureFormat
|
|
197
230
|
return if (measure != null) measure.format(Measure(value, unit)) else format.format(value)
|
|
@@ -202,8 +235,50 @@ class HybridNitroPlatformNumberFormatter(o: NumberFormatPlatformOptions) : Hybri
|
|
|
202
235
|
if (value == "NaN") return format(Double.NaN)
|
|
203
236
|
if (value.endsWith("Infinity")) return format(if (value.startsWith("-")) Double.NEGATIVE_INFINITY else Double.POSITIVE_INFINITY)
|
|
204
237
|
val number = BigDecimal(value)
|
|
238
|
+
compact?.let { return it(number) }
|
|
205
239
|
percentUnit?.let { return it.format(number) }
|
|
206
240
|
val measure = measureFormat
|
|
207
241
|
return if (measure != null) measure.format(Measure(number, unit)) else format.format(number)
|
|
208
242
|
}
|
|
243
|
+
|
|
244
|
+
private companion object {
|
|
245
|
+
/** ICU's number formatter (Android 11+): compact currency, percent and signs as CLDR writes them. */
|
|
246
|
+
@androidx.annotation.RequiresApi(Build.VERSION_CODES.R)
|
|
247
|
+
fun modernCompact(o: NumberFormatPlatformOptions, locale: ULocale): (BigDecimal) -> String {
|
|
248
|
+
var f: LocalizedNumberFormatter = NumberFormatter.withLocale(locale)
|
|
249
|
+
.notation(if (o.compactDisplay == NumberFormatCompactDisplay.LONG) Notation.compactLong() else Notation.compactShort())
|
|
250
|
+
// Compact numbers group from five digits ("9876", "12,345"): ECMA-402's
|
|
251
|
+
// default for compact notation is "min2", which is what this receives as true.
|
|
252
|
+
.grouping(if (o.useGrouping) NumberFormatter.GroupingStrategy.MIN2 else NumberFormatter.GroupingStrategy.OFF)
|
|
253
|
+
f = if (o.minimumSignificantDigits > 0) {
|
|
254
|
+
f.precision(Precision.minMaxSignificantDigits(o.minimumSignificantDigits.toInt(), o.maximumSignificantDigits.toInt()))
|
|
255
|
+
} else {
|
|
256
|
+
f.precision(Precision.minMaxFraction(o.minimumFractionDigits.toInt(), o.maximumFractionDigits.toInt()))
|
|
257
|
+
}
|
|
258
|
+
val code = o.currency
|
|
259
|
+
if (o.style == NumberFormatStyle.CURRENCY && code != null) {
|
|
260
|
+
f = f.unit(Currency.getInstance(code)).unitWidth(
|
|
261
|
+
when (o.currencyDisplay) {
|
|
262
|
+
NumberFormatCurrencyDisplay.CODE -> NumberFormatter.UnitWidth.ISO_CODE
|
|
263
|
+
NumberFormatCurrencyDisplay.NAME -> NumberFormatter.UnitWidth.FULL_NAME
|
|
264
|
+
NumberFormatCurrencyDisplay.NARROWSYMBOL -> NumberFormatter.UnitWidth.NARROW
|
|
265
|
+
else -> NumberFormatter.UnitWidth.SHORT
|
|
266
|
+
}
|
|
267
|
+
)
|
|
268
|
+
} else if (o.style == NumberFormatStyle.PERCENT) {
|
|
269
|
+
f = f.unit(MeasureUnit.PERCENT).scale(Scale.powerOfTen(2))
|
|
270
|
+
}
|
|
271
|
+
val accounting = o.currencySign == NumberFormatCurrencySign.ACCOUNTING
|
|
272
|
+
f = f.sign(
|
|
273
|
+
when (o.signDisplay) {
|
|
274
|
+
NumberFormatSignDisplay.ALWAYS -> if (accounting) NumberFormatter.SignDisplay.ACCOUNTING_ALWAYS else NumberFormatter.SignDisplay.ALWAYS
|
|
275
|
+
NumberFormatSignDisplay.EXCEPTZERO -> if (accounting) NumberFormatter.SignDisplay.ACCOUNTING_EXCEPT_ZERO else NumberFormatter.SignDisplay.EXCEPT_ZERO
|
|
276
|
+
NumberFormatSignDisplay.NEVER -> NumberFormatter.SignDisplay.NEVER
|
|
277
|
+
else -> if (accounting) NumberFormatter.SignDisplay.ACCOUNTING else NumberFormatter.SignDisplay.AUTO
|
|
278
|
+
}
|
|
279
|
+
)
|
|
280
|
+
val formatter = f
|
|
281
|
+
return { value -> formatter.format(value).toString() }
|
|
282
|
+
}
|
|
283
|
+
}
|
|
209
284
|
}
|
|
@@ -52,6 +52,8 @@ class HybridNitroNumberView(private val context: ThemedReactContext) : HybridNit
|
|
|
52
52
|
}
|
|
53
53
|
rollingView.onRevealEnd = { onRevealEnd?.invoke() }
|
|
54
54
|
rollingView.onRevealMilestone = { index, milestone -> onRevealMilestone?.invoke(index.toDouble(), milestone) }
|
|
55
|
+
rollingView.onAnimationStart = { onAnimationStart?.invoke() }
|
|
56
|
+
rollingView.onAnimationEnd = { value -> onAnimationEnd?.invoke(value) }
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
// region Props
|
|
@@ -129,6 +131,16 @@ class HybridNitroNumberView(private val context: ThemedReactContext) : HybridNit
|
|
|
129
131
|
set(v) { field = v; markConfigDirty() }
|
|
130
132
|
override var shimmerDuration: Double? = null
|
|
131
133
|
set(v) { field = v; markConfigDirty() }
|
|
134
|
+
override var shimmerAngle: Double? = null
|
|
135
|
+
set(v) { field = v; markConfigDirty() }
|
|
136
|
+
override var shimmerWidth: Double? = null
|
|
137
|
+
set(v) { field = v; markConfigDirty() }
|
|
138
|
+
override var shimmerBaseColor: Double? = null
|
|
139
|
+
set(v) { field = v; markConfigDirty() }
|
|
140
|
+
override var shimmerDirection: NitroNumberShimmerDirection? = null
|
|
141
|
+
set(v) { field = v; markConfigDirty() }
|
|
142
|
+
override var shimmerDelay: Double? = null
|
|
143
|
+
set(v) { field = v; markConfigDirty() }
|
|
132
144
|
override var fontSize: Double? = null
|
|
133
145
|
set(v) { field = v; markConfigDirty() }
|
|
134
146
|
override var prefixFontSize: Double? = null
|
|
@@ -153,6 +165,34 @@ class HybridNitroNumberView(private val context: ThemedReactContext) : HybridNit
|
|
|
153
165
|
set(v) { field = v; markConfigDirty() }
|
|
154
166
|
override var tabularNums: Boolean? = null
|
|
155
167
|
set(v) { field = v; markConfigDirty() }
|
|
168
|
+
override var signDisplay: NitroNumberSignDisplay? = null
|
|
169
|
+
set(v) { field = v; markConfigDirty() }
|
|
170
|
+
override var plusSign: String? = null
|
|
171
|
+
set(v) { field = v; markConfigDirty() }
|
|
172
|
+
override var minusSign: String? = null
|
|
173
|
+
set(v) { field = v; markConfigDirty() }
|
|
174
|
+
override var digitGlyphs: Array<String>? = null
|
|
175
|
+
set(v) { field = v; markConfigDirty() }
|
|
176
|
+
override var groupingSizes: DoubleArray? = null
|
|
177
|
+
set(v) { field = v; markConfigDirty() }
|
|
178
|
+
override var digitMax: DoubleArray? = null
|
|
179
|
+
set(v) { field = v; markConfigDirty() }
|
|
180
|
+
override var continuous: Boolean? = null
|
|
181
|
+
set(v) { field = v; markConfigDirty() }
|
|
182
|
+
override var prefixColor: Double? = null
|
|
183
|
+
set(v) { field = v; markConfigDirty() }
|
|
184
|
+
override var suffixColor: Double? = null
|
|
185
|
+
set(v) { field = v; markConfigDirty() }
|
|
186
|
+
override var fractionColor: Double? = null
|
|
187
|
+
set(v) { field = v; markConfigDirty() }
|
|
188
|
+
override var fractionFontSize: Double? = null
|
|
189
|
+
set(v) { field = v; markConfigDirty() }
|
|
190
|
+
override var fractionAlign: NitroNumberAffixAlign? = null
|
|
191
|
+
set(v) { field = v; markConfigDirty() }
|
|
192
|
+
override var respectReduceMotion: Boolean? = null
|
|
193
|
+
set(v) { field = v; markConfigDirty() }
|
|
194
|
+
override var onAnimationStart: (() -> Unit)? = null
|
|
195
|
+
override var onAnimationEnd: ((value: Double) -> Unit)? = null
|
|
156
196
|
override var adjustsFontSizeToFit: Boolean? = null
|
|
157
197
|
set(v) { field = v; markConfigDirty() }
|
|
158
198
|
override var minimumFontScale: Double? = null
|
|
@@ -315,6 +355,11 @@ class HybridNitroNumberView(private val context: ThemedReactContext) : HybridNit
|
|
|
315
355
|
loading = null
|
|
316
356
|
shimmerColor = null
|
|
317
357
|
shimmerDuration = null
|
|
358
|
+
shimmerAngle = null
|
|
359
|
+
shimmerWidth = null
|
|
360
|
+
shimmerBaseColor = null
|
|
361
|
+
shimmerDirection = null
|
|
362
|
+
shimmerDelay = null
|
|
318
363
|
fontSize = null
|
|
319
364
|
prefixFontSize = null
|
|
320
365
|
suffixFontSize = null
|
|
@@ -327,6 +372,21 @@ class HybridNitroNumberView(private val context: ThemedReactContext) : HybridNit
|
|
|
327
372
|
prefixOffset = null
|
|
328
373
|
suffixOffset = null
|
|
329
374
|
tabularNums = null
|
|
375
|
+
signDisplay = null
|
|
376
|
+
plusSign = null
|
|
377
|
+
minusSign = null
|
|
378
|
+
digitGlyphs = null
|
|
379
|
+
groupingSizes = null
|
|
380
|
+
digitMax = null
|
|
381
|
+
continuous = null
|
|
382
|
+
prefixColor = null
|
|
383
|
+
suffixColor = null
|
|
384
|
+
fractionColor = null
|
|
385
|
+
fractionFontSize = null
|
|
386
|
+
fractionAlign = null
|
|
387
|
+
respectReduceMotion = null
|
|
388
|
+
onAnimationStart = null
|
|
389
|
+
onAnimationEnd = null
|
|
330
390
|
adjustsFontSizeToFit = null
|
|
331
391
|
minimumFontScale = null
|
|
332
392
|
allowFontScaling = null
|
|
@@ -401,6 +461,12 @@ class HybridNitroNumberView(private val context: ThemedReactContext) : HybridNit
|
|
|
401
461
|
prefixOffset = (prefixOffset ?: 0.0).takeIf { it.isFinite() }?.toFloat() ?: 0f,
|
|
402
462
|
suffixOffset = (suffixOffset ?: 0.0).takeIf { it.isFinite() }?.toFloat() ?: 0f,
|
|
403
463
|
tabularNums = tabularNums ?: true,
|
|
464
|
+
prefixColor = prefixColor?.let { colorFromARGB(it) },
|
|
465
|
+
suffixColor = suffixColor?.let { colorFromARGB(it) },
|
|
466
|
+
fractionColor = fractionColor?.let { colorFromARGB(it) },
|
|
467
|
+
fractionFontSize = fractionFontSize?.takeIf { it.isFinite() && it > 0 }?.toFloat(),
|
|
468
|
+
fractionAlign = mapAffixAlign(fractionAlign),
|
|
469
|
+
digitGlyphs = digitGlyphs?.toList() ?: emptyList(),
|
|
404
470
|
adjustsFontSizeToFit = adjustsFontSizeToFit ?: false,
|
|
405
471
|
minimumFontScale = (minimumFontScale ?: 0.5).coerceIn(0.05, 1.0).toFloat(),
|
|
406
472
|
allowFontScaling = allowFontScaling ?: false,
|
|
@@ -413,6 +479,17 @@ class HybridNitroNumberView(private val context: ThemedReactContext) : HybridNit
|
|
|
413
479
|
decimalSeparator = decimalSeparator ?: ".",
|
|
414
480
|
prefix = prefix ?: "",
|
|
415
481
|
suffix = suffix ?: "",
|
|
482
|
+
signDisplay = when (signDisplay) {
|
|
483
|
+
NitroNumberSignDisplay.ALWAYS -> 1
|
|
484
|
+
NitroNumberSignDisplay.EXCEPTZERO -> 2
|
|
485
|
+
NitroNumberSignDisplay.NEGATIVE -> 3
|
|
486
|
+
NitroNumberSignDisplay.NEVER -> 4
|
|
487
|
+
NitroNumberSignDisplay.AUTO, null -> 0
|
|
488
|
+
},
|
|
489
|
+
plusSign = plusSign?.takeIf { it.isNotEmpty() } ?: "+",
|
|
490
|
+
minusSign = minusSign?.takeIf { it.isNotEmpty() } ?: "-",
|
|
491
|
+
groupingSizes = groupingSizes?.map { if (it.isFinite()) Math.max(0, Math.rint(it).toInt()) else 0 } ?: emptyList(),
|
|
492
|
+
digitMax = digitMax?.map { if (it.isFinite()) Math.rint(it).toInt() else 9 } ?: emptyList(),
|
|
416
493
|
)
|
|
417
494
|
rollingView.timing = NitroNumberView.Timing(
|
|
418
495
|
transition = when (transition) {
|
|
@@ -446,11 +523,22 @@ class HybridNitroNumberView(private val context: ThemedReactContext) : HybridNit
|
|
|
446
523
|
},
|
|
447
524
|
revealStaggerMs = Math.max(0.0, revealStagger ?: 200.0).toLong(),
|
|
448
525
|
revealMilestoneHoldMs = Math.max(0.0, revealMilestoneHold ?: 0.0).toLong(),
|
|
526
|
+
continuous = continuous ?: false,
|
|
527
|
+
respectReduceMotion = respectReduceMotion ?: true,
|
|
449
528
|
)
|
|
450
529
|
rollingView.revealMilestones = revealMilestones ?: DoubleArray(0)
|
|
451
530
|
rollingView.shimmer = NitroNumberView.Shimmer(
|
|
452
531
|
color = shimmerColor?.let { colorFromARGB(it) },
|
|
453
532
|
durationMs = Math.max(200.0, shimmerDuration ?: 950.0).toLong(),
|
|
533
|
+
angle = (shimmerAngle?.takeIf { it.isFinite() } ?: 31.0).toFloat(),
|
|
534
|
+
width = (shimmerWidth?.takeIf { it.isFinite() && it > 0 } ?: 1.0).toFloat(),
|
|
535
|
+
baseColor = shimmerBaseColor?.let { colorFromARGB(it) },
|
|
536
|
+
leftToRight = when (shimmerDirection) {
|
|
537
|
+
NitroNumberShimmerDirection.LTR -> true
|
|
538
|
+
NitroNumberShimmerDirection.RTL -> false
|
|
539
|
+
else -> null
|
|
540
|
+
},
|
|
541
|
+
delayMs = Math.max(0.0, shimmerDelay?.takeIf { it.isFinite() } ?: 0.0).toLong(),
|
|
454
542
|
)
|
|
455
543
|
rollingView.flash = NitroNumberView.Flash(
|
|
456
544
|
upColor = flashUpColor?.let { colorFromARGB(it) },
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
package com.margelo.nitro.nitroinput
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.Keep
|
|
4
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Measures a NitroText line on the JS thread, the way [NitroTextView] lays it
|
|
8
|
+
* out ([NitroTextFonts]): every code point's advance plus the letter spacing,
|
|
9
|
+
* in dp.
|
|
10
|
+
*
|
|
11
|
+
* Mirrors `HybridNitroTextMeasure` in `HybridNitroTextView.swift` on iOS.
|
|
12
|
+
*/
|
|
13
|
+
@Keep
|
|
14
|
+
@DoNotStrip
|
|
15
|
+
class HybridNitroTextMeasure : HybridNitroTextMeasureSpec() {
|
|
16
|
+
override fun measure(text: String, fontSize: Double, fontWeight: Double, fontFamily: String, letterSpacing: Double): Double {
|
|
17
|
+
val entry = NitroTextFonts.entry(fontSize, fontWeight, fontFamily)
|
|
18
|
+
val density = NitroTextFonts.density
|
|
19
|
+
val spacingPx = (if (letterSpacing.isFinite()) letterSpacing else 0.0).toFloat() * density
|
|
20
|
+
return (NitroTextFonts.width(text, entry, spacingPx) / density).toDouble()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
override fun lineHeight(fontSize: Double, fontWeight: Double, fontFamily: String): Double =
|
|
24
|
+
(NitroTextFonts.entry(fontSize, fontWeight, fontFamily).lineHeight / NitroTextFonts.density).toDouble()
|
|
25
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
package com.margelo.nitro.nitroinput
|
|
2
|
+
|
|
3
|
+
import android.graphics.Color
|
|
4
|
+
import android.os.Handler
|
|
5
|
+
import android.os.Looper
|
|
6
|
+
import android.view.View
|
|
7
|
+
import androidx.annotation.Keep
|
|
8
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
9
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
10
|
+
import com.margelo.nitro.views.RecyclableView
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Nitro glue between NitroText's props and [NitroTextView]: the props land
|
|
14
|
+
* one by one and are applied together once Nitro says the update is done.
|
|
15
|
+
*
|
|
16
|
+
* Mirrors `HybridNitroTextView.swift` on iOS.
|
|
17
|
+
*/
|
|
18
|
+
@Keep
|
|
19
|
+
@DoNotStrip
|
|
20
|
+
class HybridNitroTextView(private val context: ThemedReactContext) : HybridNitroTextViewSpec(), RecyclableView {
|
|
21
|
+
private val mainHandler = Handler(Looper.getMainLooper())
|
|
22
|
+
private val textView = NitroTextView(context)
|
|
23
|
+
|
|
24
|
+
override val view: View
|
|
25
|
+
get() = textView
|
|
26
|
+
|
|
27
|
+
override var text: String = ""
|
|
28
|
+
// Unset unless the element set it: the wrapper sends only those.
|
|
29
|
+
override var fontSize: Double? = null
|
|
30
|
+
override var fontWeight: Double? = null
|
|
31
|
+
override var fontFamily: String? = null
|
|
32
|
+
override var color: Double? = null
|
|
33
|
+
override var letterSpacing: Double? = null
|
|
34
|
+
override var textAlign: NitroNumberTextAlign? = null
|
|
35
|
+
override var rightToLeft: Boolean? = null
|
|
36
|
+
override var duration: Double? = null
|
|
37
|
+
override var easing: NitroInputEasing? = null
|
|
38
|
+
override var bounce: Double? = null
|
|
39
|
+
override var effect: NitroInputEffect? = null
|
|
40
|
+
override var respectReduceMotion: Boolean? = null
|
|
41
|
+
override var loading: Boolean? = null
|
|
42
|
+
override var shimmerColor: Double? = null
|
|
43
|
+
override var shimmerDuration: Double? = null
|
|
44
|
+
override var shimmerAngle: Double? = null
|
|
45
|
+
override var shimmerWidth: Double? = null
|
|
46
|
+
override var shimmerBaseColor: Double? = null
|
|
47
|
+
override var shimmerDirection: NitroNumberShimmerDirection? = null
|
|
48
|
+
override var shimmerDelay: Double? = null
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Every prop of an update is set before this runs: apply them in one go
|
|
52
|
+
* (the style first, so the text is laid out in its font).
|
|
53
|
+
*/
|
|
54
|
+
override fun afterUpdate() {
|
|
55
|
+
onMain { apply() }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private fun apply() {
|
|
59
|
+
textView.style = NitroTextView.Style(
|
|
60
|
+
fontSize = fontSize?.takeIf { it.isFinite() && it > 0 } ?: 17.0,
|
|
61
|
+
fontWeight = fontWeight?.takeIf { it.isFinite() } ?: 400.0,
|
|
62
|
+
fontFamily = fontFamily ?: "",
|
|
63
|
+
color = color?.let(::colorFromARGB),
|
|
64
|
+
letterSpacing = (letterSpacing?.takeIf { it.isFinite() } ?: 0.0).toFloat(),
|
|
65
|
+
textAlign = when (textAlign) {
|
|
66
|
+
NitroNumberTextAlign.LEFT -> NitroNumberView.Alignment.LEFT
|
|
67
|
+
NitroNumberTextAlign.CENTER -> NitroNumberView.Alignment.CENTER
|
|
68
|
+
NitroNumberTextAlign.RIGHT -> NitroNumberView.Alignment.RIGHT
|
|
69
|
+
else -> NitroNumberView.Alignment.AUTO
|
|
70
|
+
},
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
textView.timing = NitroTextView.Timing(
|
|
74
|
+
durationSeconds = Math.max(0.0, (duration?.takeIf { it.isFinite() } ?: 400.0) / 1000.0),
|
|
75
|
+
easing = when (easing) {
|
|
76
|
+
NitroInputEasing.EASEOUT -> 1
|
|
77
|
+
NitroInputEasing.EASEINOUT -> 2
|
|
78
|
+
NitroInputEasing.LINEAR -> 3
|
|
79
|
+
NitroInputEasing.SPRING -> 4
|
|
80
|
+
else -> 0
|
|
81
|
+
},
|
|
82
|
+
bounce = bounce?.takeIf { it.isFinite() } ?: 0.15,
|
|
83
|
+
effect = when (effect) {
|
|
84
|
+
NitroInputEffect.SLIDE -> 1
|
|
85
|
+
NitroInputEffect.FADE -> 2
|
|
86
|
+
else -> 0
|
|
87
|
+
},
|
|
88
|
+
respectReduceMotion = respectReduceMotion ?: true,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
textView.shimmer = NitroNumberView.Shimmer(
|
|
92
|
+
color = shimmerColor?.let(::colorFromARGB),
|
|
93
|
+
durationMs = Math.max(200.0, shimmerDuration?.takeIf { it.isFinite() } ?: 950.0).toLong(),
|
|
94
|
+
angle = (shimmerAngle?.takeIf { it.isFinite() } ?: 31.0).toFloat(),
|
|
95
|
+
width = (shimmerWidth?.takeIf { it.isFinite() && it > 0 } ?: 1.0).toFloat(),
|
|
96
|
+
baseColor = shimmerBaseColor?.let(::colorFromARGB),
|
|
97
|
+
leftToRight = when (shimmerDirection) {
|
|
98
|
+
NitroNumberShimmerDirection.LTR -> true
|
|
99
|
+
NitroNumberShimmerDirection.RTL -> false
|
|
100
|
+
else -> null
|
|
101
|
+
},
|
|
102
|
+
delayMs = Math.max(0.0, shimmerDelay?.takeIf { it.isFinite() } ?: 0.0).toLong(),
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
textView.rightToLeft = rightToLeft ?: false
|
|
106
|
+
textView.text = text
|
|
107
|
+
textView.loading = loading ?: false
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Fabric dropped the view: stop its frame loop (a recycled one is reset next). */
|
|
111
|
+
override fun onDropView() {
|
|
112
|
+
onMain { textView.stopFrames() }
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Fabric is about to reuse this view for another element. */
|
|
116
|
+
override fun prepareForRecycle() {
|
|
117
|
+
// The next element's props arrive as a first mount's do, only the ones it set.
|
|
118
|
+
text = ""
|
|
119
|
+
fontSize = null; fontWeight = null; fontFamily = null; color = null; letterSpacing = null
|
|
120
|
+
textAlign = null; rightToLeft = null
|
|
121
|
+
duration = null; easing = null; bounce = null; effect = null; respectReduceMotion = null
|
|
122
|
+
loading = null
|
|
123
|
+
shimmerColor = null; shimmerDuration = null; shimmerAngle = null; shimmerWidth = null
|
|
124
|
+
shimmerBaseColor = null; shimmerDirection = null; shimmerDelay = null
|
|
125
|
+
onMain { textView.resetForRecycle() }
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
override val memorySize: Long
|
|
129
|
+
get() = 8L * 1024
|
|
130
|
+
|
|
131
|
+
private fun onMain(block: () -> Unit) {
|
|
132
|
+
if (Looper.myLooper() == Looper.getMainLooper()) block() else mainHandler.post(block)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private fun colorFromARGB(value: Double): Int? {
|
|
136
|
+
if (!value.isFinite()) return null
|
|
137
|
+
val bits = value.toLong().toInt()
|
|
138
|
+
return Color.argb((bits ushr 24) and 0xff, (bits ushr 16) and 0xff, (bits ushr 8) and 0xff, bits and 0xff)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -25,6 +25,20 @@ class MaskEngine {
|
|
|
25
25
|
external fun addNotation(character: String, characterSet: String, isOptional: Boolean)
|
|
26
26
|
/** False when the pattern is malformed; the engine then passes text through. */
|
|
27
27
|
external fun setFormat(format: String): Boolean
|
|
28
|
+
/** Stages alternative patterns for the next [setFormat]; the best one wins each edit. */
|
|
29
|
+
external fun clearAffinityFormats()
|
|
30
|
+
external fun addAffinityFormat(format: String)
|
|
31
|
+
/** `NitroInputMaskAffinity.value`: how the best alternative is chosen. */
|
|
32
|
+
external fun setAffinityStrategy(strategy: Int)
|
|
33
|
+
/** `NitroInputTextCase.value`: letters folded before masking. */
|
|
34
|
+
external fun setTextCase(textCase: Int)
|
|
35
|
+
/** Characters replaced before masking; an empty [to] drops [from]. */
|
|
36
|
+
external fun clearCharacterMap()
|
|
37
|
+
external fun addCharacterMapping(from: String, to: String)
|
|
38
|
+
/** What each empty slot shows in the tail placeholder; empty = its notation character. */
|
|
39
|
+
external fun setSlotPlaceholder(character: String)
|
|
40
|
+
/** False until a valid pattern is set. */
|
|
41
|
+
external fun isActive(): Boolean
|
|
28
42
|
|
|
29
43
|
/** Replaces code points `[start, end)` of [current] with [replacement]. */
|
|
30
44
|
external fun applyEdit(
|
|
@@ -47,4 +61,6 @@ class MaskEngine {
|
|
|
47
61
|
external fun lastTailPlaceholder(): String
|
|
48
62
|
/** Whether every mandatory slot is filled. */
|
|
49
63
|
external fun lastComplete(): Boolean
|
|
64
|
+
/** Which pattern produced the last result: 0 the primary, 1… the alternatives. */
|
|
65
|
+
external fun lastFormatIndex(): Int
|
|
50
66
|
}
|
|
@@ -7,6 +7,7 @@ import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
|
7
7
|
import com.facebook.react.uimanager.ViewManager
|
|
8
8
|
import com.margelo.nitro.nitroinput.views.HybridNitroInputViewManager
|
|
9
9
|
import com.margelo.nitro.nitroinput.views.HybridNitroNumberViewManager
|
|
10
|
+
import com.margelo.nitro.nitroinput.views.HybridNitroTextViewManager
|
|
10
11
|
|
|
11
12
|
class NitroInputPackage : BaseReactPackage() {
|
|
12
13
|
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? = null
|
|
@@ -14,7 +15,7 @@ class NitroInputPackage : BaseReactPackage() {
|
|
|
14
15
|
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider = ReactModuleInfoProvider { HashMap() }
|
|
15
16
|
|
|
16
17
|
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
17
|
-
return listOf(HybridNitroInputViewManager(), HybridNitroNumberViewManager())
|
|
18
|
+
return listOf(HybridNitroInputViewManager(), HybridNitroNumberViewManager(), HybridNitroTextViewManager())
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
companion object {
|
|
@@ -79,6 +79,9 @@ class NitroInputView(context: Context) : FrameLayout(context) {
|
|
|
79
79
|
/** A caller-defined slot character for [Format.mask]. */
|
|
80
80
|
data class MaskNotation(val character: String, val characterSet: String, val isOptional: Boolean)
|
|
81
81
|
|
|
82
|
+
/** One character replaced by another before masking. */
|
|
83
|
+
data class MaskMapping(val from: String, val to: String)
|
|
84
|
+
|
|
82
85
|
/**
|
|
83
86
|
* The frame the view draws for itself: the outline (or fill) and the floating
|
|
84
87
|
* label. Separate from [Format] because it changes independently. Lengths are
|
|
@@ -110,6 +113,16 @@ class NitroInputView(context: Context) : FrameLayout(context) {
|
|
|
110
113
|
val maskNotations: List<MaskNotation> = emptyList(),
|
|
111
114
|
val maskAutocomplete: Boolean = true,
|
|
112
115
|
val maskAutoSkip: Boolean = false,
|
|
116
|
+
/** Mask mode: alternative patterns and how the best is chosen (`NitroInputMaskAffinity.value`). */
|
|
117
|
+
val maskAffinityFormats: List<String> = emptyList(),
|
|
118
|
+
val maskAffinityStrategy: Int = 0,
|
|
119
|
+
/** Mask mode: `NitroInputTextCase.value`. */
|
|
120
|
+
val maskTextCase: Int = 0,
|
|
121
|
+
val maskCharacterMap: List<MaskMapping> = emptyList(),
|
|
122
|
+
/** Mask mode: what an empty slot shows in the tail; empty = its notation. */
|
|
123
|
+
val maskSlotPlaceholder: String = "",
|
|
124
|
+
/** Mask mode: keep the rest of the placeholder after the typed text. */
|
|
125
|
+
val keepPlaceholder: Boolean = false,
|
|
113
126
|
val fractionDigits: Int = 2,
|
|
114
127
|
val maxIntegerDigits: Int = 15,
|
|
115
128
|
val groupingSeparator: String = ",",
|
|
@@ -218,11 +231,20 @@ class NitroInputView(context: Context) : FrameLayout(context) {
|
|
|
218
231
|
val old = field
|
|
219
232
|
field = value
|
|
220
233
|
formatter.setFormat(value.fractionDigits, value.maxIntegerDigits, value.groupingSeparator, value.decimalSeparator)
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
234
|
+
val maskChanged = old.mask != value.mask || old.maskNotations != value.maskNotations ||
|
|
235
|
+
old.maskAffinityFormats != value.maskAffinityFormats || old.maskAffinityStrategy != value.maskAffinityStrategy ||
|
|
236
|
+
old.maskTextCase != value.maskTextCase || old.maskCharacterMap != value.maskCharacterMap ||
|
|
237
|
+
old.maskSlotPlaceholder != value.maskSlotPlaceholder
|
|
238
|
+
if (value.mode == Mode.MASK && (old.mode != Mode.MASK || maskChanged)) {
|
|
224
239
|
maskEngine.clearNotations()
|
|
225
240
|
value.maskNotations.forEach { maskEngine.addNotation(it.character, it.characterSet, it.isOptional) }
|
|
241
|
+
maskEngine.clearAffinityFormats()
|
|
242
|
+
value.maskAffinityFormats.forEach { maskEngine.addAffinityFormat(it) }
|
|
243
|
+
maskEngine.setAffinityStrategy(value.maskAffinityStrategy)
|
|
244
|
+
maskEngine.setTextCase(value.maskTextCase)
|
|
245
|
+
maskEngine.clearCharacterMap()
|
|
246
|
+
value.maskCharacterMap.forEach { maskEngine.addCharacterMapping(it.from, it.to) }
|
|
247
|
+
maskEngine.setSlotPlaceholder(value.maskSlotPlaceholder)
|
|
226
248
|
// A bad pattern leaves the engine inactive; the field then behaves as
|
|
227
249
|
// plain text rather than refusing every keystroke.
|
|
228
250
|
maskEngine.setFormat(value.mask)
|
|
@@ -382,6 +404,23 @@ class NitroInputView(context: Context) : FrameLayout(context) {
|
|
|
382
404
|
return offsetForTap(x)
|
|
383
405
|
}
|
|
384
406
|
|
|
407
|
+
private val ghostPaint = android.text.TextPaint()
|
|
408
|
+
|
|
409
|
+
override fun onDraw(canvas: Canvas) {
|
|
410
|
+
super.onDraw(canvas)
|
|
411
|
+
// Plain mode has no overlay, so `keepPlaceholder`'s tail is drawn here:
|
|
412
|
+
// from where the field's own text ends, on its baseline, in its paint
|
|
413
|
+
// and the hint colour. (onDraw's canvas is already scrolled.)
|
|
414
|
+
if (!ready || !keyboard.plain || layoutDirection == LAYOUT_DIRECTION_RTL) return
|
|
415
|
+
val tail = ghostTail
|
|
416
|
+
val textLayout = layout ?: return
|
|
417
|
+
if (tail.isEmpty()) return
|
|
418
|
+
ghostPaint.set(paint)
|
|
419
|
+
ghostPaint.color = currentHintTextColor
|
|
420
|
+
val x = compoundPaddingLeft + textLayout.getPrimaryHorizontal(length())
|
|
421
|
+
canvas.drawText(tail, x, baseline.toFloat(), ghostPaint)
|
|
422
|
+
}
|
|
423
|
+
|
|
385
424
|
override fun onSelectionChanged(selStart: Int, selEnd: Int) {
|
|
386
425
|
super.onSelectionChanged(selStart, selEnd)
|
|
387
426
|
if (!ready) return
|
|
@@ -1528,7 +1567,12 @@ class NitroInputView(context: Context) : FrameLayout(context) {
|
|
|
1528
1567
|
// A plain field draws its own text and never feeds the engine, but its
|
|
1529
1568
|
// width still has to reach React for `autoWidth`; every text, font, affix
|
|
1530
1569
|
// and hint change comes through here.
|
|
1531
|
-
if (keyboard.plain) {
|
|
1570
|
+
if (keyboard.plain) {
|
|
1571
|
+
// The EditText draws the kept placeholder's tail itself (HiddenEditText.onDraw).
|
|
1572
|
+
editText.invalidate()
|
|
1573
|
+
reportIntrinsicSize()
|
|
1574
|
+
return
|
|
1575
|
+
}
|
|
1532
1576
|
val f = fonts
|
|
1533
1577
|
engine.setReduceMotion(animationsDisabled())
|
|
1534
1578
|
engine.beginText()
|
|
@@ -1549,7 +1593,13 @@ class NitroInputView(context: Context) : FrameLayout(context) {
|
|
|
1549
1593
|
// body glyph before a suffix carry the seams instead.
|
|
1550
1594
|
if (signed) addRun(shown.substring(0, 1), Role.BODY, f, placeholder = false)
|
|
1551
1595
|
addRun(format.prefix, Role.PREFIX, f, placeholder = false, lastSpacing = f.prefixSeam)
|
|
1596
|
+
val tail = if (showPlaceholder) "" else ghostTail
|
|
1552
1597
|
addRun(if (signed) shown.substring(1) else shown, Role.BODY, f, placeholder = showPlaceholder,
|
|
1598
|
+
lastSpacing = if (format.suffix.isNotEmpty() && tail.isEmpty()) f.suffixSeam else null)
|
|
1599
|
+
// `keepPlaceholder`: the rest of the mask trails the text as placeholder
|
|
1600
|
+
// glyphs. They come after every typed glyph, so the caret - which counts
|
|
1601
|
+
// body glyphs in order - never lands among them.
|
|
1602
|
+
addRun(tail, Role.BODY, f, placeholder = true,
|
|
1553
1603
|
lastSpacing = if (format.suffix.isNotEmpty()) f.suffixSeam else null)
|
|
1554
1604
|
addRun(format.suffix, Role.SUFFIX, f, placeholder = false)
|
|
1555
1605
|
engine.commitText(caret, now())
|
|
@@ -1720,7 +1770,7 @@ class NitroInputView(context: Context) : FrameLayout(context) {
|
|
|
1720
1770
|
val body = when {
|
|
1721
1771
|
text.isEmpty() -> effectivePlaceholder
|
|
1722
1772
|
keyboard.secureTextEntry -> "\u2022".repeat(text.codePointCount(0, text.length))
|
|
1723
|
-
else -> text
|
|
1773
|
+
else -> text + ghostTail
|
|
1724
1774
|
}
|
|
1725
1775
|
// The edit text's own letter spacing follows every glyph; the affixes take their room with their seams.
|
|
1726
1776
|
val f = fonts
|
|
@@ -1940,7 +1990,47 @@ class NitroInputView(context: Context) : FrameLayout(context) {
|
|
|
1940
1990
|
* waits until the label has floated clear rather than printing over it.
|
|
1941
1991
|
*/
|
|
1942
1992
|
private val effectivePlaceholder: String
|
|
1943
|
-
get() = if (inputFrame.hasLabel && !labelShouldFloat) "" else
|
|
1993
|
+
get() = if (inputFrame.hasLabel && !labelShouldFloat) "" else basePlaceholder
|
|
1994
|
+
|
|
1995
|
+
/**
|
|
1996
|
+
* `keepPlaceholder` without a `placeholder` shows the mask itself, empty
|
|
1997
|
+
* slots as `maskSlotPlaceholder`: "+1 (___) ___-____".
|
|
1998
|
+
*/
|
|
1999
|
+
private val basePlaceholder: String
|
|
2000
|
+
get() {
|
|
2001
|
+
if (format.placeholder.isEmpty() && format.mode == Mode.MASK && format.keepPlaceholder && maskEngine.isActive()) {
|
|
2002
|
+
maskEngine.applyAll("", 0, true, false, false)
|
|
2003
|
+
return maskEngine.lastTailPlaceholder()
|
|
2004
|
+
}
|
|
2005
|
+
return format.placeholder
|
|
2006
|
+
}
|
|
2007
|
+
|
|
2008
|
+
/**
|
|
2009
|
+
* `keepPlaceholder`: what is still to come after the typed text, drawn in the
|
|
2010
|
+
* placeholder colour. The caller's placeholder from where the text ends -
|
|
2011
|
+
* "1234 5" leaves "678 9012" of "1234 5678 9012" - or, without one, the rest
|
|
2012
|
+
* of the mask. The placeholder is written for `mask`, so when one of
|
|
2013
|
+
* `maskAffinityFormats` has taken over (a 4-6-5 Amex under a 4-4-4-4
|
|
2014
|
+
* placeholder) its characters no longer line up, and that format's own tail
|
|
2015
|
+
* is shown instead. A complete text has nothing to come.
|
|
2016
|
+
*/
|
|
2017
|
+
private val ghostTail: String
|
|
2018
|
+
get() {
|
|
2019
|
+
if (format.mode != Mode.MASK || !format.keepPlaceholder || text.isEmpty() || keyboard.secureTextEntry ||
|
|
2020
|
+
!maskEngine.isActive()
|
|
2021
|
+
) {
|
|
2022
|
+
return ""
|
|
2023
|
+
}
|
|
2024
|
+
val typed = text.codePointCount(0, text.length)
|
|
2025
|
+
maskEngine.applyAll(text, typed, true, false, false)
|
|
2026
|
+
if (maskEngine.lastComplete()) return ""
|
|
2027
|
+
val placeholder = format.placeholder
|
|
2028
|
+
if (placeholder.isNotEmpty() && maskEngine.lastFormatIndex() == 0) {
|
|
2029
|
+
val total = placeholder.codePointCount(0, placeholder.length)
|
|
2030
|
+
return if (typed < total) placeholder.substring(placeholder.offsetByCodePoints(0, typed)) else ""
|
|
2031
|
+
}
|
|
2032
|
+
return maskEngine.lastTailPlaceholder()
|
|
2033
|
+
}
|
|
1944
2034
|
|
|
1945
2035
|
private fun resolvedStrokeColor(): Int {
|
|
1946
2036
|
val base = inputFrame.strokeColor ?: mutedTextColor
|