react-native-advanced-text 0.1.17 → 0.1.19
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 +269 -303
- package/android/src/main/java/com/advancedtext/AdvancedTextViewManager.kt +110 -95
- package/lib/module/AdvancedText.js +6 -1
- package/lib/module/AdvancedText.js.map +1 -1
- package/lib/module/AdvancedTextViewNativeComponent.ts +4 -4
- 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 +2 -1
- package/lib/typescript/src/AdvancedTextViewNativeComponent.d.ts.map +1 -1
- package/package.json +175 -175
- package/src/AdvancedText.tsx +24 -8
- package/src/AdvancedTextViewNativeComponent.ts +4 -4
|
@@ -1,95 +1,110 @@
|
|
|
1
|
-
// File: AdvancedTextViewManager.kt
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import android.
|
|
6
|
-
import
|
|
7
|
-
import com.facebook.react.
|
|
8
|
-
import com.facebook.react.
|
|
9
|
-
import com.facebook.react.uimanager.
|
|
10
|
-
import com.facebook.react.uimanager.
|
|
11
|
-
import com.facebook.react.uimanager.annotations.ReactProp
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
view
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
1
|
+
// File: AdvancedTextViewManager.kt
|
|
2
|
+
package com.advancedtext
|
|
3
|
+
|
|
4
|
+
import android.graphics.Color
|
|
5
|
+
import android.util.TypedValue
|
|
6
|
+
import android.view.ViewGroup
|
|
7
|
+
import com.facebook.react.bridge.ReadableArray
|
|
8
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
9
|
+
import com.facebook.react.uimanager.SimpleViewManager
|
|
10
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
11
|
+
import com.facebook.react.uimanager.annotations.ReactProp
|
|
12
|
+
|
|
13
|
+
@ReactModule(name = AdvancedTextViewManager.NAME)
|
|
14
|
+
class AdvancedTextViewManager : SimpleViewManager<AdvancedTextView>() {
|
|
15
|
+
|
|
16
|
+
override fun getName(): String {
|
|
17
|
+
return NAME
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public override fun createViewInstance(context: ThemedReactContext): AdvancedTextView {
|
|
21
|
+
val view = AdvancedTextView(context)
|
|
22
|
+
view.layoutParams = ViewGroup.LayoutParams(
|
|
23
|
+
ViewGroup.LayoutParams.MATCH_PARENT,
|
|
24
|
+
ViewGroup.LayoutParams.WRAP_CONTENT
|
|
25
|
+
)
|
|
26
|
+
// Set default text color to black to ensure visibility
|
|
27
|
+
view.setTextColor(Color.BLACK)
|
|
28
|
+
android.util.Log.d(NAME, "createViewInstance: View created")
|
|
29
|
+
return view
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@ReactProp(name = "text")
|
|
33
|
+
fun setText(view: AdvancedTextView?, text: String?) {
|
|
34
|
+
android.util.Log.d(NAME, "setText called with: '$text'")
|
|
35
|
+
view?.setAdvancedText(text ?: "")
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@ReactProp(name = "highlightedWords")
|
|
39
|
+
fun setHighlightedWords(view: AdvancedTextView?, highlightedWords: ReadableArray?) {
|
|
40
|
+
if (highlightedWords == null) {
|
|
41
|
+
view?.setHighlightedWords(emptyList())
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
val words = mutableListOf<HighlightedWord>()
|
|
46
|
+
for (i in 0 until highlightedWords.size()) {
|
|
47
|
+
val map = highlightedWords.getMap(i)
|
|
48
|
+
map?.let { wordMap ->
|
|
49
|
+
if (wordMap.hasKey("index") && wordMap.hasKey("highlightColor")) {
|
|
50
|
+
words.add(
|
|
51
|
+
HighlightedWord(
|
|
52
|
+
index = wordMap.getInt("index"),
|
|
53
|
+
highlightColor = wordMap.getString("highlightColor") ?: "#FFFF00"
|
|
54
|
+
)
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
android.util.Log.d(NAME, "setHighlightedWords: ${words.size} words")
|
|
60
|
+
view?.setHighlightedWords(words)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@ReactProp(name = "menuOptions")
|
|
64
|
+
fun setMenuOptions(view: AdvancedTextView?, menuOptions: ReadableArray?) {
|
|
65
|
+
if (menuOptions == null) {
|
|
66
|
+
view?.setMenuOptions(emptyList())
|
|
67
|
+
return
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
val options = mutableListOf<String>()
|
|
71
|
+
for (i in 0 until menuOptions.size()) {
|
|
72
|
+
menuOptions.getString(i)?.let { option ->
|
|
73
|
+
options.add(option)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
android.util.Log.d(NAME, "setMenuOptions: ${options.size} options")
|
|
77
|
+
view?.setMenuOptions(options)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@ReactProp(name = "indicatorWordIndex")
|
|
81
|
+
fun setIndicatorWordIndex(view: AdvancedTextView?, index: Int) {
|
|
82
|
+
android.util.Log.d(NAME, "setIndicatorWordIndex: $index")
|
|
83
|
+
view?.setIndicatorWordIndex(if (index >= 0) index else -1)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@ReactProp(name = "color", customType = "Color")
|
|
87
|
+
fun setColor(view: AdvancedTextView?, color: Int?) {
|
|
88
|
+
android.util.Log.d(NAME, "setColor called with: $color")
|
|
89
|
+
view?.setTextColor(color ?: Color.BLACK)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
@ReactProp(name = "fontSize")
|
|
93
|
+
fun setFontSize(view: AdvancedTextView?, fontSize: Float) {
|
|
94
|
+
android.util.Log.d(NAME, "setFontSize called with: $fontSize")
|
|
95
|
+
if (fontSize > 0) {
|
|
96
|
+
view?.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSize)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
override fun getExportedCustomDirectEventTypeConstants(): Map<String, Any> {
|
|
101
|
+
return mapOf(
|
|
102
|
+
"onWordPress" to mapOf("registrationName" to "onWordPress"),
|
|
103
|
+
"onSelection" to mapOf("registrationName" to "onSelection")
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
companion object {
|
|
108
|
+
const val NAME = "AdvancedTextView"
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -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
|
+
/* eslint-disable prettier/prettier */
|
|
1
2
|
import type { ViewProps } from 'react-native';
|
|
2
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, Int32} from 'react-native/Libraries/Types/CodegenTypes';
|
|
6
6
|
|
|
7
7
|
interface HighlightedWord {
|
|
8
8
|
index: Int32;
|
|
@@ -13,8 +13,8 @@ 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
19
|
}
|
|
20
20
|
|
|
@@ -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"}
|
|
@@ -10,10 +10,11 @@ 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;
|
|
19
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AdvancedTextViewNativeComponent.d.ts","sourceRoot":"","sources":["../../../src/AdvancedTextViewNativeComponent.ts"],"names":[],"mappings":"
|
|
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"}
|