react-native-advanced-text 0.1.16 → 0.1.18
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/android/src/main/java/com/advancedtext/AdvancedTextView.kt +95 -129
- package/android/src/main/java/com/advancedtext/AdvancedTextViewManager.kt +40 -13
- package/lib/module/AdvancedText.js +6 -1
- package/lib/module/AdvancedText.js.map +1 -1
- package/lib/module/AdvancedTextViewNativeComponent.ts +7 -5
- package/lib/typescript/src/AdvancedText.d.ts +13 -9
- package/lib/typescript/src/AdvancedText.d.ts.map +1 -1
- package/lib/typescript/src/AdvancedTextViewNativeComponent.d.ts +5 -2
- package/lib/typescript/src/AdvancedTextViewNativeComponent.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/AdvancedText.tsx +24 -8
- package/src/AdvancedTextViewNativeComponent.ts +7 -5
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// File: AdvancedTextView.kt
|
|
1
2
|
package com.advancedtext
|
|
2
3
|
|
|
3
4
|
import android.content.Context
|
|
@@ -29,32 +30,32 @@ class AdvancedTextView : TextView {
|
|
|
29
30
|
private var menuOptions: List<String> = emptyList()
|
|
30
31
|
private var indicatorWordIndex: Int = -1
|
|
31
32
|
private var lastSelectedText: String = ""
|
|
32
|
-
private var isSelectionEnabled: Boolean = true
|
|
33
33
|
private var customActionMode: ActionMode? = null
|
|
34
|
+
private var currentText: String = ""
|
|
35
|
+
|
|
36
|
+
// Cache for word positions to avoid recalculating
|
|
37
|
+
private var wordPositions: List<WordPosition> = emptyList()
|
|
34
38
|
|
|
35
39
|
constructor(context: Context?) : super(context) { init() }
|
|
36
40
|
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) { init() }
|
|
37
41
|
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { init() }
|
|
38
42
|
|
|
39
|
-
|
|
43
|
+
private fun init() {
|
|
40
44
|
Log.d(TAG, "AdvancedTextView initialized")
|
|
41
45
|
|
|
42
|
-
// Set default
|
|
46
|
+
// Set default properties
|
|
43
47
|
textSize = 16f
|
|
44
48
|
setPadding(16, 16, 16, 16)
|
|
45
|
-
|
|
46
49
|
movementMethod = LinkMovementMethod.getInstance()
|
|
47
50
|
setTextIsSelectable(true)
|
|
48
51
|
|
|
49
52
|
customSelectionActionModeCallback = object : ActionMode.Callback {
|
|
50
53
|
override fun onCreateActionMode(mode: ActionMode?, menu: Menu?): Boolean {
|
|
51
|
-
Log.d(TAG, "onCreateActionMode triggered")
|
|
52
54
|
customActionMode = mode
|
|
53
55
|
return true
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
override fun onPrepareActionMode(mode: ActionMode?, menu: Menu?): Boolean {
|
|
57
|
-
Log.d(TAG, "onPrepareActionMode triggered")
|
|
58
59
|
menu?.clear()
|
|
59
60
|
|
|
60
61
|
val selectionStart = selectionStart
|
|
@@ -62,8 +63,6 @@ class AdvancedTextView : TextView {
|
|
|
62
63
|
|
|
63
64
|
if (selectionStart >= 0 && selectionEnd >= 0 && selectionStart != selectionEnd) {
|
|
64
65
|
lastSelectedText = text.subSequence(selectionStart, selectionEnd).toString()
|
|
65
|
-
Log.d(TAG, "User selected text: '$lastSelectedText'")
|
|
66
|
-
Log.d(TAG, "Menu options available: $menuOptions")
|
|
67
66
|
|
|
68
67
|
menuOptions.forEachIndexed { index, option ->
|
|
69
68
|
menu?.add(0, index, index, option)
|
|
@@ -78,7 +77,6 @@ class AdvancedTextView : TextView {
|
|
|
78
77
|
override fun onActionItemClicked(mode: ActionMode?, item: MenuItem?): Boolean {
|
|
79
78
|
item?.let {
|
|
80
79
|
val menuItemText = it.title.toString()
|
|
81
|
-
Log.d(TAG, "Menu item clicked: $menuItemText")
|
|
82
80
|
sendSelectionEvent(lastSelectedText, menuItemText)
|
|
83
81
|
mode?.finish()
|
|
84
82
|
return true
|
|
@@ -87,133 +85,119 @@ class AdvancedTextView : TextView {
|
|
|
87
85
|
}
|
|
88
86
|
|
|
89
87
|
override fun onDestroyActionMode(mode: ActionMode?) {
|
|
90
|
-
Log.d(TAG, "onDestroyActionMode")
|
|
91
88
|
customActionMode = null
|
|
92
89
|
}
|
|
93
90
|
}
|
|
94
91
|
}
|
|
95
92
|
|
|
96
93
|
fun setAdvancedText(text: String) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
94
|
+
if (currentText == text) {
|
|
95
|
+
Log.d(TAG, "Text unchanged, skipping update")
|
|
96
|
+
return
|
|
97
|
+
}
|
|
101
98
|
|
|
102
|
-
|
|
99
|
+
Log.d(TAG, "setAdvancedText: length=${text.length}")
|
|
100
|
+
currentText = text
|
|
101
|
+
calculateWordPositions(text)
|
|
103
102
|
updateTextWithHighlights()
|
|
104
|
-
|
|
105
|
-
// Force layout update
|
|
106
|
-
requestLayout()
|
|
107
|
-
invalidate()
|
|
108
103
|
}
|
|
109
104
|
|
|
110
105
|
fun setMenuOptions(menuOptions: List<String>) {
|
|
111
|
-
|
|
106
|
+
if (this.menuOptions == menuOptions) return
|
|
112
107
|
this.menuOptions = menuOptions
|
|
113
108
|
}
|
|
114
109
|
|
|
115
110
|
fun setHighlightedWords(highlightedWords: List<HighlightedWord>) {
|
|
116
|
-
|
|
111
|
+
if (this.highlightedWords == highlightedWords) return
|
|
117
112
|
this.highlightedWords = highlightedWords
|
|
118
113
|
updateTextWithHighlights()
|
|
119
114
|
}
|
|
120
115
|
|
|
121
116
|
fun setIndicatorWordIndex(index: Int) {
|
|
122
|
-
|
|
117
|
+
if (this.indicatorWordIndex == index) return
|
|
123
118
|
this.indicatorWordIndex = index
|
|
124
119
|
updateTextWithHighlights()
|
|
125
120
|
}
|
|
126
121
|
|
|
127
|
-
private fun
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
Log.d(TAG, "Current text: $textValue")
|
|
131
|
-
Log.d(TAG, "Highlighted words: $highlightedWords")
|
|
132
|
-
Log.d(TAG, "Indicator index: $indicatorWordIndex")
|
|
133
|
-
|
|
134
|
-
if (textValue.isEmpty()) {
|
|
135
|
-
Log.d(TAG, "No text available, skipping")
|
|
122
|
+
private fun calculateWordPositions(text: String) {
|
|
123
|
+
if (text.isEmpty()) {
|
|
124
|
+
wordPositions = emptyList()
|
|
136
125
|
return
|
|
137
126
|
}
|
|
138
127
|
|
|
139
|
-
val
|
|
128
|
+
val positions = mutableListOf<WordPosition>()
|
|
129
|
+
val regex = "\\S+".toRegex()
|
|
140
130
|
|
|
141
|
-
|
|
142
|
-
|
|
131
|
+
regex.findAll(text).forEachIndexed { index, match ->
|
|
132
|
+
positions.add(WordPosition(
|
|
133
|
+
index = index,
|
|
134
|
+
start = match.range.first,
|
|
135
|
+
end = match.range.last + 1,
|
|
136
|
+
word = match.value
|
|
137
|
+
))
|
|
138
|
+
}
|
|
143
139
|
|
|
144
|
-
|
|
145
|
-
|
|
140
|
+
wordPositions = positions
|
|
141
|
+
Log.d(TAG, "Calculated ${wordPositions.size} word positions")
|
|
142
|
+
}
|
|
146
143
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
144
|
+
private fun updateTextWithHighlights() {
|
|
145
|
+
if (currentText.isEmpty()) {
|
|
146
|
+
Log.d(TAG, "No text available, skipping")
|
|
147
|
+
return
|
|
148
|
+
}
|
|
151
149
|
|
|
152
|
-
|
|
150
|
+
val spannableString = SpannableString(currentText)
|
|
153
151
|
|
|
154
|
-
|
|
152
|
+
// Apply spans efficiently
|
|
153
|
+
wordPositions.forEach { wordPos ->
|
|
154
|
+
// Apply highlights
|
|
155
|
+
highlightedWords.find { it.index == wordPos.index }?.let { highlightedWord ->
|
|
156
|
+
val color = parseColor(highlightedWord.highlightColor)
|
|
155
157
|
spannableString.setSpan(
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
158
|
+
BackgroundColorSpan(color),
|
|
159
|
+
wordPos.start,
|
|
160
|
+
wordPos.end,
|
|
159
161
|
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
|
|
160
162
|
)
|
|
161
|
-
|
|
162
|
-
// Then apply background color for highlighted words
|
|
163
|
-
highlightedWords.find { it.index == wordIndex }?.let { highlightedWord ->
|
|
164
|
-
val color = try {
|
|
165
|
-
Color.parseColor(highlightedWord.highlightColor)
|
|
166
|
-
} catch (e: IllegalArgumentException) {
|
|
167
|
-
Log.e(TAG, "Invalid color: ${highlightedWord.highlightColor}, using yellow")
|
|
168
|
-
Color.YELLOW
|
|
169
|
-
}
|
|
170
|
-
Log.d(TAG, "Applying highlight to word '$word' at index $wordIndex with color ${highlightedWord.highlightColor}")
|
|
171
|
-
|
|
172
|
-
spannableString.setSpan(
|
|
173
|
-
BackgroundColorSpan(color),
|
|
174
|
-
wordStart,
|
|
175
|
-
wordEnd,
|
|
176
|
-
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
|
|
177
|
-
)
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// Then apply indicator span
|
|
181
|
-
if (wordIndex == indicatorWordIndex) {
|
|
182
|
-
Log.d(TAG, "Applying indicator span to word '$word' at index $wordIndex")
|
|
183
|
-
|
|
184
|
-
spannableString.setSpan(
|
|
185
|
-
IndicatorSpan(),
|
|
186
|
-
wordStart,
|
|
187
|
-
wordEnd,
|
|
188
|
-
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
|
|
189
|
-
)
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
currentIndex = wordEnd
|
|
193
163
|
}
|
|
194
|
-
}
|
|
195
164
|
|
|
196
|
-
|
|
197
|
-
|
|
165
|
+
// Apply indicator color
|
|
166
|
+
if (wordPos.index == indicatorWordIndex) {
|
|
167
|
+
spannableString.setSpan(
|
|
168
|
+
ForegroundColorSpan(Color.RED),
|
|
169
|
+
wordPos.start,
|
|
170
|
+
wordPos.end,
|
|
171
|
+
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
|
|
172
|
+
)
|
|
173
|
+
}
|
|
198
174
|
|
|
199
|
-
|
|
200
|
-
|
|
175
|
+
// Make words clickable
|
|
176
|
+
spannableString.setSpan(
|
|
177
|
+
WordClickableSpan(wordPos.index, wordPos.word),
|
|
178
|
+
wordPos.start,
|
|
179
|
+
wordPos.end,
|
|
180
|
+
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
|
|
181
|
+
)
|
|
182
|
+
}
|
|
201
183
|
|
|
202
|
-
|
|
184
|
+
// Use post to ensure UI thread and avoid layout issues
|
|
185
|
+
post {
|
|
186
|
+
setText(spannableString, BufferType.SPANNABLE)
|
|
187
|
+
Log.d(TAG, "Text updated with ${wordPositions.size} spans")
|
|
188
|
+
}
|
|
203
189
|
}
|
|
204
190
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
191
|
+
private fun parseColor(colorString: String): Int {
|
|
192
|
+
return try {
|
|
193
|
+
Color.parseColor(colorString)
|
|
194
|
+
} catch (e: IllegalArgumentException) {
|
|
195
|
+
Log.e(TAG, "Invalid color: $colorString, using yellow")
|
|
196
|
+
Color.YELLOW
|
|
197
|
+
}
|
|
212
198
|
}
|
|
213
199
|
|
|
214
200
|
private fun sendSelectionEvent(selectedText: String, eventType: String) {
|
|
215
|
-
Log.d(TAG, "sendSelectionEvent -> eventType='$eventType' selectedText='$selectedText'")
|
|
216
|
-
|
|
217
201
|
try {
|
|
218
202
|
val reactContext = context as? ReactContext ?: return
|
|
219
203
|
val event = Arguments.createMap().apply {
|
|
@@ -229,43 +213,28 @@ class AdvancedTextView : TextView {
|
|
|
229
213
|
}
|
|
230
214
|
|
|
231
215
|
private inner class WordClickableSpan(
|
|
232
|
-
|
|
233
|
-
|
|
216
|
+
private val wordIndex: Int,
|
|
217
|
+
private val word: String
|
|
234
218
|
) : ClickableSpan() {
|
|
235
219
|
|
|
236
220
|
override fun onClick(widget: View) {
|
|
237
|
-
Log.d(TAG, "
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
221
|
+
Log.d(TAG, "Word clicked: '$word' (index=$wordIndex)")
|
|
222
|
+
val spannable = widget as? TextView
|
|
223
|
+
spannable?.text?.let {
|
|
224
|
+
if (it is android.text.Spannable) {
|
|
225
|
+
Selection.removeSelection(it)
|
|
226
|
+
}
|
|
242
227
|
}
|
|
228
|
+
sendWordPressEvent(word, wordIndex)
|
|
243
229
|
}
|
|
244
230
|
|
|
245
231
|
override fun updateDrawState(ds: TextPaint) {
|
|
246
|
-
|
|
247
|
-
// Keep the original text appearance
|
|
248
|
-
|
|
249
|
-
ds.isUnderlineText = false
|
|
250
|
-
ds.bgColor = Color.TRANSPARENT
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
private inner class IndicatorSpan : ClickableSpan() {
|
|
255
|
-
override fun onClick(widget: View) {
|
|
256
|
-
Log.d(TAG, "IndicatorSpan clicked (shouldn't trigger action)")
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
override fun updateDrawState(ds: TextPaint) {
|
|
260
|
-
|
|
261
|
-
ds.isFakeBoldText = true
|
|
232
|
+
super.updateDrawState(ds)
|
|
262
233
|
ds.isUnderlineText = false
|
|
263
234
|
}
|
|
264
235
|
}
|
|
265
236
|
|
|
266
237
|
private fun sendWordPressEvent(word: String, index: Int) {
|
|
267
|
-
Log.d(TAG, "sendWordPressEvent -> word='$word', index=$index")
|
|
268
|
-
|
|
269
238
|
try {
|
|
270
239
|
val reactContext = context as? ReactContext ?: return
|
|
271
240
|
val event = Arguments.createMap().apply {
|
|
@@ -281,20 +250,17 @@ class AdvancedTextView : TextView {
|
|
|
281
250
|
}
|
|
282
251
|
|
|
283
252
|
fun clearSelection() {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
|
290
|
-
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
|
291
|
-
Log.d(TAG, "onMeasure: width=${measuredWidth}, height=${measuredHeight}")
|
|
253
|
+
(text as? android.text.Spannable)?.let {
|
|
254
|
+
Selection.removeSelection(it)
|
|
255
|
+
}
|
|
292
256
|
}
|
|
293
257
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
258
|
+
data class WordPosition(
|
|
259
|
+
val index: Int,
|
|
260
|
+
val start: Int,
|
|
261
|
+
val end: Int,
|
|
262
|
+
val word: String
|
|
263
|
+
)
|
|
298
264
|
}
|
|
299
265
|
|
|
300
266
|
data class HighlightedWord(
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// File: AdvancedTextViewManager.kt
|
|
2
|
-
// This should be the ONLY content in this file
|
|
3
2
|
package com.advancedtext
|
|
4
3
|
|
|
4
|
+
import android.graphics.Color
|
|
5
|
+
import android.util.TypedValue
|
|
5
6
|
import android.view.ViewGroup
|
|
6
7
|
import com.facebook.react.bridge.ReadableArray
|
|
7
8
|
import com.facebook.react.module.annotations.ReactModule
|
|
@@ -11,10 +12,12 @@ import com.facebook.react.uimanager.ViewManagerDelegate
|
|
|
11
12
|
import com.facebook.react.uimanager.annotations.ReactProp
|
|
12
13
|
import com.facebook.react.viewmanagers.AdvancedTextViewManagerInterface
|
|
13
14
|
import com.facebook.react.viewmanagers.AdvancedTextViewManagerDelegate
|
|
15
|
+
import com.facebook.react.uimanager.PixelUtil
|
|
14
16
|
|
|
15
17
|
@ReactModule(name = AdvancedTextViewManager.NAME)
|
|
16
18
|
class AdvancedTextViewManager : SimpleViewManager<AdvancedTextView>(),
|
|
17
19
|
AdvancedTextViewManagerInterface<AdvancedTextView> {
|
|
20
|
+
|
|
18
21
|
private val mDelegate: ViewManagerDelegate<AdvancedTextView>
|
|
19
22
|
|
|
20
23
|
init {
|
|
@@ -31,26 +34,33 @@ class AdvancedTextViewManager : SimpleViewManager<AdvancedTextView>(),
|
|
|
31
34
|
|
|
32
35
|
public override fun createViewInstance(context: ThemedReactContext): AdvancedTextView {
|
|
33
36
|
val view = AdvancedTextView(context)
|
|
34
|
-
// Set default layout params to ensure the view is visible
|
|
35
37
|
view.layoutParams = ViewGroup.LayoutParams(
|
|
36
38
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
|
37
39
|
ViewGroup.LayoutParams.WRAP_CONTENT
|
|
38
40
|
)
|
|
41
|
+
// Set default text color to black to ensure visibility
|
|
42
|
+
view.setTextColor(Color.BLACK)
|
|
39
43
|
return view
|
|
40
44
|
}
|
|
41
45
|
|
|
42
46
|
@ReactProp(name = "text")
|
|
43
47
|
override fun setText(view: AdvancedTextView?, text: String?) {
|
|
48
|
+
android.util.Log.d("AdvancedTextViewManager", "setText called with: '$text'")
|
|
44
49
|
view?.setAdvancedText(text ?: "")
|
|
45
50
|
}
|
|
46
51
|
|
|
47
52
|
@ReactProp(name = "highlightedWords")
|
|
48
53
|
override fun setHighlightedWords(view: AdvancedTextView?, highlightedWords: ReadableArray?) {
|
|
54
|
+
if (highlightedWords == null) {
|
|
55
|
+
view?.setHighlightedWords(emptyList())
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
|
|
49
59
|
val words = mutableListOf<HighlightedWord>()
|
|
50
|
-
highlightedWords
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
60
|
+
for (i in 0 until highlightedWords.size()) {
|
|
61
|
+
val map = highlightedWords.getMap(i)
|
|
62
|
+
map?.let { wordMap ->
|
|
63
|
+
if (wordMap.hasKey("index") && wordMap.hasKey("highlightColor")) {
|
|
54
64
|
words.add(
|
|
55
65
|
HighlightedWord(
|
|
56
66
|
index = wordMap.getInt("index"),
|
|
@@ -65,12 +75,15 @@ class AdvancedTextViewManager : SimpleViewManager<AdvancedTextView>(),
|
|
|
65
75
|
|
|
66
76
|
@ReactProp(name = "menuOptions")
|
|
67
77
|
override fun setMenuOptions(view: AdvancedTextView?, menuOptions: ReadableArray?) {
|
|
78
|
+
if (menuOptions == null) {
|
|
79
|
+
view?.setMenuOptions(emptyList())
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
|
|
68
83
|
val options = mutableListOf<String>()
|
|
69
|
-
menuOptions
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
options.add(option)
|
|
73
|
-
}
|
|
84
|
+
for (i in 0 until menuOptions.size()) {
|
|
85
|
+
menuOptions.getString(i)?.let { option ->
|
|
86
|
+
options.add(option)
|
|
74
87
|
}
|
|
75
88
|
}
|
|
76
89
|
view?.setMenuOptions(options)
|
|
@@ -78,10 +91,24 @@ class AdvancedTextViewManager : SimpleViewManager<AdvancedTextView>(),
|
|
|
78
91
|
|
|
79
92
|
@ReactProp(name = "indicatorWordIndex")
|
|
80
93
|
override fun setIndicatorWordIndex(view: AdvancedTextView?, index: Int) {
|
|
81
|
-
view?.setIndicatorWordIndex(index)
|
|
94
|
+
view?.setIndicatorWordIndex(if (index >= 0) index else -1)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@ReactProp(name = "color", customType = "Color")
|
|
98
|
+
fun setColor(view: AdvancedTextView?, color: Int?) {
|
|
99
|
+
android.util.Log.d("AdvancedTextViewManager", "setColor called with: $color")
|
|
100
|
+
view?.setTextColor(color ?: Color.BLACK)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
@ReactProp(name = "fontSize")
|
|
104
|
+
fun setFontSize(view: AdvancedTextView?, fontSize: Float) {
|
|
105
|
+
android.util.Log.d("AdvancedTextViewManager", "setFontSize called with: $fontSize")
|
|
106
|
+
if (fontSize > 0) {
|
|
107
|
+
// Convert from React Native points to Android pixels
|
|
108
|
+
view?.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSize)
|
|
109
|
+
}
|
|
82
110
|
}
|
|
83
111
|
|
|
84
|
-
// Add this method to register custom events
|
|
85
112
|
override fun getExportedCustomDirectEventTypeConstants(): Map<String, Any> {
|
|
86
113
|
return mapOf(
|
|
87
114
|
"onWordPress" to mapOf("registrationName" to "onWordPress"),
|
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
import React from 'react';
|
|
3
4
|
import AdvancedTextViewNativeComponent from './AdvancedTextViewNativeComponent';
|
|
4
5
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
6
|
export const AdvancedText = ({
|
|
6
7
|
text,
|
|
8
|
+
style,
|
|
7
9
|
highlightedWords,
|
|
8
10
|
menuOptions,
|
|
9
11
|
onWordPress,
|
|
10
12
|
onSelection,
|
|
11
|
-
indicatorWordIndex
|
|
13
|
+
indicatorWordIndex,
|
|
14
|
+
...restProps
|
|
12
15
|
}) => {
|
|
13
16
|
return /*#__PURE__*/_jsx(AdvancedTextViewNativeComponent, {
|
|
17
|
+
...restProps,
|
|
18
|
+
style: style,
|
|
14
19
|
text: text,
|
|
15
20
|
highlightedWords: highlightedWords,
|
|
16
21
|
menuOptions: menuOptions,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["AdvancedTextViewNativeComponent","jsx","_jsx","AdvancedText","text","highlightedWords","menuOptions","onWordPress","onSelection","indicatorWordIndex"],"sourceRoot":"..\\..\\src","sources":["AdvancedText.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"names":["React","AdvancedTextViewNativeComponent","jsx","_jsx","AdvancedText","text","style","highlightedWords","menuOptions","onWordPress","onSelection","indicatorWordIndex","restProps"],"sourceRoot":"..\\..\\src","sources":["AdvancedText.tsx"],"mappings":";;AAAA,OAAOA,KAAK,MAAM,OAAO;AAOzB,OAAOC,+BAA+B,MAAM,mCAAmC;AAAC,SAAAC,GAAA,IAAAC,IAAA;AA2BhF,OAAO,MAAMC,YAAmC,GAAGA,CAAC;EAClDC,IAAI;EACJC,KAAK;EACLC,gBAAgB;EAChBC,WAAW;EACXC,WAAW;EACXC,WAAW;EACXC,kBAAkB;EAClB,GAAGC;AACL,CAAC,KAAK;EACJ,oBACET,IAAA,CAACF,+BAA+B;IAAA,GAC1BW,SAAS;IACbN,KAAK,EAAEA,KAAM;IACbD,IAAI,EAAEA,IAAK;IACXE,gBAAgB,EAAEA,gBAAiB;IACnCC,WAAW,EAAEA,WAAY;IACzBC,WAAW,EAAEA,WAAY;IACzBC,WAAW,EAAEA,WAAY;IACzBC,kBAAkB,EAAEA;EAAmB,CACxC,CAAC;AAEN,CAAC","ignoreList":[]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable prettier/prettier */
|
|
2
2
|
import type { ViewProps } from 'react-native';
|
|
3
|
+
import { codegenNativeComponent } from 'react-native';
|
|
3
4
|
// @ts-ignore
|
|
4
|
-
|
|
5
|
-
import type { DirectEventHandler, Int32 } from 'react-native/Libraries/Types/CodegenTypes';
|
|
5
|
+
import type { DirectEventHandler, Float, Int32} from 'react-native/Libraries/Types/CodegenTypes';
|
|
6
6
|
|
|
7
7
|
interface HighlightedWord {
|
|
8
8
|
index: Int32;
|
|
@@ -13,9 +13,11 @@ interface NativeProps extends ViewProps {
|
|
|
13
13
|
text: string;
|
|
14
14
|
highlightedWords?: ReadonlyArray<HighlightedWord>;
|
|
15
15
|
menuOptions?: ReadonlyArray<string>;
|
|
16
|
-
onWordPress?: DirectEventHandler<{ word: string }>;
|
|
17
|
-
onSelection?: DirectEventHandler<{ selectedText: string;
|
|
16
|
+
onWordPress?: DirectEventHandler<{ word: string; index: Int32 }>;
|
|
17
|
+
onSelection?: DirectEventHandler<{ selectedText: string; event: string }>;
|
|
18
18
|
indicatorWordIndex?: Int32;
|
|
19
|
+
color?: Int32;
|
|
20
|
+
fontSize?: Float;
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
export default codegenNativeComponent<NativeProps>('AdvancedTextView');
|
|
@@ -1,20 +1,24 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { NativeSyntheticEvent, StyleProp, ViewProps, ViewStyle } from 'react-native';
|
|
2
3
|
interface HighlightedWord {
|
|
3
4
|
index: number;
|
|
4
5
|
highlightColor: string;
|
|
5
6
|
}
|
|
7
|
+
interface WordPressEvent {
|
|
8
|
+
word: string;
|
|
9
|
+
index: number;
|
|
10
|
+
}
|
|
11
|
+
interface SelectionEvent {
|
|
12
|
+
selectedText: string;
|
|
13
|
+
event: string;
|
|
14
|
+
}
|
|
6
15
|
interface NativeProps extends ViewProps {
|
|
7
16
|
text: string;
|
|
17
|
+
style?: StyleProp<ViewStyle>;
|
|
8
18
|
highlightedWords?: ReadonlyArray<HighlightedWord>;
|
|
9
19
|
menuOptions?: ReadonlyArray<string>;
|
|
10
|
-
onWordPress?: (event: NativeSyntheticEvent<
|
|
11
|
-
|
|
12
|
-
index: string;
|
|
13
|
-
}>) => void;
|
|
14
|
-
onSelection?: (event: NativeSyntheticEvent<{
|
|
15
|
-
selectedText: string;
|
|
16
|
-
event: string;
|
|
17
|
-
}>) => void;
|
|
20
|
+
onWordPress?: (event: NativeSyntheticEvent<WordPressEvent>) => void;
|
|
21
|
+
onSelection?: (event: NativeSyntheticEvent<SelectionEvent>) => void;
|
|
18
22
|
indicatorWordIndex?: number;
|
|
19
23
|
}
|
|
20
24
|
export declare const AdvancedText: React.FC<NativeProps>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AdvancedText.d.ts","sourceRoot":"","sources":["../../../src/AdvancedText.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"AdvancedText.d.ts","sourceRoot":"","sources":["../../../src/AdvancedText.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EACV,oBAAoB,EACpB,SAAS,EACT,SAAS,EACT,SAAS,EACV,MAAM,cAAc,CAAC;AAGtB,UAAU,eAAe;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,UAAU,cAAc;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,UAAU,cAAc;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,UAAU,WAAY,SAAQ,SAAS;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,gBAAgB,CAAC,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;IAClD,WAAW,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACpC,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,oBAAoB,CAAC,cAAc,CAAC,KAAK,IAAI,CAAC;IACpE,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,oBAAoB,CAAC,cAAc,CAAC,KAAK,IAAI,CAAC;IACpE,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAsB9C,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ViewProps } from 'react-native';
|
|
2
|
-
import type { DirectEventHandler, Int32 } from 'react-native/Libraries/Types/CodegenTypes';
|
|
2
|
+
import type { DirectEventHandler, Float, Int32 } from 'react-native/Libraries/Types/CodegenTypes';
|
|
3
3
|
interface HighlightedWord {
|
|
4
4
|
index: Int32;
|
|
5
5
|
highlightColor: string;
|
|
@@ -10,12 +10,15 @@ interface NativeProps extends ViewProps {
|
|
|
10
10
|
menuOptions?: ReadonlyArray<string>;
|
|
11
11
|
onWordPress?: DirectEventHandler<{
|
|
12
12
|
word: string;
|
|
13
|
+
index: Int32;
|
|
13
14
|
}>;
|
|
14
15
|
onSelection?: DirectEventHandler<{
|
|
15
16
|
selectedText: string;
|
|
16
|
-
|
|
17
|
+
event: string;
|
|
17
18
|
}>;
|
|
18
19
|
indicatorWordIndex?: Int32;
|
|
20
|
+
color?: Int32;
|
|
21
|
+
fontSize?: Float;
|
|
19
22
|
}
|
|
20
23
|
declare const _default: import("react-native/types_generated/Libraries/Utilities/codegenNativeComponent").NativeComponentType<NativeProps>;
|
|
21
24
|
export default _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AdvancedTextViewNativeComponent.d.ts","sourceRoot":"","sources":["../../../src/AdvancedTextViewNativeComponent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAG9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,KAAK,EAAE,MAAM,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"AdvancedTextViewNativeComponent.d.ts","sourceRoot":"","sources":["../../../src/AdvancedTextViewNativeComponent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAG9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,KAAK,EAAE,KAAK,EAAC,MAAM,2CAA2C,CAAC;AAEjG,UAAU,eAAe;IACvB,KAAK,EAAE,KAAK,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,UAAU,WAAY,SAAQ,SAAS;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB,CAAC,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;IAClD,WAAW,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACpC,WAAW,CAAC,EAAE,kBAAkB,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,KAAK,CAAA;KAAE,CAAC,CAAC;IACjE,WAAW,CAAC,EAAE,kBAAkB,CAAC;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC1E,kBAAkB,CAAC,EAAE,KAAK,CAAC;IAC3B,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,QAAQ,CAAC,EAAE,KAAK,CAAC;CAClB;;AAED,wBAAuE"}
|
package/package.json
CHANGED
package/src/AdvancedText.tsx
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type {
|
|
3
|
+
NativeSyntheticEvent,
|
|
4
|
+
StyleProp,
|
|
5
|
+
ViewProps,
|
|
6
|
+
ViewStyle,
|
|
7
|
+
} from 'react-native';
|
|
2
8
|
import AdvancedTextViewNativeComponent from './AdvancedTextViewNativeComponent';
|
|
3
9
|
|
|
4
10
|
interface HighlightedWord {
|
|
@@ -6,30 +12,40 @@ interface HighlightedWord {
|
|
|
6
12
|
highlightColor: string;
|
|
7
13
|
}
|
|
8
14
|
|
|
15
|
+
interface WordPressEvent {
|
|
16
|
+
word: string;
|
|
17
|
+
index: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface SelectionEvent {
|
|
21
|
+
selectedText: string;
|
|
22
|
+
event: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
9
25
|
interface NativeProps extends ViewProps {
|
|
10
26
|
text: string;
|
|
27
|
+
style?: StyleProp<ViewStyle>;
|
|
11
28
|
highlightedWords?: ReadonlyArray<HighlightedWord>;
|
|
12
|
-
|
|
13
29
|
menuOptions?: ReadonlyArray<string>;
|
|
14
|
-
onWordPress?: (
|
|
15
|
-
|
|
16
|
-
) => void;
|
|
17
|
-
onSelection?: (
|
|
18
|
-
event: NativeSyntheticEvent<{ selectedText: string; event: string }>
|
|
19
|
-
) => void;
|
|
30
|
+
onWordPress?: (event: NativeSyntheticEvent<WordPressEvent>) => void;
|
|
31
|
+
onSelection?: (event: NativeSyntheticEvent<SelectionEvent>) => void;
|
|
20
32
|
indicatorWordIndex?: number;
|
|
21
33
|
}
|
|
22
34
|
|
|
23
35
|
export const AdvancedText: React.FC<NativeProps> = ({
|
|
24
36
|
text,
|
|
37
|
+
style,
|
|
25
38
|
highlightedWords,
|
|
26
39
|
menuOptions,
|
|
27
40
|
onWordPress,
|
|
28
41
|
onSelection,
|
|
29
42
|
indicatorWordIndex,
|
|
43
|
+
...restProps
|
|
30
44
|
}) => {
|
|
31
45
|
return (
|
|
32
46
|
<AdvancedTextViewNativeComponent
|
|
47
|
+
{...restProps}
|
|
48
|
+
style={style}
|
|
33
49
|
text={text}
|
|
34
50
|
highlightedWords={highlightedWords}
|
|
35
51
|
menuOptions={menuOptions}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable prettier/prettier */
|
|
2
2
|
import type { ViewProps } from 'react-native';
|
|
3
|
+
import { codegenNativeComponent } from 'react-native';
|
|
3
4
|
// @ts-ignore
|
|
4
|
-
|
|
5
|
-
import type { DirectEventHandler, Int32 } from 'react-native/Libraries/Types/CodegenTypes';
|
|
5
|
+
import type { DirectEventHandler, Float, Int32} from 'react-native/Libraries/Types/CodegenTypes';
|
|
6
6
|
|
|
7
7
|
interface HighlightedWord {
|
|
8
8
|
index: Int32;
|
|
@@ -13,9 +13,11 @@ interface NativeProps extends ViewProps {
|
|
|
13
13
|
text: string;
|
|
14
14
|
highlightedWords?: ReadonlyArray<HighlightedWord>;
|
|
15
15
|
menuOptions?: ReadonlyArray<string>;
|
|
16
|
-
onWordPress?: DirectEventHandler<{ word: string }>;
|
|
17
|
-
onSelection?: DirectEventHandler<{ selectedText: string;
|
|
16
|
+
onWordPress?: DirectEventHandler<{ word: string; index: Int32 }>;
|
|
17
|
+
onSelection?: DirectEventHandler<{ selectedText: string; event: string }>;
|
|
18
18
|
indicatorWordIndex?: Int32;
|
|
19
|
+
color?: Int32;
|
|
20
|
+
fontSize?: Float;
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
export default codegenNativeComponent<NativeProps>('AdvancedTextView');
|