react-native-advanced-text 0.1.24 → 0.1.26
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 +56 -5
- package/android/src/main/java/com/advancedtext/AdvancedTextViewManager.kt +28 -4
- package/lib/module/AdvancedText.js.map +1 -1
- package/lib/module/AdvancedTextViewNativeComponent.ts +7 -2
- package/lib/typescript/src/AdvancedText.d.ts +1 -23
- package/lib/typescript/src/AdvancedText.d.ts.map +1 -1
- package/lib/typescript/src/AdvancedTextViewNativeComponent.d.ts +6 -1
- package/lib/typescript/src/AdvancedTextViewNativeComponent.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/AdvancedText.tsx +3 -32
- package/src/AdvancedTextViewNativeComponent.ts +7 -2
|
@@ -20,6 +20,7 @@ import com.facebook.react.bridge.Arguments
|
|
|
20
20
|
import com.facebook.react.bridge.ReactContext
|
|
21
21
|
import com.facebook.react.uimanager.events.RCTEventEmitter
|
|
22
22
|
import android.text.Selection
|
|
23
|
+
import android.graphics.Typeface
|
|
23
24
|
|
|
24
25
|
class AdvancedTextView : TextView {
|
|
25
26
|
|
|
@@ -32,6 +33,10 @@ class AdvancedTextView : TextView {
|
|
|
32
33
|
private var customActionMode: ActionMode? = null
|
|
33
34
|
private var currentText: String = ""
|
|
34
35
|
private var textColor: String = "#000000"
|
|
36
|
+
private var fontSize: Float = 16f
|
|
37
|
+
private var fontWeight: String = "normal"
|
|
38
|
+
private var textAlign: String = "left"
|
|
39
|
+
private var fontFamily: String = "sans-serif"
|
|
35
40
|
|
|
36
41
|
private var wordPositions: List<WordPosition> = emptyList()
|
|
37
42
|
|
|
@@ -46,7 +51,7 @@ class AdvancedTextView : TextView {
|
|
|
46
51
|
setPadding(16, 16, 16, 16)
|
|
47
52
|
movementMethod = LinkMovementMethod.getInstance()
|
|
48
53
|
setTextIsSelectable(true)
|
|
49
|
-
|
|
54
|
+
|
|
50
55
|
|
|
51
56
|
customSelectionActionModeCallback = object : ActionMode.Callback {
|
|
52
57
|
override fun onCreateActionMode(mode: ActionMode?, menu: Menu?): Boolean {
|
|
@@ -90,10 +95,6 @@ class AdvancedTextView : TextView {
|
|
|
90
95
|
}
|
|
91
96
|
|
|
92
97
|
|
|
93
|
-
fun setAdvancedTextColor(colorInt: Int) {
|
|
94
|
-
textColor = String.format("#%06X", 0xFFFFFF and colorInt)
|
|
95
|
-
updateTextWithHighlights()
|
|
96
|
-
}
|
|
97
98
|
|
|
98
99
|
fun setAdvancedText(text: String) {
|
|
99
100
|
if (currentText == text) {
|
|
@@ -107,6 +108,41 @@ class AdvancedTextView : TextView {
|
|
|
107
108
|
updateTextWithHighlights()
|
|
108
109
|
}
|
|
109
110
|
|
|
111
|
+
fun setAdvancedTextColor(colorInt: Int) {
|
|
112
|
+
textColor = String.format("#%06X", 0xFFFFFF and colorInt)
|
|
113
|
+
updateTextWithHighlights()
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
fun setAdvancedTextSize(size: Float) {
|
|
118
|
+
if (fontSize == size) return
|
|
119
|
+
fontSize = size
|
|
120
|
+
updateTextWithHighlights()
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
fun setAdvancedFontWeight(weight: String) {
|
|
124
|
+
if (fontWeight == weight) return
|
|
125
|
+
fontWeight = weight
|
|
126
|
+
updateTextWithHighlights()
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
fun setAdvancedTextAlign(align: String) {
|
|
130
|
+
if (textAlign == align) return
|
|
131
|
+
textAlign = align
|
|
132
|
+
when (align) {
|
|
133
|
+
"left" -> textAlignment = View.TEXT_ALIGNMENT_TEXT_START
|
|
134
|
+
"center" -> textAlignment = View.TEXT_ALIGNMENT_CENTER
|
|
135
|
+
"right" -> textAlignment = View.TEXT_ALIGNMENT_TEXT_END
|
|
136
|
+
else -> textAlignment = View.TEXT_ALIGNMENT_TEXT_START
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
fun setAdvancedFontFamily(family: String) {
|
|
141
|
+
if (fontFamily == family) return
|
|
142
|
+
fontFamily = family
|
|
143
|
+
typeface = Typeface.create(family, Typeface.NORMAL)
|
|
144
|
+
}
|
|
145
|
+
|
|
110
146
|
fun setMenuOptions(menuOptions: List<String>) {
|
|
111
147
|
if (this.menuOptions == menuOptions) return
|
|
112
148
|
this.menuOptions = menuOptions
|
|
@@ -182,6 +218,21 @@ class AdvancedTextView : TextView {
|
|
|
182
218
|
)
|
|
183
219
|
}
|
|
184
220
|
|
|
221
|
+
textAlignment = when (textAlign) {
|
|
222
|
+
"left" -> View.TEXT_ALIGNMENT_TEXT_START
|
|
223
|
+
"center" -> View.TEXT_ALIGNMENT_CENTER
|
|
224
|
+
"right" -> View.TEXT_ALIGNMENT_TEXT_END
|
|
225
|
+
else -> View.TEXT_ALIGNMENT_TEXT_START
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
setTextSize(fontSize)
|
|
229
|
+
|
|
230
|
+
typeface = when (fontWeight) {
|
|
231
|
+
"bold" -> Typeface.create(fontFamily, Typeface.BOLD)
|
|
232
|
+
"italic" -> Typeface.create(fontFamily, Typeface.ITALIC)
|
|
233
|
+
else -> Typeface.create(fontFamily, Typeface.NORMAL)
|
|
234
|
+
}
|
|
235
|
+
|
|
185
236
|
post {
|
|
186
237
|
setText(spannableString, BufferType.SPANNABLE)
|
|
187
238
|
Log.d(TAG, "Text updated with ${wordPositions.size} spans")
|
|
@@ -83,11 +83,11 @@ class AdvancedTextViewManager : SimpleViewManager<AdvancedTextView>() {
|
|
|
83
83
|
view?.setIndicatorWordIndex(if (index >= 0) index else -1)
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
@ReactProp(name = "color"
|
|
87
|
-
fun setColor(view: AdvancedTextView?, color:
|
|
86
|
+
@ReactProp(name = "color")
|
|
87
|
+
fun setColor(view: AdvancedTextView?, color: String?) {
|
|
88
88
|
android.util.Log.d(NAME, "setColor called with: $color")
|
|
89
89
|
if (color != null) {
|
|
90
|
-
view?.setAdvancedTextColor(color)
|
|
90
|
+
view?.setAdvancedTextColor(Color.parseColor(color))
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
|
|
@@ -95,7 +95,31 @@ class AdvancedTextViewManager : SimpleViewManager<AdvancedTextView>() {
|
|
|
95
95
|
fun setFontSize(view: AdvancedTextView?, fontSize: Float) {
|
|
96
96
|
android.util.Log.d(NAME, "setFontSize called with: $fontSize")
|
|
97
97
|
if (fontSize > 0) {
|
|
98
|
-
view?.
|
|
98
|
+
view?.setAdvancedTextSize(fontSize)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@ReactProp(name = "fontWeight")
|
|
103
|
+
fun setFontWeight(view: AdvancedTextView?, fontWeight: String?) {
|
|
104
|
+
android.util.Log.d(NAME, "setFontWeight called with: $fontWeight")
|
|
105
|
+
if (fontWeight != null) {
|
|
106
|
+
view?.setAdvancedFontWeight(fontWeight)
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
@ReactProp(name = "textAlign")
|
|
111
|
+
fun setTextAlign(view: AdvancedTextView?, textAlign: String?) {
|
|
112
|
+
android.util.Log.d(NAME, "setTextAlign called with: $textAlign")
|
|
113
|
+
if (textAlign != null) {
|
|
114
|
+
view?.setAdvancedTextAlign(textAlign)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@ReactProp(name = "fontFamily")
|
|
119
|
+
fun setFontFamily(view: AdvancedTextView?, fontFamily: String?) {
|
|
120
|
+
android.util.Log.d(NAME, "setFontFamily called with: $fontFamily")
|
|
121
|
+
if (fontFamily != null) {
|
|
122
|
+
view?.setAdvancedFontFamily(fontFamily)
|
|
99
123
|
}
|
|
100
124
|
}
|
|
101
125
|
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AACzB,OAAOC,+BAA+B,MAE/B,mCAAmC;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAE3C,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":[]}
|
|
@@ -2,20 +2,25 @@
|
|
|
2
2
|
import type { ViewProps } from 'react-native';
|
|
3
3
|
import { codegenNativeComponent } from 'react-native';
|
|
4
4
|
// @ts-ignore
|
|
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;
|
|
9
9
|
highlightColor: string;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
interface NativeProps extends ViewProps {
|
|
12
|
+
export interface NativeProps extends ViewProps {
|
|
13
13
|
text: string;
|
|
14
14
|
highlightedWords?: ReadonlyArray<HighlightedWord>;
|
|
15
15
|
menuOptions?: ReadonlyArray<string>;
|
|
16
16
|
onWordPress?: DirectEventHandler<{ word: string; index: Int32 }>;
|
|
17
17
|
onSelection?: DirectEventHandler<{ selectedText: string; event: string }>;
|
|
18
18
|
indicatorWordIndex?: Int32;
|
|
19
|
+
fontSize?: Int32;
|
|
20
|
+
fontWeight?: string;
|
|
21
|
+
color?: string;
|
|
22
|
+
textAlign?: string;
|
|
23
|
+
fontFamily?: string;
|
|
19
24
|
}
|
|
20
25
|
|
|
21
26
|
export default codegenNativeComponent<NativeProps>('AdvancedTextView');
|
|
@@ -1,26 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
3
|
-
interface HighlightedWord {
|
|
4
|
-
index: number;
|
|
5
|
-
highlightColor: string;
|
|
6
|
-
}
|
|
7
|
-
interface WordPressEvent {
|
|
8
|
-
word: string;
|
|
9
|
-
index: number;
|
|
10
|
-
}
|
|
11
|
-
interface SelectionEvent {
|
|
12
|
-
selectedText: string;
|
|
13
|
-
event: string;
|
|
14
|
-
}
|
|
15
|
-
interface NativeProps extends ViewProps {
|
|
16
|
-
text: string;
|
|
17
|
-
style?: StyleProp<ViewStyle>;
|
|
18
|
-
highlightedWords?: ReadonlyArray<HighlightedWord>;
|
|
19
|
-
menuOptions?: ReadonlyArray<string>;
|
|
20
|
-
onWordPress?: (event: NativeSyntheticEvent<WordPressEvent>) => void;
|
|
21
|
-
onSelection?: (event: NativeSyntheticEvent<SelectionEvent>) => void;
|
|
22
|
-
indicatorWordIndex?: number;
|
|
23
|
-
}
|
|
2
|
+
import { type NativeProps } from './AdvancedTextViewNativeComponent';
|
|
24
3
|
export declare const AdvancedText: React.FC<NativeProps>;
|
|
25
|
-
export {};
|
|
26
4
|
//# sourceMappingURL=AdvancedText.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AdvancedText.d.ts","sourceRoot":"","sources":["../../../src/AdvancedText.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,
|
|
1
|
+
{"version":3,"file":"AdvancedText.d.ts","sourceRoot":"","sources":["../../../src/AdvancedText.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAwC,EACtC,KAAK,WAAW,EACjB,MAAM,mCAAmC,CAAC;AAE3C,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAsB9C,CAAC"}
|
|
@@ -4,7 +4,7 @@ interface HighlightedWord {
|
|
|
4
4
|
index: Int32;
|
|
5
5
|
highlightColor: string;
|
|
6
6
|
}
|
|
7
|
-
interface NativeProps extends ViewProps {
|
|
7
|
+
export interface NativeProps extends ViewProps {
|
|
8
8
|
text: string;
|
|
9
9
|
highlightedWords?: ReadonlyArray<HighlightedWord>;
|
|
10
10
|
menuOptions?: ReadonlyArray<string>;
|
|
@@ -17,6 +17,11 @@ interface NativeProps extends ViewProps {
|
|
|
17
17
|
event: string;
|
|
18
18
|
}>;
|
|
19
19
|
indicatorWordIndex?: Int32;
|
|
20
|
+
fontSize?: Int32;
|
|
21
|
+
fontWeight?: string;
|
|
22
|
+
color?: string;
|
|
23
|
+
textAlign?: string;
|
|
24
|
+
fontFamily?: string;
|
|
20
25
|
}
|
|
21
26
|
declare const _default: import("react-native/types_generated/Libraries/Utilities/codegenNativeComponent").NativeComponentType<NativeProps>;
|
|
22
27
|
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,EAAE,MAAM,2CAA2C,CAAC;AAE3F,UAAU,eAAe;IACvB,KAAK,EAAE,KAAK,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,WAAY,SAAQ,SAAS;IAC5C,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,QAAQ,CAAC,EAAE,KAAK,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;;AAED,wBAAuE"}
|
package/package.json
CHANGED
package/src/AdvancedText.tsx
CHANGED
|
@@ -1,36 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
ViewProps,
|
|
6
|
-
ViewStyle,
|
|
7
|
-
} from 'react-native';
|
|
8
|
-
import AdvancedTextViewNativeComponent from './AdvancedTextViewNativeComponent';
|
|
9
|
-
|
|
10
|
-
interface HighlightedWord {
|
|
11
|
-
index: number;
|
|
12
|
-
highlightColor: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
interface WordPressEvent {
|
|
16
|
-
word: string;
|
|
17
|
-
index: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
interface SelectionEvent {
|
|
21
|
-
selectedText: string;
|
|
22
|
-
event: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
interface NativeProps extends ViewProps {
|
|
26
|
-
text: string;
|
|
27
|
-
style?: StyleProp<ViewStyle>;
|
|
28
|
-
highlightedWords?: ReadonlyArray<HighlightedWord>;
|
|
29
|
-
menuOptions?: ReadonlyArray<string>;
|
|
30
|
-
onWordPress?: (event: NativeSyntheticEvent<WordPressEvent>) => void;
|
|
31
|
-
onSelection?: (event: NativeSyntheticEvent<SelectionEvent>) => void;
|
|
32
|
-
indicatorWordIndex?: number;
|
|
33
|
-
}
|
|
2
|
+
import AdvancedTextViewNativeComponent, {
|
|
3
|
+
type NativeProps,
|
|
4
|
+
} from './AdvancedTextViewNativeComponent';
|
|
34
5
|
|
|
35
6
|
export const AdvancedText: React.FC<NativeProps> = ({
|
|
36
7
|
text,
|
|
@@ -2,20 +2,25 @@
|
|
|
2
2
|
import type { ViewProps } from 'react-native';
|
|
3
3
|
import { codegenNativeComponent } from 'react-native';
|
|
4
4
|
// @ts-ignore
|
|
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;
|
|
9
9
|
highlightColor: string;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
interface NativeProps extends ViewProps {
|
|
12
|
+
export interface NativeProps extends ViewProps {
|
|
13
13
|
text: string;
|
|
14
14
|
highlightedWords?: ReadonlyArray<HighlightedWord>;
|
|
15
15
|
menuOptions?: ReadonlyArray<string>;
|
|
16
16
|
onWordPress?: DirectEventHandler<{ word: string; index: Int32 }>;
|
|
17
17
|
onSelection?: DirectEventHandler<{ selectedText: string; event: string }>;
|
|
18
18
|
indicatorWordIndex?: Int32;
|
|
19
|
+
fontSize?: Int32;
|
|
20
|
+
fontWeight?: string;
|
|
21
|
+
color?: string;
|
|
22
|
+
textAlign?: string;
|
|
23
|
+
fontFamily?: string;
|
|
19
24
|
}
|
|
20
25
|
|
|
21
26
|
export default codegenNativeComponent<NativeProps>('AdvancedTextView');
|