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.
- package/CHANGELOG.md +305 -3
- package/NitroInput.podspec +4 -4
- package/README.md +378 -53
- package/android/CMakeLists.txt +5 -3
- package/android/src/main/cpp/JOutlineGeometry.hpp +1 -1
- package/android/src/main/cpp/JReflowEngine.cpp +132 -0
- package/android/src/main/cpp/{JMorphEngine.hpp → JReflowEngine.hpp} +7 -7
- package/android/src/main/cpp/JRollingEngine.cpp +222 -0
- package/android/src/main/cpp/JRollingEngine.hpp +68 -0
- package/android/src/main/cpp/cpp-adapter.cpp +4 -2
- package/android/src/main/java/com/margelo/nitro/nitroinput/AmountFormatter.kt +1 -1
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroInputView.kt +1 -1
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroNumberView.kt +471 -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 +38 -16
- package/android/src/main/java/com/margelo/nitro/nitroinput/NitroNumberView.kt +1741 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/{MorphEngine.kt → ReflowEngine.kt} +2 -2
- package/android/src/main/java/com/margelo/nitro/nitroinput/RollingEngine.kt +59 -0
- package/cpp/AmountFormatter.cpp +5 -0
- package/cpp/AmountFormatter.hpp +10 -2
- package/cpp/{MorphEngine.cpp → ReflowEngine.cpp} +52 -47
- package/cpp/{MorphEngine.hpp → ReflowEngine.hpp} +12 -4
- package/cpp/RollingEngine.cpp +1224 -0
- package/cpp/RollingEngine.hpp +468 -0
- package/cpp/SwiftNonCopyable.hpp +22 -0
- package/cpp/worklets/NitroInputWorkletsBridge.cpp +3 -3
- package/cpp/worklets/NitroInputWorkletsBridge.hpp +1 -1
- package/ios/{HybridMorphInputView.swift → HybridNitroInputView.swift} +1 -1
- package/ios/HybridNitroNumberView.swift +439 -0
- package/ios/NitroInputView.swift +69 -45
- package/ios/NitroNumberView.swift +1934 -0
- package/lib/commonjs/nitrogen/generated/shared/json/NitroNumberViewConfig.json +55 -0
- package/lib/commonjs/src/NitroInput.js +21 -52
- package/lib/commonjs/src/NitroNumber.js +139 -0
- package/lib/commonjs/src/index.js +4 -3
- package/lib/commonjs/src/specs/NitroNumber.nitro.js +2 -0
- package/lib/commonjs/src/styleHelpers.js +36 -0
- package/lib/module/nitrogen/generated/shared/json/NitroNumberViewConfig.json +55 -0
- package/lib/module/src/NitroInput.js +12 -43
- package/lib/module/src/NitroNumber.js +100 -0
- package/lib/module/src/index.js +1 -1
- package/lib/module/src/specs/NitroNumber.nitro.js +1 -0
- package/lib/module/src/styleHelpers.js +32 -0
- package/lib/typescript/src/NitroInput.d.ts +28 -21
- package/lib/typescript/src/NitroNumber.d.ts +211 -0
- package/lib/typescript/src/index.d.ts +3 -2
- package/lib/typescript/src/specs/NitroInput.nitro.d.ts +9 -9
- package/lib/typescript/src/specs/NitroNumber.nitro.d.ts +238 -0
- package/lib/typescript/src/styleHelpers.d.ts +3 -0
- package/nitro.json +10 -0
- package/nitrogen/generated/android/NitroInput+autolinking.cmake +4 -0
- package/nitrogen/generated/android/NitroInputOnLoad.cpp +20 -0
- package/nitrogen/generated/android/c++/JFunc_void.hpp +75 -0
- package/nitrogen/generated/android/c++/JFunc_void_double_double.hpp +10 -10
- package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.cpp +536 -0
- package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.hpp +156 -0
- package/nitrogen/generated/android/c++/JNitroNumberAffixAlign.hpp +64 -0
- package/nitrogen/generated/android/c++/JNitroNumberDirection.hpp +61 -0
- package/nitrogen/generated/android/c++/JNitroNumberEasing.hpp +67 -0
- package/nitrogen/generated/android/c++/JNitroNumberRevealStyle.hpp +58 -0
- package/nitrogen/generated/android/c++/JNitroNumberTextAlign.hpp +64 -0
- package/nitrogen/generated/android/c++/JNitroNumberTransition.hpp +61 -0
- package/nitrogen/generated/android/c++/views/JHybridNitroNumberViewStateUpdater.cpp +299 -0
- package/nitrogen/generated/android/c++/views/JHybridNitroNumberViewStateUpdater.hpp +54 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/Func_void.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/Func_void_double_double.kt +9 -9
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroNumberViewSpec.kt +363 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberAffixAlign.kt +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberDirection.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberEasing.kt +26 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberRevealStyle.kt +23 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberTextAlign.kt +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberTransition.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/views/HybridNitroNumberViewManager.kt +96 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/views/HybridNitroNumberViewStateUpdater.kt +23 -0
- package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.cpp +25 -0
- package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.hpp +248 -0
- package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Umbrella.hpp +23 -0
- package/nitrogen/generated/ios/NitroInputAutolinking.mm +8 -0
- package/nitrogen/generated/ios/NitroInputAutolinking.swift +12 -0
- package/nitrogen/generated/ios/c++/HybridNitroNumberViewSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNitroNumberViewSpecSwift.hpp +432 -0
- package/nitrogen/generated/ios/c++/views/HybridNitroNumberViewComponent.mm +414 -0
- package/nitrogen/generated/ios/swift/Func_void.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_double_double.swift +5 -5
- package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec.swift +102 -0
- package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec_cxx.swift +1243 -0
- package/nitrogen/generated/ios/swift/NitroNumberAffixAlign.swift +48 -0
- package/nitrogen/generated/ios/swift/NitroNumberDirection.swift +44 -0
- package/nitrogen/generated/ios/swift/NitroNumberEasing.swift +52 -0
- package/nitrogen/generated/ios/swift/NitroNumberRevealStyle.swift +40 -0
- package/nitrogen/generated/ios/swift/NitroNumberTextAlign.swift +48 -0
- package/nitrogen/generated/ios/swift/NitroNumberTransition.swift +44 -0
- package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.cpp +115 -0
- package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.hpp +175 -0
- package/nitrogen/generated/shared/c++/NitroNumberAffixAlign.hpp +84 -0
- package/nitrogen/generated/shared/c++/NitroNumberDirection.hpp +80 -0
- package/nitrogen/generated/shared/c++/NitroNumberEasing.hpp +88 -0
- package/nitrogen/generated/shared/c++/NitroNumberRevealStyle.hpp +76 -0
- package/nitrogen/generated/shared/c++/NitroNumberTextAlign.hpp +84 -0
- package/nitrogen/generated/shared/c++/NitroNumberTransition.hpp +80 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.cpp +124 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.hpp +227 -0
- package/nitrogen/generated/shared/json/NitroNumberViewConfig.json +55 -0
- package/package.json +15 -7
- package/src/NitroInput.tsx +37 -60
- package/src/NitroNumber.tsx +481 -0
- package/src/index.ts +20 -6
- package/src/specs/NitroInput.nitro.ts +9 -9
- package/src/specs/NitroNumber.nitro.ts +259 -0
- package/src/styleHelpers.ts +32 -0
- package/android/src/main/cpp/JMorphEngine.cpp +0 -132
- package/lib/commonjs/src/MorphInput.js +0 -42
- package/lib/module/src/MorphInput.js +0 -6
- package/lib/typescript/src/MorphInput.d.ts +0 -18
- package/src/MorphInput.tsx +0 -30
|
@@ -0,0 +1,471 @@
|
|
|
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 React props / hybrid methods and [NitroNumberView].
|
|
14
|
+
*/
|
|
15
|
+
@Keep
|
|
16
|
+
@DoNotStrip
|
|
17
|
+
class HybridNitroNumberView(private val context: ThemedReactContext) : HybridNitroNumberViewSpec(), RecyclableView {
|
|
18
|
+
private val mainHandler = Handler(Looper.getMainLooper())
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The platform view, or null once Fabric has dropped it. This hybrid is
|
|
22
|
+
* kept alive by Nitro's C++ part for as long as the JS handle to it (the
|
|
23
|
+
* `hybridRef`) exists, and Hermes collects that handle only when the JS
|
|
24
|
+
* heap fills up; so a dropped hybrid lets go of the view rather than keep a
|
|
25
|
+
* `View`, its display list and engine around meanwhile. A method called on
|
|
26
|
+
* a stale ref gets a fresh, detached view.
|
|
27
|
+
*/
|
|
28
|
+
private var attachedView: NitroNumberView? = null
|
|
29
|
+
private val rollingView: NitroNumberView
|
|
30
|
+
get() = attachedView ?: NitroNumberView(context).also {
|
|
31
|
+
wire(it)
|
|
32
|
+
attachedView = it
|
|
33
|
+
}
|
|
34
|
+
/** Set by [prepareForRecycle]: Fabric is keeping the dropped view for reuse. */
|
|
35
|
+
private var recycled = false
|
|
36
|
+
|
|
37
|
+
override val view: View
|
|
38
|
+
get() = rollingView
|
|
39
|
+
|
|
40
|
+
private var isBatching = false
|
|
41
|
+
private var pendingValue: Double? = null
|
|
42
|
+
private var configDirty = true
|
|
43
|
+
/**
|
|
44
|
+
* The `reveal` prop as last applied: null = normal rolling, false = held at
|
|
45
|
+
* the opening frame, true = the count has been fired.
|
|
46
|
+
*/
|
|
47
|
+
private var appliedReveal: Boolean? = null
|
|
48
|
+
|
|
49
|
+
private fun wire(rollingView: NitroNumberView) {
|
|
50
|
+
rollingView.onIntrinsicSizeChange = { width, height ->
|
|
51
|
+
onSizeChange?.invoke(width.toDouble(), height.toDouble())
|
|
52
|
+
}
|
|
53
|
+
rollingView.onRevealEnd = { onRevealEnd?.invoke() }
|
|
54
|
+
rollingView.onRevealMilestone = { index, milestone -> onRevealMilestone?.invoke(index.toDouble(), milestone) }
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// region Props
|
|
58
|
+
|
|
59
|
+
override var value: Double
|
|
60
|
+
get() = rollingView.targetValue
|
|
61
|
+
set(v) {
|
|
62
|
+
pendingValue = v
|
|
63
|
+
commitIfNeeded()
|
|
64
|
+
}
|
|
65
|
+
override var fractionDigits: Double? = null
|
|
66
|
+
set(v) { field = v; markConfigDirty() }
|
|
67
|
+
override var minimumIntegerDigits: Double? = null
|
|
68
|
+
set(v) { field = v; markConfigDirty() }
|
|
69
|
+
override var groupingSeparator: String? = null
|
|
70
|
+
set(v) { field = v; markConfigDirty() }
|
|
71
|
+
override var decimalSeparator: String? = null
|
|
72
|
+
set(v) { field = v; markConfigDirty() }
|
|
73
|
+
override var prefix: String? = null
|
|
74
|
+
set(v) { field = v; markConfigDirty() }
|
|
75
|
+
override var suffix: String? = null
|
|
76
|
+
set(v) { field = v; markConfigDirty() }
|
|
77
|
+
override var transition: NitroNumberTransition? = null
|
|
78
|
+
set(v) { field = v; markConfigDirty() }
|
|
79
|
+
override var flashUpColor: Double? = null
|
|
80
|
+
set(v) { field = v; markConfigDirty() }
|
|
81
|
+
override var flashDownColor: Double? = null
|
|
82
|
+
set(v) { field = v; markConfigDirty() }
|
|
83
|
+
override var flashDuration: Double? = null
|
|
84
|
+
set(v) { field = v; markConfigDirty() }
|
|
85
|
+
override var popOnChange: Double? = null
|
|
86
|
+
set(v) { field = v; markConfigDirty() }
|
|
87
|
+
override var duration: Double? = null
|
|
88
|
+
set(v) { field = v; markConfigDirty() }
|
|
89
|
+
override var easing: NitroNumberEasing? = null
|
|
90
|
+
set(v) { field = v; markConfigDirty() }
|
|
91
|
+
override var bounce: Double? = null
|
|
92
|
+
set(v) { field = v; markConfigDirty() }
|
|
93
|
+
override var stagger: Double? = null
|
|
94
|
+
set(v) { field = v; markConfigDirty() }
|
|
95
|
+
override var rollDirection: NitroNumberDirection? = null
|
|
96
|
+
set(v) { field = v; markConfigDirty() }
|
|
97
|
+
override var revealState: Double? = null
|
|
98
|
+
set(v) { field = v; commitIfNeeded() }
|
|
99
|
+
/** The tri-state `reveal` prop: null = normal rolling, false = hold, true = play. */
|
|
100
|
+
private val reveal: Boolean?
|
|
101
|
+
get() {
|
|
102
|
+
val state = revealState ?: return null
|
|
103
|
+
if (!state.isFinite()) return null
|
|
104
|
+
return when {
|
|
105
|
+
state >= 2 -> true
|
|
106
|
+
state >= 1 -> false
|
|
107
|
+
else -> null
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
override var revealStyle: NitroNumberRevealStyle? = null
|
|
111
|
+
set(v) { field = v; markConfigDirty() }
|
|
112
|
+
override var revealDuration: Double? = null
|
|
113
|
+
set(v) { field = v; markConfigDirty() }
|
|
114
|
+
override var revealBounce: Double? = null
|
|
115
|
+
set(v) { field = v; markConfigDirty() }
|
|
116
|
+
override var revealGrow: Double? = null
|
|
117
|
+
set(v) { field = v; markConfigDirty() }
|
|
118
|
+
override var revealStagger: Double? = null
|
|
119
|
+
set(v) { field = v; markConfigDirty() }
|
|
120
|
+
override var revealMilestones: DoubleArray? = null
|
|
121
|
+
set(v) { field = v; markConfigDirty() }
|
|
122
|
+
override var revealMilestoneHold: Double? = null
|
|
123
|
+
set(v) { field = v; markConfigDirty() }
|
|
124
|
+
override var onRevealEnd: (() -> Unit)? = null
|
|
125
|
+
override var onRevealMilestone: ((index: Double, value: Double) -> Unit)? = null
|
|
126
|
+
override var loading: Boolean? = null
|
|
127
|
+
set(v) { field = v; markConfigDirty() }
|
|
128
|
+
override var shimmerColor: Double? = null
|
|
129
|
+
set(v) { field = v; markConfigDirty() }
|
|
130
|
+
override var shimmerDuration: Double? = null
|
|
131
|
+
set(v) { field = v; markConfigDirty() }
|
|
132
|
+
override var fontSize: Double? = null
|
|
133
|
+
set(v) { field = v; markConfigDirty() }
|
|
134
|
+
override var prefixFontSize: Double? = null
|
|
135
|
+
set(v) { field = v; markConfigDirty() }
|
|
136
|
+
override var suffixFontSize: Double? = null
|
|
137
|
+
set(v) { field = v; markConfigDirty() }
|
|
138
|
+
override var affixAlign: NitroNumberAffixAlign? = null
|
|
139
|
+
set(v) { field = v; markConfigDirty() }
|
|
140
|
+
override var prefixAlign: NitroNumberAffixAlign? = null
|
|
141
|
+
set(v) { field = v; markConfigDirty() }
|
|
142
|
+
override var suffixAlign: NitroNumberAffixAlign? = null
|
|
143
|
+
set(v) { field = v; markConfigDirty() }
|
|
144
|
+
override var adjustsFontSizeToFit: Boolean? = null
|
|
145
|
+
set(v) { field = v; markConfigDirty() }
|
|
146
|
+
override var minimumFontScale: Double? = null
|
|
147
|
+
set(v) { field = v; markConfigDirty() }
|
|
148
|
+
override var allowFontScaling: Boolean? = null
|
|
149
|
+
set(v) { field = v; markConfigDirty() }
|
|
150
|
+
override var maxFontSizeMultiplier: Double? = null
|
|
151
|
+
set(v) { field = v; markConfigDirty() }
|
|
152
|
+
override var fontWeight: Double? = null
|
|
153
|
+
set(v) { field = v; markConfigDirty() }
|
|
154
|
+
override var fontFamily: String? = null
|
|
155
|
+
set(v) { field = v; markConfigDirty() }
|
|
156
|
+
override var color: Double? = null
|
|
157
|
+
set(v) { field = v; markConfigDirty() }
|
|
158
|
+
override var textAlign: NitroNumberTextAlign? = null
|
|
159
|
+
set(v) { field = v; markConfigDirty() }
|
|
160
|
+
override var rightToLeft: Boolean? = null
|
|
161
|
+
set(v) { field = v; markConfigDirty() }
|
|
162
|
+
override var onSizeChange: ((width: Double, height: Double) -> Unit)? = null
|
|
163
|
+
set(v) {
|
|
164
|
+
field = v
|
|
165
|
+
onMain { rollingView.resendIntrinsicSize() }
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// endregion
|
|
169
|
+
|
|
170
|
+
// region Methods
|
|
171
|
+
|
|
172
|
+
override fun jumpTo(value: Double) = enqueue(Command.Jump(value))
|
|
173
|
+
|
|
174
|
+
override fun animateTo(value: Double) = enqueue(Command.Animate(value))
|
|
175
|
+
|
|
176
|
+
override fun revealTo(value: Double) = enqueue(Command.Reveal(value))
|
|
177
|
+
|
|
178
|
+
private sealed class Command {
|
|
179
|
+
class Jump(val value: Double) : Command()
|
|
180
|
+
class Animate(val value: Double) : Command()
|
|
181
|
+
class Reveal(val value: Double) : Command()
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
private val commandLock = Any()
|
|
185
|
+
private var pendingCommand: Command? = null
|
|
186
|
+
private var commandScheduled = false
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Coalesces calls from the JS thread: only the latest value is applied per
|
|
190
|
+
* main-thread turn, so a caller pushing a value every frame (scrubbing, live
|
|
191
|
+
* meters, many views at once) can never pile up a backlog of posts that
|
|
192
|
+
* stalls the main thread. A frame only ever shows the newest value anyway.
|
|
193
|
+
*/
|
|
194
|
+
private fun enqueue(command: Command) {
|
|
195
|
+
val schedule: Boolean
|
|
196
|
+
synchronized(commandLock) {
|
|
197
|
+
pendingCommand = command
|
|
198
|
+
schedule = !commandScheduled
|
|
199
|
+
commandScheduled = true
|
|
200
|
+
}
|
|
201
|
+
if (schedule) onMain { drainCommand() }
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
private fun drainCommand() {
|
|
205
|
+
val command: Command?
|
|
206
|
+
synchronized(commandLock) {
|
|
207
|
+
command = pendingCommand
|
|
208
|
+
pendingCommand = null
|
|
209
|
+
commandScheduled = false
|
|
210
|
+
}
|
|
211
|
+
command ?: return
|
|
212
|
+
pendingValue = null
|
|
213
|
+
flushConfigIfNeeded()
|
|
214
|
+
when (command) {
|
|
215
|
+
is Command.Jump -> rollingView.setValue(command.value)
|
|
216
|
+
is Command.Animate -> rollingView.animateTo(command.value)
|
|
217
|
+
is Command.Reveal -> {
|
|
218
|
+
rollingView.reveal(command.value)
|
|
219
|
+
// The prop machine treats the count as fired, so a later `reveal={true}` doesn't replay it.
|
|
220
|
+
if (reveal != null) appliedReveal = true
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// endregion
|
|
226
|
+
|
|
227
|
+
// region Lifecycle
|
|
228
|
+
|
|
229
|
+
override fun beforeUpdate() {
|
|
230
|
+
isBatching = true
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
override fun afterUpdate() {
|
|
234
|
+
isBatching = false
|
|
235
|
+
commit()
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Fabric dropped the view. The Kotlin object lives on until the JS handle
|
|
240
|
+
* to it (`hybridRef`) is garbage-collected, so the view lets go of what is
|
|
241
|
+
* sizeable now and keeps only itself.
|
|
242
|
+
*/
|
|
243
|
+
override fun onDropView() {
|
|
244
|
+
recycled = false
|
|
245
|
+
onMain {
|
|
246
|
+
attachedView?.release()
|
|
247
|
+
// With view recycling on, Fabric asks for prepareForRecycle right after
|
|
248
|
+
// this hook, synchronously; by the next main-thread turn we know whether
|
|
249
|
+
// the view is wanted again or can go.
|
|
250
|
+
mainHandler.post { if (!recycled) attachedView = null }
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** JS called `dispose()` on the ref: same as a drop. */
|
|
255
|
+
override fun dispose() {
|
|
256
|
+
onMain { attachedView?.release() }
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Reported to the JS garbage collector so a dropped view's handle counts as
|
|
261
|
+
* the memory it holds rather than as an empty object; that is what makes
|
|
262
|
+
* Hermes collect the handles, and with them the views, in time.
|
|
263
|
+
*/
|
|
264
|
+
override val memorySize: Long
|
|
265
|
+
get() = attachedView?.memoryEstimateBytes() ?: 0L
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Fabric is about to reuse this view for another element: forget every prop
|
|
269
|
+
* and all animation state. Nitro re-applies the new element's props next.
|
|
270
|
+
*/
|
|
271
|
+
override fun prepareForRecycle() {
|
|
272
|
+
recycled = true
|
|
273
|
+
// Batch the resets so the setters don't flush config thirty times.
|
|
274
|
+
isBatching = true
|
|
275
|
+
pendingValue = null
|
|
276
|
+
fractionDigits = null
|
|
277
|
+
minimumIntegerDigits = null
|
|
278
|
+
groupingSeparator = null
|
|
279
|
+
decimalSeparator = null
|
|
280
|
+
prefix = null
|
|
281
|
+
suffix = null
|
|
282
|
+
transition = null
|
|
283
|
+
flashUpColor = null
|
|
284
|
+
flashDownColor = null
|
|
285
|
+
flashDuration = null
|
|
286
|
+
popOnChange = null
|
|
287
|
+
duration = null
|
|
288
|
+
easing = null
|
|
289
|
+
bounce = null
|
|
290
|
+
stagger = null
|
|
291
|
+
rollDirection = null
|
|
292
|
+
revealState = null
|
|
293
|
+
revealStyle = null
|
|
294
|
+
revealDuration = null
|
|
295
|
+
revealBounce = null
|
|
296
|
+
revealGrow = null
|
|
297
|
+
revealStagger = null
|
|
298
|
+
revealMilestones = null
|
|
299
|
+
revealMilestoneHold = null
|
|
300
|
+
onRevealEnd = null
|
|
301
|
+
onRevealMilestone = null
|
|
302
|
+
appliedReveal = null
|
|
303
|
+
loading = null
|
|
304
|
+
shimmerColor = null
|
|
305
|
+
shimmerDuration = null
|
|
306
|
+
fontSize = null
|
|
307
|
+
prefixFontSize = null
|
|
308
|
+
suffixFontSize = null
|
|
309
|
+
affixAlign = null
|
|
310
|
+
prefixAlign = null
|
|
311
|
+
suffixAlign = null
|
|
312
|
+
adjustsFontSizeToFit = null
|
|
313
|
+
minimumFontScale = null
|
|
314
|
+
allowFontScaling = null
|
|
315
|
+
maxFontSizeMultiplier = null
|
|
316
|
+
fontWeight = null
|
|
317
|
+
fontFamily = null
|
|
318
|
+
color = null
|
|
319
|
+
textAlign = null
|
|
320
|
+
rightToLeft = null
|
|
321
|
+
onSizeChange = null
|
|
322
|
+
configDirty = true
|
|
323
|
+
isBatching = false
|
|
324
|
+
onMain { rollingView.resetForRecycle() }
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// endregion
|
|
328
|
+
|
|
329
|
+
// region Batching
|
|
330
|
+
|
|
331
|
+
private fun markConfigDirty() {
|
|
332
|
+
configDirty = true
|
|
333
|
+
commitIfNeeded()
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
private fun commitIfNeeded() {
|
|
337
|
+
if (!isBatching) commit()
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
private fun commit() {
|
|
341
|
+
onMain {
|
|
342
|
+
flushConfigIfNeeded()
|
|
343
|
+
val changed = pendingValue
|
|
344
|
+
pendingValue = null
|
|
345
|
+
val value = changed ?: rollingView.targetValue
|
|
346
|
+
val reveal = this.reveal
|
|
347
|
+
if (reveal == null) {
|
|
348
|
+
// A normal NitroNumber (also when leaving reveal mode).
|
|
349
|
+
appliedReveal = null
|
|
350
|
+
if (changed != null) rollingView.animateTo(changed)
|
|
351
|
+
return@onMain
|
|
352
|
+
}
|
|
353
|
+
if (!reveal) {
|
|
354
|
+
// Hold the opening frame; re-hold when the figure or the mode changed.
|
|
355
|
+
if (changed != null || appliedReveal != false) rollingView.holdReveal(value)
|
|
356
|
+
} else if (appliedReveal != true) {
|
|
357
|
+
// `reveal` just turned true (or the view mounted with it true): fire the count.
|
|
358
|
+
rollingView.reveal(value)
|
|
359
|
+
} else if (changed != null) {
|
|
360
|
+
// A new figure after the count was fired: re-target a running count, roll a landed one.
|
|
361
|
+
if (rollingView.isRevealing) rollingView.reveal(changed) else rollingView.animateTo(changed)
|
|
362
|
+
}
|
|
363
|
+
appliedReveal = reveal
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
private fun flushConfigIfNeeded() {
|
|
368
|
+
if (!configDirty) return
|
|
369
|
+
configDirty = false
|
|
370
|
+
|
|
371
|
+
rollingView.typography = NitroNumberView.Typography(
|
|
372
|
+
fontSize = (fontSize ?: 32.0).toFloat(),
|
|
373
|
+
prefixFontSize = prefixFontSize?.toFloat(),
|
|
374
|
+
suffixFontSize = suffixFontSize?.toFloat(),
|
|
375
|
+
fontWeight = clampInt(fontWeight, 100, 900, 400),
|
|
376
|
+
fontFamily = fontFamily,
|
|
377
|
+
color = color?.let { colorFromARGB(it) },
|
|
378
|
+
prefixAlign = mapAffixAlign(prefixAlign ?: affixAlign),
|
|
379
|
+
suffixAlign = mapAffixAlign(suffixAlign ?: affixAlign),
|
|
380
|
+
adjustsFontSizeToFit = adjustsFontSizeToFit ?: false,
|
|
381
|
+
minimumFontScale = (minimumFontScale ?: 0.5).coerceIn(0.05, 1.0).toFloat(),
|
|
382
|
+
allowFontScaling = allowFontScaling ?: false,
|
|
383
|
+
maxFontSizeMultiplier = Math.max(0.0, maxFontSizeMultiplier ?: 0.0).toFloat(),
|
|
384
|
+
)
|
|
385
|
+
rollingView.format = NitroNumberView.Format(
|
|
386
|
+
fractionDigits = clampInt(fractionDigits, 0, 9, 0),
|
|
387
|
+
minimumIntegerDigits = clampInt(minimumIntegerDigits, 1, 15, 1),
|
|
388
|
+
groupingSeparator = groupingSeparator ?: "",
|
|
389
|
+
decimalSeparator = decimalSeparator ?: ".",
|
|
390
|
+
prefix = prefix ?: "",
|
|
391
|
+
suffix = suffix ?: "",
|
|
392
|
+
)
|
|
393
|
+
rollingView.timing = NitroNumberView.Timing(
|
|
394
|
+
transition = when (transition) {
|
|
395
|
+
NitroNumberTransition.NUMERIC -> NitroNumberView.Transition.NUMERIC
|
|
396
|
+
NitroNumberTransition.SCRAMBLE -> NitroNumberView.Transition.SCRAMBLE
|
|
397
|
+
NitroNumberTransition.ROLL, null -> NitroNumberView.Transition.ROLL
|
|
398
|
+
},
|
|
399
|
+
popOnChange = (popOnChange ?: 0.0).coerceIn(0.0, 1.0),
|
|
400
|
+
durationMs = Math.max(0.0, duration ?: 500.0).toLong(),
|
|
401
|
+
easing = when (easing) {
|
|
402
|
+
NitroNumberEasing.LINEAR -> NitroNumberView.Easing.LINEAR
|
|
403
|
+
NitroNumberEasing.EASEIN -> NitroNumberView.Easing.EASE_IN
|
|
404
|
+
NitroNumberEasing.EASEOUT -> NitroNumberView.Easing.EASE_OUT
|
|
405
|
+
NitroNumberEasing.SPRING -> NitroNumberView.Easing.SPRING
|
|
406
|
+
NitroNumberEasing.EASEINOUT, null -> NitroNumberView.Easing.EASE_IN_OUT
|
|
407
|
+
},
|
|
408
|
+
bounce = bounce ?: 0.15,
|
|
409
|
+
staggerMs = Math.max(0.0, stagger ?: 0.0).toLong(),
|
|
410
|
+
direction = when (rollDirection) {
|
|
411
|
+
NitroNumberDirection.UP -> NitroNumberView.Direction.UP
|
|
412
|
+
NitroNumberDirection.DOWN -> NitroNumberView.Direction.DOWN
|
|
413
|
+
NitroNumberDirection.AUTO, null -> NitroNumberView.Direction.AUTO
|
|
414
|
+
},
|
|
415
|
+
revealDurationMs = Math.max(0.0, revealDuration ?: 2200.0).toLong(),
|
|
416
|
+
revealBounce = (revealBounce ?: 0.12).coerceIn(0.0, 1.0),
|
|
417
|
+
revealGrow = (revealGrow ?: 0.2).coerceIn(0.0, 1.0),
|
|
418
|
+
revealStyle = when (revealStyle) {
|
|
419
|
+
NitroNumberRevealStyle.SPIN -> NitroNumberView.RevealStyle.SPIN
|
|
420
|
+
NitroNumberRevealStyle.COUNT, null -> NitroNumberView.RevealStyle.COUNT
|
|
421
|
+
},
|
|
422
|
+
revealStaggerMs = Math.max(0.0, revealStagger ?: 200.0).toLong(),
|
|
423
|
+
revealMilestoneHoldMs = Math.max(0.0, revealMilestoneHold ?: 0.0).toLong(),
|
|
424
|
+
)
|
|
425
|
+
rollingView.revealMilestones = revealMilestones ?: DoubleArray(0)
|
|
426
|
+
rollingView.shimmer = NitroNumberView.Shimmer(
|
|
427
|
+
color = shimmerColor?.let { colorFromARGB(it) },
|
|
428
|
+
durationMs = Math.max(200.0, shimmerDuration ?: 950.0).toLong(),
|
|
429
|
+
)
|
|
430
|
+
rollingView.flash = NitroNumberView.Flash(
|
|
431
|
+
upColor = flashUpColor?.let { colorFromARGB(it) },
|
|
432
|
+
downColor = flashDownColor?.let { colorFromARGB(it) },
|
|
433
|
+
durationMs = Math.max(50.0, flashDuration ?: 600.0).toLong(),
|
|
434
|
+
)
|
|
435
|
+
rollingView.alignment = when (textAlign) {
|
|
436
|
+
NitroNumberTextAlign.CENTER -> NitroNumberView.Alignment.CENTER
|
|
437
|
+
NitroNumberTextAlign.RIGHT -> NitroNumberView.Alignment.RIGHT
|
|
438
|
+
NitroNumberTextAlign.LEFT -> NitroNumberView.Alignment.LEFT
|
|
439
|
+
NitroNumberTextAlign.AUTO, null -> NitroNumberView.Alignment.AUTO
|
|
440
|
+
}
|
|
441
|
+
// Fabric does not hand a Hybrid View its layout direction, so JS resolves
|
|
442
|
+
// it and the view is told outright; the alignment and the affixes read it back.
|
|
443
|
+
val direction = if (rightToLeft == true) android.view.View.LAYOUT_DIRECTION_RTL else android.view.View.LAYOUT_DIRECTION_LTR
|
|
444
|
+
if (rollingView.layoutDirection != direction) rollingView.layoutDirection = direction
|
|
445
|
+
rollingView.loading = loading ?: false
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// endregion
|
|
449
|
+
|
|
450
|
+
private fun mapAffixAlign(align: NitroNumberAffixAlign?): NitroNumberView.AffixAlign = when (align) {
|
|
451
|
+
NitroNumberAffixAlign.CENTER -> NitroNumberView.AffixAlign.CENTER
|
|
452
|
+
NitroNumberAffixAlign.TOP -> NitroNumberView.AffixAlign.TOP
|
|
453
|
+
NitroNumberAffixAlign.BOTTOM -> NitroNumberView.AffixAlign.BOTTOM
|
|
454
|
+
NitroNumberAffixAlign.BASELINE, null -> NitroNumberView.AffixAlign.BASELINE
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
private fun onMain(block: () -> Unit) {
|
|
458
|
+
if (Looper.myLooper() == Looper.getMainLooper()) block() else mainHandler.post(block)
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
private fun clampInt(value: Double?, lower: Int, upper: Int, fallback: Int): Int {
|
|
462
|
+
if (value == null || !value.isFinite()) return fallback
|
|
463
|
+
return Math.rint(value).toInt().coerceIn(lower, upper)
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
private fun colorFromARGB(value: Double): Int? {
|
|
467
|
+
if (!value.isFinite()) return null
|
|
468
|
+
val bits = value.toLong().toInt()
|
|
469
|
+
return Color.argb((bits ushr 24) and 0xff, (bits ushr 16) and 0xff, (bits ushr 8) and 0xff, bits and 0xff)
|
|
470
|
+
}
|
|
471
|
+
}
|
|
@@ -6,6 +6,7 @@ import com.facebook.react.bridge.ReactApplicationContext
|
|
|
6
6
|
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
|
+
import com.margelo.nitro.nitroinput.views.HybridNitroNumberViewManager
|
|
9
10
|
|
|
10
11
|
class NitroInputPackage : BaseReactPackage() {
|
|
11
12
|
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? = null
|
|
@@ -13,7 +14,7 @@ class NitroInputPackage : BaseReactPackage() {
|
|
|
13
14
|
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider = ReactModuleInfoProvider { HashMap() }
|
|
14
15
|
|
|
15
16
|
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
16
|
-
return listOf(HybridNitroInputViewManager())
|
|
17
|
+
return listOf(HybridNitroInputViewManager(), HybridNitroNumberViewManager())
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
companion object {
|
|
@@ -43,10 +43,10 @@ import kotlin.math.min
|
|
|
43
43
|
import kotlin.math.roundToInt
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
|
-
* The
|
|
46
|
+
* The reflowing input. A hidden [AppCompatEditText] filling the bounds owns the
|
|
47
47
|
* keyboard, editing, selection, paste and accessibility; an overlay on top
|
|
48
|
-
* draws the glyphs the shared C++ `
|
|
49
|
-
* [
|
|
48
|
+
* draws the glyphs the shared C++ `ReflowEngine` reports (through the
|
|
49
|
+
* [ReflowEngine] JNI handle) plus our own caret. In number mode every edit is
|
|
50
50
|
* run through the shared `AmountFormatter` before it is committed, so the
|
|
51
51
|
* field never shows an unformatted frame.
|
|
52
52
|
*
|
|
@@ -173,7 +173,7 @@ class NitroInputView(context: Context) : FrameLayout(context) {
|
|
|
173
173
|
/** `NitroInput`: the EditText draws its own text and the overlay is off. */
|
|
174
174
|
val plain: Boolean = false,
|
|
175
175
|
/**
|
|
176
|
-
* Wrapping field. Always plain and always text - the JS side drops `
|
|
176
|
+
* Wrapping field. Always plain and always text - the JS side drops `transition="reflow"`
|
|
177
177
|
* and any non-text mode before it gets here - so nothing below has to
|
|
178
178
|
* reconcile a wrapped run with the glyph engine.
|
|
179
179
|
*/
|
|
@@ -435,7 +435,7 @@ class NitroInputView(context: Context) : FrameLayout(context) {
|
|
|
435
435
|
var scale = 1f
|
|
436
436
|
}
|
|
437
437
|
|
|
438
|
-
private val engine =
|
|
438
|
+
private val engine = ReflowEngine()
|
|
439
439
|
private val formatter = AmountFormatter()
|
|
440
440
|
private val maskEngine = MaskEngine()
|
|
441
441
|
private val density = context.resources.displayMetrics.density
|
|
@@ -470,7 +470,7 @@ class NitroInputView(context: Context) : FrameLayout(context) {
|
|
|
470
470
|
private var contentWidth = 0f
|
|
471
471
|
private var lastReportedWidth = -1f
|
|
472
472
|
private var lastReportedHeight = -1f
|
|
473
|
-
/** A narrower settled size waiting for the running
|
|
473
|
+
/** A narrower settled size waiting for the running reflow to finish before it is reported. */
|
|
474
474
|
private var pendingSizeReport = false
|
|
475
475
|
private var frameScheduled = false
|
|
476
476
|
private var applying = false
|
|
@@ -627,7 +627,22 @@ class NitroInputView(context: Context) : FrameLayout(context) {
|
|
|
627
627
|
val baselineNudge: Float = (lineHeight - fontLineHeight) / 2f
|
|
628
628
|
private val widthCaches = Array(3) { HashMap<Int, Float>() }
|
|
629
629
|
private val capHeightCache = HashMap<Role, Float>()
|
|
630
|
-
|
|
630
|
+
// By role, then text: a key built from both was a string allocated for
|
|
631
|
+
// every affix glyph on every frame of a reflow.
|
|
632
|
+
private val inkDescentCaches = Array(3) { HashMap<String, Float>() }
|
|
633
|
+
// Each role's metrics, read once: `Paint.fontMetrics` allocates, and the
|
|
634
|
+
// affixes' baselines are asked for on every frame of a reflow.
|
|
635
|
+
private val metrics = arrayOf(prefix.fontMetrics, bodyMetrics, suffix.fontMetrics)
|
|
636
|
+
private val shapedCaches = Array(3) { HashMap<Int, ShapedText>() }
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* One character of [role] shaped once, for [Canvas.drawGlyphs]: `drawText`
|
|
640
|
+
* runs the text shaper on every call, and a reflow draws every glyph on
|
|
641
|
+
* every frame of its animation (see NitroNumberView's `shaped`).
|
|
642
|
+
*/
|
|
643
|
+
@androidx.annotation.RequiresApi(Build.VERSION_CODES.S)
|
|
644
|
+
fun shaped(codePoint: Int, role: Role): ShapedText =
|
|
645
|
+
shapedCaches[role.ordinal].getOrPut(codePoint) { ShapedText.of(charString(codePoint), paint(role)) }
|
|
631
646
|
|
|
632
647
|
fun paint(role: Role): TextPaint = when (role) {
|
|
633
648
|
Role.BODY -> body
|
|
@@ -659,8 +674,7 @@ class NitroInputView(context: Context) : FrameLayout(context) {
|
|
|
659
674
|
// centres in the line box itself, which is already the new height.
|
|
660
675
|
val bodyBaseline = lineTop + baselineNudge - bodyMetrics.ascent
|
|
661
676
|
if (role == Role.BODY) return bodyBaseline
|
|
662
|
-
val
|
|
663
|
-
val m = p.fontMetrics
|
|
677
|
+
val m = metrics[role.ordinal]
|
|
664
678
|
return when (if (role == Role.PREFIX) prefixAlign else suffixAlign) {
|
|
665
679
|
AffixAlign.BASELINE -> bodyBaseline
|
|
666
680
|
AffixAlign.CENTER -> lineTop + (lineHeight - (m.descent - m.ascent)) / 2f - m.ascent
|
|
@@ -673,7 +687,7 @@ class NitroInputView(context: Context) : FrameLayout(context) {
|
|
|
673
687
|
}
|
|
674
688
|
|
|
675
689
|
/** How far `text`'s ink hangs below the baseline (0 for digits and capitals). */
|
|
676
|
-
private fun inkDescent(text: String, role: Role): Float =
|
|
690
|
+
private fun inkDescent(text: String, role: Role): Float = inkDescentCaches[role.ordinal].getOrPut(text) {
|
|
677
691
|
val bounds = Rect()
|
|
678
692
|
paint(role).getTextBounds(text, 0, text.length, bounds)
|
|
679
693
|
max(0, bounds.bottom).toFloat()
|
|
@@ -1123,7 +1137,7 @@ class NitroInputView(context: Context) : FrameLayout(context) {
|
|
|
1123
1137
|
inputMethodManager()?.hideSoftInputFromWindow(editText.windowToken, 0)
|
|
1124
1138
|
}
|
|
1125
1139
|
|
|
1126
|
-
/** Empties the field,
|
|
1140
|
+
/** Empties the field, reflowing the characters away. */
|
|
1127
1141
|
fun clear() = setProgrammatic("", notify = true)
|
|
1128
1142
|
|
|
1129
1143
|
/** Replaces the text (formatted in number mode), caret at the end. */
|
|
@@ -1640,7 +1654,7 @@ class NitroInputView(context: Context) : FrameLayout(context) {
|
|
|
1640
1654
|
}
|
|
1641
1655
|
|
|
1642
1656
|
/**
|
|
1643
|
-
* The width the content asks for: the engine's layout in
|
|
1657
|
+
* The width the content asks for: the engine's layout in reflow mode; in plain
|
|
1644
1658
|
* mode, which never feeds the engine, the text (or the hint) and the affixes
|
|
1645
1659
|
* measured with the paints the field draws them in.
|
|
1646
1660
|
*/
|
|
@@ -1666,7 +1680,7 @@ class NitroInputView(context: Context) : FrameLayout(context) {
|
|
|
1666
1680
|
return
|
|
1667
1681
|
}
|
|
1668
1682
|
// Growing: report right away so React widens the box before the new glyph
|
|
1669
|
-
// has arrived. Shrinking mid-
|
|
1683
|
+
// has arrived. Shrinking mid-reflow: keep the wider box until the reflow has
|
|
1670
1684
|
// finished, otherwise adjustsFontSizeToFit would squeeze the leaving glyphs.
|
|
1671
1685
|
if (lastReportedWidth > 0f && widthDp < lastReportedWidth && engine.isAnimating()) {
|
|
1672
1686
|
pendingSizeReport = true
|
|
@@ -1749,6 +1763,9 @@ class NitroInputView(context: Context) : FrameLayout(context) {
|
|
|
1749
1763
|
return out
|
|
1750
1764
|
}
|
|
1751
1765
|
|
|
1766
|
+
/** Scratch for [ShapedText.draw], grown on demand. */
|
|
1767
|
+
private var glyphPositions = FloatArray(8)
|
|
1768
|
+
|
|
1752
1769
|
private fun drawContent(canvas: Canvas, view: View) {
|
|
1753
1770
|
syncFromEngine()
|
|
1754
1771
|
val f = fonts
|
|
@@ -1778,7 +1795,7 @@ class NitroInputView(context: Context) : FrameLayout(context) {
|
|
|
1778
1795
|
val base = if (g.placeholder) placeholderColor else textColor
|
|
1779
1796
|
paint.color = base
|
|
1780
1797
|
// The hint colour carries its own alpha — the platform's is translucent
|
|
1781
|
-
// black, not grey. Multiply the
|
|
1798
|
+
// black, not grey. Multiply the reflow's opacity into it rather than
|
|
1782
1799
|
// replacing it, or the placeholder is drawn solid.
|
|
1783
1800
|
val alpha = (Color.alpha(base) * g.opacity).roundToInt().coerceIn(0, 255)
|
|
1784
1801
|
if (alpha == 0) continue
|
|
@@ -1793,7 +1810,12 @@ class NitroInputView(context: Context) : FrameLayout(context) {
|
|
|
1793
1810
|
canvas.clipRect(-1e5f, -band, 1e5f, lineHeight + band)
|
|
1794
1811
|
}
|
|
1795
1812
|
if (g.scale != 1f) canvas.scale(g.scale, g.scale, g.x + g.width / 2f, lineHeight / 2f)
|
|
1796
|
-
|
|
1813
|
+
val baseline = f.baseline(role, str, 0f) + g.y * lineHeight
|
|
1814
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
1815
|
+
glyphPositions = f.shaped(g.character, role).draw(canvas, g.x, baseline, paint, glyphPositions)
|
|
1816
|
+
} else {
|
|
1817
|
+
canvas.drawText(str, g.x, baseline, paint)
|
|
1818
|
+
}
|
|
1797
1819
|
canvas.restore()
|
|
1798
1820
|
}
|
|
1799
1821
|
|
|
@@ -1918,7 +1940,7 @@ class NitroInputView(context: Context) : FrameLayout(context) {
|
|
|
1918
1940
|
}
|
|
1919
1941
|
|
|
1920
1942
|
/**
|
|
1921
|
-
* Runs the label to where it belongs. The
|
|
1943
|
+
* Runs the label to where it belongs. The reflow glyphs are laid out against
|
|
1922
1944
|
* the insets, and the placeholder appears only once the label is clear of it,
|
|
1923
1945
|
* so a change re-feeds the engine as well as redrawing.
|
|
1924
1946
|
*/
|