react-native-advanced-text 0.1.24 → 0.1.25

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.
@@ -32,6 +32,10 @@ class AdvancedTextView : TextView {
32
32
  private var customActionMode: ActionMode? = null
33
33
  private var currentText: String = ""
34
34
  private var textColor: String = "#000000"
35
+ private var fontSize: Float = 16f
36
+ private var fontWeight: String = "normal"
37
+ private var textAlign: String = "left"
38
+ private var fontFamily: String = "sans-serif"
35
39
 
36
40
  private var wordPositions: List<WordPosition> = emptyList()
37
41
 
@@ -46,7 +50,7 @@ class AdvancedTextView : TextView {
46
50
  setPadding(16, 16, 16, 16)
47
51
  movementMethod = LinkMovementMethod.getInstance()
48
52
  setTextIsSelectable(true)
49
-
53
+
50
54
 
51
55
  customSelectionActionModeCallback = object : ActionMode.Callback {
52
56
  override fun onCreateActionMode(mode: ActionMode?, menu: Menu?): Boolean {
@@ -90,10 +94,6 @@ class AdvancedTextView : TextView {
90
94
  }
91
95
 
92
96
 
93
- fun setAdvancedTextColor(colorInt: Int) {
94
- textColor = String.format("#%06X", 0xFFFFFF and colorInt)
95
- updateTextWithHighlights()
96
- }
97
97
 
98
98
  fun setAdvancedText(text: String) {
99
99
  if (currentText == text) {
@@ -107,6 +107,40 @@ class AdvancedTextView : TextView {
107
107
  updateTextWithHighlights()
108
108
  }
109
109
 
110
+ fun setAdvancedTextColor(colorInt: Int) {
111
+ textColor = String.format("#%06X", 0xFFFFFF and colorInt)
112
+ updateTextWithHighlights()
113
+ }
114
+
115
+
116
+ fun setAdvancedTextSize(size: Float) {
117
+ if (fontSize == size) return
118
+ fontSize = size
119
+ updateTextWithHighlights() // ensures size change is applied with highlights
120
+ }
121
+
122
+ fun setAdvancedFontWeight(weight: String) {
123
+ if (fontWeight == weight) return
124
+ fontWeight = weight
125
+ }
126
+
127
+ fun setAdvancedTextAlign(align: String) {
128
+ if (textAlign == align) return
129
+ textAlign = align
130
+ when (align) {
131
+ "left" -> textAlignment = View.TEXT_ALIGNMENT_TEXT_START
132
+ "center" -> textAlignment = View.TEXT_ALIGNMENT_CENTER
133
+ "right" -> textAlignment = View.TEXT_ALIGNMENT_TEXT_END
134
+ else -> textAlignment = View.TEXT_ALIGNMENT_TEXT_START
135
+ }
136
+ }
137
+
138
+ fun setAdvancedFontFamily(family: String) {
139
+ if (fontFamily == family) return
140
+ fontFamily = family
141
+ typeface = Typeface.create(family, Typeface.NORMAL)
142
+ }
143
+
110
144
  fun setMenuOptions(menuOptions: List<String>) {
111
145
  if (this.menuOptions == menuOptions) return
112
146
  this.menuOptions = menuOptions
@@ -182,6 +216,21 @@ class AdvancedTextView : TextView {
182
216
  )
183
217
  }
184
218
 
219
+ textAlignment = when (textAlign) {
220
+ "left" -> View.TEXT_ALIGNMENT_TEXT_START
221
+ "center" -> View.TEXT_ALIGNMENT_CENTER
222
+ "right" -> View.TEXT_ALIGNMENT_TEXT_END
223
+ else -> View.TEXT_ALIGNMENT_TEXT_START
224
+ }
225
+
226
+ setTextSize(fontSize)
227
+
228
+ typeface = when (fontWeight) {
229
+ "bold" -> Typeface.create(fontFamily, Typeface.BOLD)
230
+ "italic" -> Typeface.create(fontFamily, Typeface.ITALIC)
231
+ else -> Typeface.create(fontFamily, Typeface.NORMAL)
232
+ }
233
+
185
234
  post {
186
235
  setText(spannableString, BufferType.SPANNABLE)
187
236
  Log.d(TAG, "Text updated with ${wordPositions.size} spans")
@@ -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?.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSize)
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;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
+ {"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 type { NativeSyntheticEvent, StyleProp, ViewProps, ViewStyle } from 'react-native';
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,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
+ {"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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E,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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-advanced-text",
3
- "version": "0.1.24",
3
+ "version": "0.1.25",
4
4
  "description": " Advanced text component for React Native with custom select options.",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -1,36 +1,7 @@
1
1
  import React from 'react';
2
- import type {
3
- NativeSyntheticEvent,
4
- StyleProp,
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');