react-native-typerich 0.1.11 → 0.1.13

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.
@@ -45,7 +45,6 @@ class TypeRichTextInputView : AppCompatEditText {
45
45
  lateinit var layoutManager: TypeRichTextInputViewLayoutManager
46
46
 
47
47
  var isDuringTransaction: Boolean = false
48
- var isRemovingMany: Boolean = false
49
48
  var scrollEnabled: Boolean = true
50
49
 
51
50
  var experimentalSynchronousEvents: Boolean = false
@@ -60,10 +59,11 @@ class TypeRichTextInputView : AppCompatEditText {
60
59
  private var fontWeight: Int = ReactConstants.UNSET
61
60
  private var defaultValue: CharSequence? = null
62
61
  private var defaultValueDirty: Boolean = false
63
- private var keyboardAppearance: String = "default"
62
+ // private var keyboardAppearance: String = "default" // used in ios only
64
63
  private var inputMethodManager: InputMethodManager? = null
65
64
  private var lineHeightPx: Int? = null
66
65
  private var isSettingTextFromJS = false
66
+ private var isInitialized = false
67
67
 
68
68
 
69
69
  constructor(context: Context) : super(context) {
@@ -106,8 +106,14 @@ class TypeRichTextInputView : AppCompatEditText {
106
106
  override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) { if (isSettingTextFromJS) return}
107
107
 
108
108
  override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
109
- if (!isDuringTransaction) {
110
- if (isSettingTextFromJS) return
109
+ if (isSettingTextFromJS) return
110
+
111
+ if (!isInitialized) {
112
+ layoutManager.invalidateLayout()
113
+ return
114
+ }
115
+
116
+ if (!isDuringTransaction ) {
111
117
 
112
118
  val reactContext = context as ReactContext
113
119
  val surfaceId = UIManagerHelper.getSurfaceId(reactContext)
@@ -211,7 +217,12 @@ class TypeRichTextInputView : AppCompatEditText {
211
217
 
212
218
  // text
213
219
  val text = item.coerceToText(context).toString()
214
- this.append(text)
220
+ val editable = editableText
221
+ val start = selectionStart.coerceAtLeast(0)
222
+ val end = selectionEnd.coerceAtLeast(0)
223
+
224
+ editable.replace(minOf(start, end), maxOf(start, end), text)
225
+
215
226
  return true
216
227
  }
217
228
 
@@ -290,6 +301,7 @@ class TypeRichTextInputView : AppCompatEditText {
290
301
 
291
302
  override fun onSelectionChanged(selStart: Int, selEnd: Int) {
292
303
  super.onSelectionChanged(selStart, selEnd)
304
+ if (isDuringTransaction) return
293
305
 
294
306
  val reactContext = context as? ReactContext ?: return
295
307
  val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, id)
@@ -541,6 +553,8 @@ class TypeRichTextInputView : AppCompatEditText {
541
553
  updateTypeface()
542
554
  updateDefaultValue()
543
555
  applyLineHeight()
556
+
557
+ isInitialized = true
544
558
  }
545
559
 
546
560
  fun setDefaultValue(value: CharSequence?) {
@@ -551,7 +565,7 @@ class TypeRichTextInputView : AppCompatEditText {
551
565
  private fun updateDefaultValue() {
552
566
  if (!defaultValueDirty) return
553
567
  defaultValueDirty = false
554
- setText(defaultValue?.toString() ?: "")
568
+ setValue(defaultValue)
555
569
  }
556
570
 
557
571
  private fun updateTypeface() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-typerich",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "Textinput replacement",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",