react-native-advanced-text 0.1.18 → 0.1.20
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 +11 -3
- package/android/src/main/java/com/advancedtext/AdvancedTextViewManager.kt +15 -25
- package/lib/module/AdvancedTextViewNativeComponent.ts +1 -3
- package/lib/typescript/src/AdvancedTextViewNativeComponent.d.ts +1 -3
- package/lib/typescript/src/AdvancedTextViewNativeComponent.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/AdvancedTextViewNativeComponent.ts +1 -3
|
@@ -32,6 +32,7 @@ class AdvancedTextView : TextView {
|
|
|
32
32
|
private var lastSelectedText: String = ""
|
|
33
33
|
private var customActionMode: ActionMode? = null
|
|
34
34
|
private var currentText: String = ""
|
|
35
|
+
private var textColor: String = "#000000"
|
|
35
36
|
|
|
36
37
|
// Cache for word positions to avoid recalculating
|
|
37
38
|
private var wordPositions: List<WordPosition> = emptyList()
|
|
@@ -90,6 +91,12 @@ class AdvancedTextView : TextView {
|
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
93
|
|
|
94
|
+
|
|
95
|
+
fun setAdvancedTextColor(colorInt: Int) {
|
|
96
|
+
textColor = String.format("#%06X", 0xFFFFFF and colorInt)
|
|
97
|
+
updateTextWithHighlights()
|
|
98
|
+
}
|
|
99
|
+
|
|
93
100
|
fun setAdvancedText(text: String) {
|
|
94
101
|
if (currentText == text) {
|
|
95
102
|
Log.d(TAG, "Text unchanged, skipping update")
|
|
@@ -165,7 +172,7 @@ class AdvancedTextView : TextView {
|
|
|
165
172
|
// Apply indicator color
|
|
166
173
|
if (wordPos.index == indicatorWordIndex) {
|
|
167
174
|
spannableString.setSpan(
|
|
168
|
-
ForegroundColorSpan(Color.
|
|
175
|
+
ForegroundColorSpan(Color.parseColor(textColor)),
|
|
169
176
|
wordPos.start,
|
|
170
177
|
wordPos.end,
|
|
171
178
|
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
|
|
@@ -213,8 +220,8 @@ class AdvancedTextView : TextView {
|
|
|
213
220
|
}
|
|
214
221
|
|
|
215
222
|
private inner class WordClickableSpan(
|
|
216
|
-
|
|
217
|
-
|
|
223
|
+
private val wordIndex: Int,
|
|
224
|
+
private val word: String
|
|
218
225
|
) : ClickableSpan() {
|
|
219
226
|
|
|
220
227
|
override fun onClick(widget: View) {
|
|
@@ -231,6 +238,7 @@ class AdvancedTextView : TextView {
|
|
|
231
238
|
override fun updateDrawState(ds: TextPaint) {
|
|
232
239
|
super.updateDrawState(ds)
|
|
233
240
|
ds.isUnderlineText = false
|
|
241
|
+
ds.color = Color.parseColor(textColor)
|
|
234
242
|
}
|
|
235
243
|
}
|
|
236
244
|
|
|
@@ -8,25 +8,10 @@ import com.facebook.react.bridge.ReadableArray
|
|
|
8
8
|
import com.facebook.react.module.annotations.ReactModule
|
|
9
9
|
import com.facebook.react.uimanager.SimpleViewManager
|
|
10
10
|
import com.facebook.react.uimanager.ThemedReactContext
|
|
11
|
-
import com.facebook.react.uimanager.ViewManagerDelegate
|
|
12
11
|
import com.facebook.react.uimanager.annotations.ReactProp
|
|
13
|
-
import com.facebook.react.viewmanagers.AdvancedTextViewManagerInterface
|
|
14
|
-
import com.facebook.react.viewmanagers.AdvancedTextViewManagerDelegate
|
|
15
|
-
import com.facebook.react.uimanager.PixelUtil
|
|
16
12
|
|
|
17
13
|
@ReactModule(name = AdvancedTextViewManager.NAME)
|
|
18
|
-
class AdvancedTextViewManager : SimpleViewManager<AdvancedTextView>()
|
|
19
|
-
AdvancedTextViewManagerInterface<AdvancedTextView> {
|
|
20
|
-
|
|
21
|
-
private val mDelegate: ViewManagerDelegate<AdvancedTextView>
|
|
22
|
-
|
|
23
|
-
init {
|
|
24
|
-
mDelegate = AdvancedTextViewManagerDelegate(this)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
override fun getDelegate(): ViewManagerDelegate<AdvancedTextView>? {
|
|
28
|
-
return mDelegate
|
|
29
|
-
}
|
|
14
|
+
class AdvancedTextViewManager : SimpleViewManager<AdvancedTextView>() {
|
|
30
15
|
|
|
31
16
|
override fun getName(): String {
|
|
32
17
|
return NAME
|
|
@@ -40,17 +25,18 @@ class AdvancedTextViewManager : SimpleViewManager<AdvancedTextView>(),
|
|
|
40
25
|
)
|
|
41
26
|
// Set default text color to black to ensure visibility
|
|
42
27
|
view.setTextColor(Color.BLACK)
|
|
28
|
+
android.util.Log.d(NAME, "createViewInstance: View created")
|
|
43
29
|
return view
|
|
44
30
|
}
|
|
45
31
|
|
|
46
32
|
@ReactProp(name = "text")
|
|
47
|
-
|
|
48
|
-
android.util.Log.d(
|
|
33
|
+
fun setText(view: AdvancedTextView?, text: String?) {
|
|
34
|
+
android.util.Log.d(NAME, "setText called with: '$text'")
|
|
49
35
|
view?.setAdvancedText(text ?: "")
|
|
50
36
|
}
|
|
51
37
|
|
|
52
38
|
@ReactProp(name = "highlightedWords")
|
|
53
|
-
|
|
39
|
+
fun setHighlightedWords(view: AdvancedTextView?, highlightedWords: ReadableArray?) {
|
|
54
40
|
if (highlightedWords == null) {
|
|
55
41
|
view?.setHighlightedWords(emptyList())
|
|
56
42
|
return
|
|
@@ -70,11 +56,12 @@ class AdvancedTextViewManager : SimpleViewManager<AdvancedTextView>(),
|
|
|
70
56
|
}
|
|
71
57
|
}
|
|
72
58
|
}
|
|
59
|
+
android.util.Log.d(NAME, "setHighlightedWords: ${words.size} words")
|
|
73
60
|
view?.setHighlightedWords(words)
|
|
74
61
|
}
|
|
75
62
|
|
|
76
63
|
@ReactProp(name = "menuOptions")
|
|
77
|
-
|
|
64
|
+
fun setMenuOptions(view: AdvancedTextView?, menuOptions: ReadableArray?) {
|
|
78
65
|
if (menuOptions == null) {
|
|
79
66
|
view?.setMenuOptions(emptyList())
|
|
80
67
|
return
|
|
@@ -86,25 +73,28 @@ class AdvancedTextViewManager : SimpleViewManager<AdvancedTextView>(),
|
|
|
86
73
|
options.add(option)
|
|
87
74
|
}
|
|
88
75
|
}
|
|
76
|
+
android.util.Log.d(NAME, "setMenuOptions: ${options.size} options")
|
|
89
77
|
view?.setMenuOptions(options)
|
|
90
78
|
}
|
|
91
79
|
|
|
92
80
|
@ReactProp(name = "indicatorWordIndex")
|
|
93
|
-
|
|
81
|
+
fun setIndicatorWordIndex(view: AdvancedTextView?, index: Int) {
|
|
82
|
+
android.util.Log.d(NAME, "setIndicatorWordIndex: $index")
|
|
94
83
|
view?.setIndicatorWordIndex(if (index >= 0) index else -1)
|
|
95
84
|
}
|
|
96
85
|
|
|
97
86
|
@ReactProp(name = "color", customType = "Color")
|
|
98
87
|
fun setColor(view: AdvancedTextView?, color: Int?) {
|
|
99
|
-
android.util.Log.d(
|
|
100
|
-
|
|
88
|
+
android.util.Log.d(NAME, "setColor called with: $color")
|
|
89
|
+
if (color != null) {
|
|
90
|
+
view?.setAdvancedTextColor(color)
|
|
91
|
+
}
|
|
101
92
|
}
|
|
102
93
|
|
|
103
94
|
@ReactProp(name = "fontSize")
|
|
104
95
|
fun setFontSize(view: AdvancedTextView?, fontSize: Float) {
|
|
105
|
-
android.util.Log.d(
|
|
96
|
+
android.util.Log.d(NAME, "setFontSize called with: $fontSize")
|
|
106
97
|
if (fontSize > 0) {
|
|
107
|
-
// Convert from React Native points to Android pixels
|
|
108
98
|
view?.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSize)
|
|
109
99
|
}
|
|
110
100
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import type { ViewProps } from 'react-native';
|
|
3
3
|
import { codegenNativeComponent } from 'react-native';
|
|
4
4
|
// @ts-ignore
|
|
5
|
-
import type { DirectEventHandler,
|
|
5
|
+
import type { DirectEventHandler, Int32} from 'react-native/Libraries/Types/CodegenTypes';
|
|
6
6
|
|
|
7
7
|
interface HighlightedWord {
|
|
8
8
|
index: Int32;
|
|
@@ -16,8 +16,6 @@ interface NativeProps extends ViewProps {
|
|
|
16
16
|
onWordPress?: DirectEventHandler<{ word: string; index: Int32 }>;
|
|
17
17
|
onSelection?: DirectEventHandler<{ selectedText: string; event: string }>;
|
|
18
18
|
indicatorWordIndex?: Int32;
|
|
19
|
-
color?: Int32;
|
|
20
|
-
fontSize?: Float;
|
|
21
19
|
}
|
|
22
20
|
|
|
23
21
|
export default codegenNativeComponent<NativeProps>('AdvancedTextView');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ViewProps } from 'react-native';
|
|
2
|
-
import type { DirectEventHandler,
|
|
2
|
+
import type { DirectEventHandler, Int32 } from 'react-native/Libraries/Types/CodegenTypes';
|
|
3
3
|
interface HighlightedWord {
|
|
4
4
|
index: Int32;
|
|
5
5
|
highlightColor: string;
|
|
@@ -17,8 +17,6 @@ interface NativeProps extends ViewProps {
|
|
|
17
17
|
event: string;
|
|
18
18
|
}>;
|
|
19
19
|
indicatorWordIndex?: Int32;
|
|
20
|
-
color?: Int32;
|
|
21
|
-
fontSize?: Float;
|
|
22
20
|
}
|
|
23
21
|
declare const _default: import("react-native/types_generated/Libraries/Utilities/codegenNativeComponent").NativeComponentType<NativeProps>;
|
|
24
22
|
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,
|
|
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,EAAC,MAAM,2CAA2C,CAAC;AAE1F,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;CAC5B;;AAED,wBAAuE"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import type { ViewProps } from 'react-native';
|
|
3
3
|
import { codegenNativeComponent } from 'react-native';
|
|
4
4
|
// @ts-ignore
|
|
5
|
-
import type { DirectEventHandler,
|
|
5
|
+
import type { DirectEventHandler, Int32} from 'react-native/Libraries/Types/CodegenTypes';
|
|
6
6
|
|
|
7
7
|
interface HighlightedWord {
|
|
8
8
|
index: Int32;
|
|
@@ -16,8 +16,6 @@ interface NativeProps extends ViewProps {
|
|
|
16
16
|
onWordPress?: DirectEventHandler<{ word: string; index: Int32 }>;
|
|
17
17
|
onSelection?: DirectEventHandler<{ selectedText: string; event: string }>;
|
|
18
18
|
indicatorWordIndex?: Int32;
|
|
19
|
-
color?: Int32;
|
|
20
|
-
fontSize?: Float;
|
|
21
19
|
}
|
|
22
20
|
|
|
23
21
|
export default codegenNativeComponent<NativeProps>('AdvancedTextView');
|