react-native-advanced-text 0.1.17 → 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.
@@ -1,95 +1,122 @@
1
- // File: AdvancedTextViewManager.kt
2
- // This should be the ONLY content in this file
3
- package com.advancedtext
4
-
5
- import android.view.ViewGroup
6
- import com.facebook.react.bridge.ReadableArray
7
- import com.facebook.react.module.annotations.ReactModule
8
- import com.facebook.react.uimanager.SimpleViewManager
9
- import com.facebook.react.uimanager.ThemedReactContext
10
- import com.facebook.react.uimanager.ViewManagerDelegate
11
- import com.facebook.react.uimanager.annotations.ReactProp
12
- import com.facebook.react.viewmanagers.AdvancedTextViewManagerInterface
13
- import com.facebook.react.viewmanagers.AdvancedTextViewManagerDelegate
14
-
15
- @ReactModule(name = AdvancedTextViewManager.NAME)
16
- class AdvancedTextViewManager : SimpleViewManager<AdvancedTextView>(),
17
- AdvancedTextViewManagerInterface<AdvancedTextView> {
18
- private val mDelegate: ViewManagerDelegate<AdvancedTextView>
19
-
20
- init {
21
- mDelegate = AdvancedTextViewManagerDelegate(this)
22
- }
23
-
24
- override fun getDelegate(): ViewManagerDelegate<AdvancedTextView>? {
25
- return mDelegate
26
- }
27
-
28
- override fun getName(): String {
29
- return NAME
30
- }
31
-
32
- public override fun createViewInstance(context: ThemedReactContext): AdvancedTextView {
33
- val view = AdvancedTextView(context)
34
- // Set default layout params to ensure the view is visible
35
- view.layoutParams = ViewGroup.LayoutParams(
36
- ViewGroup.LayoutParams.MATCH_PARENT,
37
- ViewGroup.LayoutParams.WRAP_CONTENT
38
- )
39
- return view
40
- }
41
-
42
- @ReactProp(name = "text")
43
- override fun setText(view: AdvancedTextView?, text: String?) {
44
- view?.setAdvancedText(text ?: "")
45
- }
46
-
47
- @ReactProp(name = "highlightedWords")
48
- override fun setHighlightedWords(view: AdvancedTextView?, highlightedWords: ReadableArray?) {
49
- val words = mutableListOf<HighlightedWord>()
50
- highlightedWords?.let {
51
- for (i in 0 until it.size()) {
52
- val map = it.getMap(i)
53
- map?.let { wordMap ->
54
- words.add(
55
- HighlightedWord(
56
- index = wordMap.getInt("index"),
57
- highlightColor = wordMap.getString("highlightColor") ?: "#FFFF00"
58
- )
59
- )
60
- }
61
- }
62
- }
63
- view?.setHighlightedWords(words)
64
- }
65
-
66
- @ReactProp(name = "menuOptions")
67
- override fun setMenuOptions(view: AdvancedTextView?, menuOptions: ReadableArray?) {
68
- val options = mutableListOf<String>()
69
- menuOptions?.let {
70
- for (i in 0 until it.size()) {
71
- it.getString(i)?.let { option ->
72
- options.add(option)
73
- }
74
- }
75
- }
76
- view?.setMenuOptions(options)
77
- }
78
-
79
- @ReactProp(name = "indicatorWordIndex")
80
- override fun setIndicatorWordIndex(view: AdvancedTextView?, index: Int) {
81
- view?.setIndicatorWordIndex(index)
82
- }
83
-
84
- // Add this method to register custom events
85
- override fun getExportedCustomDirectEventTypeConstants(): Map<String, Any> {
86
- return mapOf(
87
- "onWordPress" to mapOf("registrationName" to "onWordPress"),
88
- "onSelection" to mapOf("registrationName" to "onSelection")
89
- )
90
- }
91
-
92
- companion object {
93
- const val NAME = "AdvancedTextView"
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.ViewManagerDelegate
12
+ 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
+
17
+ @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
+ }
30
+
31
+ override fun getName(): String {
32
+ return NAME
33
+ }
34
+
35
+ public override fun createViewInstance(context: ThemedReactContext): AdvancedTextView {
36
+ val view = AdvancedTextView(context)
37
+ view.layoutParams = ViewGroup.LayoutParams(
38
+ ViewGroup.LayoutParams.MATCH_PARENT,
39
+ ViewGroup.LayoutParams.WRAP_CONTENT
40
+ )
41
+ // Set default text color to black to ensure visibility
42
+ view.setTextColor(Color.BLACK)
43
+ return view
44
+ }
45
+
46
+ @ReactProp(name = "text")
47
+ override fun setText(view: AdvancedTextView?, text: String?) {
48
+ android.util.Log.d("AdvancedTextViewManager", "setText called with: '$text'")
49
+ view?.setAdvancedText(text ?: "")
50
+ }
51
+
52
+ @ReactProp(name = "highlightedWords")
53
+ override fun setHighlightedWords(view: AdvancedTextView?, highlightedWords: ReadableArray?) {
54
+ if (highlightedWords == null) {
55
+ view?.setHighlightedWords(emptyList())
56
+ return
57
+ }
58
+
59
+ val words = mutableListOf<HighlightedWord>()
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")) {
64
+ words.add(
65
+ HighlightedWord(
66
+ index = wordMap.getInt("index"),
67
+ highlightColor = wordMap.getString("highlightColor") ?: "#FFFF00"
68
+ )
69
+ )
70
+ }
71
+ }
72
+ }
73
+ view?.setHighlightedWords(words)
74
+ }
75
+
76
+ @ReactProp(name = "menuOptions")
77
+ override fun setMenuOptions(view: AdvancedTextView?, menuOptions: ReadableArray?) {
78
+ if (menuOptions == null) {
79
+ view?.setMenuOptions(emptyList())
80
+ return
81
+ }
82
+
83
+ val options = mutableListOf<String>()
84
+ for (i in 0 until menuOptions.size()) {
85
+ menuOptions.getString(i)?.let { option ->
86
+ options.add(option)
87
+ }
88
+ }
89
+ view?.setMenuOptions(options)
90
+ }
91
+
92
+ @ReactProp(name = "indicatorWordIndex")
93
+ override fun setIndicatorWordIndex(view: AdvancedTextView?, index: Int) {
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
+ }
110
+ }
111
+
112
+ override fun getExportedCustomDirectEventTypeConstants(): Map<String, Any> {
113
+ return mapOf(
114
+ "onWordPress" to mapOf("registrationName" to "onWordPress"),
115
+ "onSelection" to mapOf("registrationName" to "onSelection")
116
+ )
117
+ }
118
+
119
+ companion object {
120
+ const val NAME = "AdvancedTextView"
121
+ }
122
+ }
@@ -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":";;AACA,OAAOA,+BAA+B,MAAM,mCAAmC;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAqBhF,OAAO,MAAMC,YAAmC,GAAGA,CAAC;EAClDC,IAAI;EACJC,gBAAgB;EAChBC,WAAW;EACXC,WAAW;EACXC,WAAW;EACXC;AACF,CAAC,KAAK;EACJ,oBACEP,IAAA,CAACF,+BAA+B;IAC9BI,IAAI,EAAEA,IAAK;IACXC,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;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
- // eslint-disable-next-line prettier/prettier
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; eventType: 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 type { NativeSyntheticEvent, ViewProps } from 'react-native';
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
- word: string;
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,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGpE,UAAU,eAAe;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,UAAU,WAAY,SAAQ,SAAS;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB,CAAC,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;IAElD,WAAW,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACpC,WAAW,CAAC,EAAE,CACZ,KAAK,EAAE,oBAAoB,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,KACzD,IAAI,CAAC;IACV,WAAW,CAAC,EAAE,CACZ,KAAK,EAAE,oBAAoB,CAAC;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,KACjE,IAAI,CAAC;IACV,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAkB9C,CAAC"}
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
- eventType: string;
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":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAI9C,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,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,CAAA;KAAE,CAAC,CAAC;IACnD,WAAW,CAAC,EAAE,kBAAkB,CAAC;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC9E,kBAAkB,CAAC,EAAE,KAAK,CAAC;CAC5B;;AAED,wBAAuE"}
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"}