react-native-advanced-text 0.1.1

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.
@@ -0,0 +1,20 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "AdvancedText"
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+ s.homepage = package["homepage"]
10
+ s.license = package["license"]
11
+ s.authors = package["author"]
12
+
13
+ s.platforms = { :ios => min_ios_version_supported }
14
+ s.source = { :git => "https://github.com/AminAllahham/react-native-advanced-text.git", :tag => "#{s.version}" }
15
+
16
+ s.source_files = "ios/**/*.{h,m,mm,swift,cpp}"
17
+ s.private_header_files = "ios/**/*.h"
18
+
19
+ install_modules_dependencies(s)
20
+ end
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Amin Al-lahham
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # react-native-advanced-text
2
+
3
+ Advanced text component for React Native with custom select options.
4
+
5
+ ## Installation
6
+
7
+
8
+ ```sh
9
+ npm install react-native-advanced-text
10
+ ```
11
+
12
+
13
+ ## Usage
14
+
15
+
16
+ ```js
17
+ import { AdvancedTextView } from "react-native-advanced-text";
18
+
19
+ // ...
20
+
21
+ <AdvancedTextView color="tomato" />
22
+ ```
23
+
24
+
25
+ ## Contributing
26
+
27
+ - [Development workflow](CONTRIBUTING.md#development-workflow)
28
+ - [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request)
29
+ - [Code of conduct](CODE_OF_CONDUCT.md)
30
+
31
+ ## License
32
+
33
+ MIT
34
+
35
+ ---
36
+
37
+ Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
@@ -0,0 +1,77 @@
1
+ buildscript {
2
+ ext.getExtOrDefault = {name ->
3
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['AdvancedText_' + name]
4
+ }
5
+
6
+ repositories {
7
+ google()
8
+ mavenCentral()
9
+ }
10
+
11
+ dependencies {
12
+ classpath "com.android.tools.build:gradle:8.7.2"
13
+ // noinspection DifferentKotlinGradleVersion
14
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
15
+ }
16
+ }
17
+
18
+
19
+ apply plugin: "com.android.library"
20
+ apply plugin: "kotlin-android"
21
+
22
+ apply plugin: "com.facebook.react"
23
+
24
+ def getExtOrIntegerDefault(name) {
25
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["AdvancedText_" + name]).toInteger()
26
+ }
27
+
28
+ android {
29
+ namespace "com.advancedtext"
30
+
31
+ compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
32
+
33
+ defaultConfig {
34
+ minSdkVersion getExtOrIntegerDefault("minSdkVersion")
35
+ targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
36
+ }
37
+
38
+ buildFeatures {
39
+ buildConfig true
40
+ }
41
+
42
+ buildTypes {
43
+ release {
44
+ minifyEnabled false
45
+ }
46
+ }
47
+
48
+ lintOptions {
49
+ disable "GradleCompatible"
50
+ }
51
+
52
+ compileOptions {
53
+ sourceCompatibility JavaVersion.VERSION_1_8
54
+ targetCompatibility JavaVersion.VERSION_1_8
55
+ }
56
+
57
+ sourceSets {
58
+ main {
59
+ java.srcDirs += [
60
+ "generated/java",
61
+ "generated/jni"
62
+ ]
63
+ }
64
+ }
65
+ }
66
+
67
+ repositories {
68
+ mavenCentral()
69
+ google()
70
+ }
71
+
72
+ def kotlin_version = getExtOrDefault("kotlinVersion")
73
+
74
+ dependencies {
75
+ implementation "com.facebook.react:react-android"
76
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
77
+ }
@@ -0,0 +1,5 @@
1
+ AdvancedText_kotlinVersion=2.0.21
2
+ AdvancedText_minSdkVersion=24
3
+ AdvancedText_targetSdkVersion=34
4
+ AdvancedText_compileSdkVersion=35
5
+ AdvancedText_ndkVersion=27.1.12297006
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,19 @@
1
+ package com.advancedtext
2
+
3
+ import com.facebook.react.ReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.uimanager.ViewManager
7
+ import java.util.ArrayList
8
+
9
+ class AdvancedTextViewPackage : ReactPackage {
10
+ override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
11
+ val viewManagers: MutableList<ViewManager<*, *>> = ArrayList()
12
+ viewManagers.add(AdvancedTextViewManager())
13
+ return viewManagers
14
+ }
15
+
16
+ override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
17
+ return emptyList()
18
+ }
19
+ }
@@ -0,0 +1,207 @@
1
+ package com.advancedtext
2
+
3
+ import android.content.Context
4
+ import android.graphics.Color
5
+ import android.text.SpannableString
6
+ import android.text.Spanned
7
+ import android.text.TextPaint
8
+ import android.text.method.LinkMovementMethod
9
+ import android.text.style.ClickableSpan
10
+ import android.text.style.BackgroundColorSpan
11
+ import android.util.AttributeSet
12
+ import android.view.ContextMenu
13
+ import android.view.MenuItem
14
+ import android.view.View
15
+ import android.widget.TextView
16
+ import com.facebook.react.bridge.Arguments
17
+ import com.facebook.react.bridge.ReactContext
18
+ import com.facebook.react.uimanager.events.RCTEventEmitter
19
+ import android.text.Selection
20
+
21
+ class AdvancedTextView : TextView, View.OnCreateContextMenuListener {
22
+ private var highlightedWords: List<HighlightedWord> = emptyList()
23
+ private var menuOptions: List<String> = emptyList()
24
+ private var indicatorWordIndex: Int = -1
25
+ private var lastSelectedText: String = ""
26
+ private var isSelectionEnabled: Boolean = true
27
+
28
+ constructor(context: Context?) : super(context) {
29
+ init()
30
+ }
31
+
32
+ constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {
33
+ init()
34
+ }
35
+
36
+ constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
37
+ context,
38
+ attrs,
39
+ defStyleAttr
40
+ ) {
41
+ init()
42
+ }
43
+
44
+ private fun init() {
45
+ movementMethod = LinkMovementMethod.getInstance()
46
+ setTextIsSelectable(true)
47
+ setOnCreateContextMenuListener(this)
48
+
49
+ setOnLongClickListener {
50
+ if (isSelectionEnabled) {
51
+ false
52
+ } else {
53
+ true
54
+ }
55
+ }
56
+ }
57
+
58
+ fun setHighlightedWords(highlightedWords: List<HighlightedWord>) {
59
+ this.highlightedWords = highlightedWords
60
+ updateTextWithHighlights()
61
+ }
62
+
63
+ fun setMenuOptions(menuOptions: List<String>) {
64
+ this.menuOptions = menuOptions
65
+ }
66
+
67
+ fun setIndicatorWordIndex(index: Int) {
68
+ this.indicatorWordIndex = index
69
+ updateTextWithHighlights()
70
+ }
71
+
72
+ fun setAdvancedText(text: String) {
73
+ this.text = text
74
+ updateTextWithHighlights()
75
+ }
76
+
77
+ private fun updateTextWithHighlights() {
78
+ val text = this.text.toString()
79
+ if (text.isEmpty()) return
80
+
81
+ val spannableString = SpannableString(text)
82
+ val words = text.split("\\s+".toRegex())
83
+
84
+ var currentIndex = 0
85
+ words.forEachIndexed { wordIndex, word ->
86
+ if (word.isNotEmpty()) {
87
+ val wordStart = text.indexOf(word, currentIndex)
88
+ if (wordStart >= 0) {
89
+ val wordEnd = wordStart + word.length
90
+
91
+ highlightedWords.find { it.index == wordIndex }?.let { highlightedWord ->
92
+ val color = Color.parseColor(highlightedWord.highlightColor)
93
+ spannableString.setSpan(
94
+ BackgroundColorSpan(color),
95
+ wordStart,
96
+ wordEnd,
97
+ Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
98
+ )
99
+ }
100
+
101
+ if (wordIndex == indicatorWordIndex) {
102
+ spannableString.setSpan(
103
+ IndicatorSpan(),
104
+ wordStart,
105
+ wordEnd,
106
+ Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
107
+ )
108
+ }
109
+
110
+ spannableString.setSpan(
111
+ WordClickableSpan(wordIndex, word),
112
+ wordStart,
113
+ wordEnd,
114
+ Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
115
+ )
116
+
117
+ currentIndex = wordEnd
118
+ }
119
+ }
120
+ }
121
+
122
+ this.text = spannableString
123
+ }
124
+
125
+ override fun onCreateContextMenu(menu: ContextMenu?, v: View?, menuInfo: ContextMenu.ContextMenuInfo?) {
126
+ val selectionStart = selectionStart
127
+ val selectionEnd = selectionEnd
128
+
129
+ if (selectionStart >= 0 && selectionEnd >= 0 && selectionStart != selectionEnd) {
130
+ lastSelectedText = text.subSequence(selectionStart, selectionEnd).toString()
131
+
132
+ menu?.clear()
133
+
134
+ menuOptions.forEachIndexed { index, option ->
135
+ menu?.add(0, index, index, option)?.setOnMenuItemClickListener {
136
+ onMenuItemClick(it, lastSelectedText)
137
+ true
138
+ }
139
+ }
140
+
141
+ sendSelectionEvent(lastSelectedText, "selection")
142
+ }
143
+ }
144
+
145
+ private fun onMenuItemClick(item: MenuItem, selectedText: String): Boolean {
146
+ val menuItemText = menuOptions[item.itemId]
147
+ sendSelectionEvent(selectedText, menuItemText)
148
+ return true
149
+ }
150
+
151
+ private fun sendSelectionEvent(selectedText: String, eventType: String) {
152
+ val reactContext = context as ReactContext
153
+ val event = Arguments.createMap().apply {
154
+ putString("selectedText", selectedText)
155
+ putString("event", eventType)
156
+ }
157
+ reactContext.getJSModule(RCTEventEmitter::class.java)
158
+ .receiveEvent(id, "onSelection", event)
159
+ }
160
+
161
+ private inner class WordClickableSpan(
162
+ private val wordIndex: Int,
163
+ private val word: String
164
+ ) : ClickableSpan() {
165
+ override fun onClick(widget: View) {
166
+ sendWordPressEvent(word, wordIndex)
167
+ }
168
+
169
+ override fun updateDrawState(ds: TextPaint) {
170
+ super.updateDrawState(ds)
171
+ ds.isUnderlineText = false
172
+ }
173
+ }
174
+
175
+ private inner class IndicatorSpan : ClickableSpan() {
176
+ override fun onClick(widget: View) {
177
+
178
+ }
179
+
180
+ override fun updateDrawState(ds: TextPaint) {
181
+ super.updateDrawState(ds)
182
+ ds.color = Color.RED
183
+ ds.isFakeBoldText = true
184
+ ds.isUnderlineText = false
185
+ }
186
+ }
187
+
188
+ private fun sendWordPressEvent(word: String, index: Int) {
189
+ val reactContext = context as ReactContext
190
+ val event = Arguments.createMap().apply {
191
+ putString("word", word)
192
+ putInt("index", index)
193
+ }
194
+ reactContext.getJSModule(RCTEventEmitter::class.java)
195
+ .receiveEvent(id, "onWordPress", event)
196
+ }
197
+
198
+ fun clearSelection() {
199
+ val spannable = this.text as? android.text.Spannable ?: return
200
+ Selection.removeSelection(spannable)
201
+ }
202
+ }
203
+
204
+ data class HighlightedWord(
205
+ val index: Int,
206
+ val highlightColor: String
207
+ )
@@ -0,0 +1,80 @@
1
+ package com.advancedtext
2
+
3
+ import com.facebook.react.bridge.ReadableArray
4
+ import com.facebook.react.module.annotations.ReactModule
5
+ import com.facebook.react.uimanager.SimpleViewManager
6
+ import com.facebook.react.uimanager.ThemedReactContext
7
+ import com.facebook.react.uimanager.ViewManagerDelegate
8
+ import com.facebook.react.uimanager.annotations.ReactProp
9
+ import com.facebook.react.viewmanagers.AdvancedTextViewManagerInterface
10
+ import com.facebook.react.viewmanagers.AdvancedTextViewManagerDelegate
11
+
12
+ @ReactModule(name = AdvancedTextViewManager.NAME)
13
+ class AdvancedTextViewManager : SimpleViewManager<AdvancedTextView>(),
14
+ AdvancedTextViewManagerInterface<AdvancedTextView> {
15
+ private val mDelegate: ViewManagerDelegate<AdvancedTextView>
16
+
17
+ init {
18
+ mDelegate = AdvancedTextViewManagerDelegate(this)
19
+ }
20
+
21
+ override fun getDelegate(): ViewManagerDelegate<AdvancedTextView>? {
22
+ return mDelegate
23
+ }
24
+
25
+ override fun getName(): String {
26
+ return NAME
27
+ }
28
+
29
+ public override fun createViewInstance(context: ThemedReactContext): AdvancedTextView {
30
+ return AdvancedTextView(context)
31
+ }
32
+
33
+ @ReactProp(name = "text")
34
+ override fun setText(view: AdvancedTextView?, text: String?) {
35
+ view?.setAdvancedText(text ?: "")
36
+ }
37
+
38
+ @ReactProp(name = "highlightedWords")
39
+ override fun setHighlightedWords(view: AdvancedTextView?, highlightedWords: ReadableArray?) {
40
+ val words = mutableListOf<HighlightedWord>()
41
+ highlightedWords?.let {
42
+ for (i in 0 until it.size()) {
43
+ val map = it.getMap(i)
44
+ map?.let { wordMap ->
45
+ words.add(
46
+ HighlightedWord(
47
+ index = wordMap.getInt("index"),
48
+ highlightColor = wordMap.getString("highlightColor") ?: "#FFFF00"
49
+ )
50
+ )
51
+ }
52
+ }
53
+ }
54
+ view?.setHighlightedWords(words)
55
+ }
56
+
57
+ @ReactProp(name = "menuOptions")
58
+ override fun setMenuOptions(view: AdvancedTextView?, menuOptions: ReadableArray?) {
59
+ val options = mutableListOf<String>()
60
+ menuOptions?.let {
61
+ for (i in 0 until it.size()) {
62
+ it.getString(i)?.let { option ->
63
+ options.add(option)
64
+ }
65
+ }
66
+ }
67
+ view?.setMenuOptions(options)
68
+ }
69
+
70
+ @ReactProp(name = "indicatorWordIndex")
71
+ override fun setIndicatorWordIndex(view: AdvancedTextView?, index: Int) {
72
+ view?.setIndicatorWordIndex(index)
73
+ }
74
+
75
+
76
+
77
+ companion object {
78
+ const val NAME = "AdvancedTextView"
79
+ }
80
+ }
@@ -0,0 +1,14 @@
1
+ #import <React/RCTViewComponentView.h>
2
+ #import <UIKit/UIKit.h>
3
+
4
+ #ifndef AdvancedTextViewNativeComponent_h
5
+ #define AdvancedTextViewNativeComponent_h
6
+
7
+ NS_ASSUME_NONNULL_BEGIN
8
+
9
+ @interface AdvancedTextView : RCTViewComponentView
10
+ @end
11
+
12
+ NS_ASSUME_NONNULL_END
13
+
14
+ #endif /* AdvancedTextViewNativeComponent_h */
@@ -0,0 +1,71 @@
1
+ #import "AdvancedTextView.h"
2
+
3
+ #import <react/renderer/components/AdvancedTextViewSpec/ComponentDescriptors.h>
4
+ #import <react/renderer/components/AdvancedTextViewSpec/EventEmitters.h>
5
+ #import <react/renderer/components/AdvancedTextViewSpec/Props.h>
6
+ #import <react/renderer/components/AdvancedTextViewSpec/RCTComponentViewHelpers.h>
7
+
8
+ #import "RCTFabricComponentsPlugins.h"
9
+
10
+ using namespace facebook::react;
11
+
12
+ @interface AdvancedTextView () <RCTAdvancedTextViewViewProtocol>
13
+
14
+ @end
15
+
16
+ @implementation AdvancedTextView {
17
+ UIView * _view;
18
+ }
19
+
20
+ + (ComponentDescriptorProvider)componentDescriptorProvider
21
+ {
22
+ return concreteComponentDescriptorProvider<AdvancedTextViewComponentDescriptor>();
23
+ }
24
+
25
+ - (instancetype)initWithFrame:(CGRect)frame
26
+ {
27
+ if (self = [super initWithFrame:frame]) {
28
+ static const auto defaultProps = std::make_shared<const AdvancedTextViewProps>();
29
+ _props = defaultProps;
30
+
31
+ _view = [[UIView alloc] init];
32
+
33
+ self.contentView = _view;
34
+ }
35
+
36
+ return self;
37
+ }
38
+
39
+ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
40
+ {
41
+ const auto &oldViewProps = *std::static_pointer_cast<AdvancedTextViewProps const>(_props);
42
+ const auto &newViewProps = *std::static_pointer_cast<AdvancedTextViewProps const>(props);
43
+
44
+ if (oldViewProps.color != newViewProps.color) {
45
+ NSString * colorToConvert = [[NSString alloc] initWithUTF8String: newViewProps.color.c_str()];
46
+ [_view setBackgroundColor:[self hexStringToColor:colorToConvert]];
47
+ }
48
+
49
+ [super updateProps:props oldProps:oldProps];
50
+ }
51
+
52
+ Class<RCTComponentViewProtocol> AdvancedTextViewCls(void)
53
+ {
54
+ return AdvancedTextView.class;
55
+ }
56
+
57
+ - hexStringToColor:(NSString *)stringToConvert
58
+ {
59
+ NSString *noHashString = [stringToConvert stringByReplacingOccurrencesOfString:@"#" withString:@""];
60
+ NSScanner *stringScanner = [NSScanner scannerWithString:noHashString];
61
+
62
+ unsigned hex;
63
+ if (![stringScanner scanHexInt:&hex]) return nil;
64
+ int r = (hex >> 16) & 0xFF;
65
+ int g = (hex >> 8) & 0xFF;
66
+ int b = (hex) & 0xFF;
67
+
68
+ return [UIColor colorWithRed:r / 255.0f green:g / 255.0f blue:b / 255.0f alpha:1.0f];
69
+ }
70
+
71
+ @end
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ import AdvancedTextViewNativeComponent from './AdvancedTextViewNativeComponent';
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+ export const AdvancedText = ({
6
+ text,
7
+ highlightedWords,
8
+ menuOptions,
9
+ onWordPress,
10
+ onSelection,
11
+ indicatorWordIndex,
12
+ ...restProps
13
+ }) => {
14
+ return /*#__PURE__*/_jsx(AdvancedTextViewNativeComponent, {
15
+ text: text,
16
+ highlightedWords: highlightedWords,
17
+ menuOptions: menuOptions,
18
+ onWordPress: onWordPress,
19
+ onSelection: onSelection,
20
+ indicatorWordIndex: indicatorWordIndex,
21
+ ...restProps
22
+ });
23
+ };
24
+ //# sourceMappingURL=AdvancedText.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["AdvancedTextViewNativeComponent","jsx","_jsx","AdvancedText","text","highlightedWords","menuOptions","onWordPress","onSelection","indicatorWordIndex","restProps"],"sourceRoot":"..\\..\\src","sources":["AdvancedText.tsx"],"mappings":";;AACA,OAAOA,+BAA+B,MAAM,mCAAmC;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAkBhF,OAAO,MAAMC,YAAmC,GAAGA,CAAC;EAClDC,IAAI;EACJC,gBAAgB;EAChBC,WAAW;EACXC,WAAW;EACXC,WAAW;EACXC,kBAAkB;EAClB,GAAGC;AACL,CAAC,KAAK;EACJ,oBACER,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,kBAAmB;IAAA,GACnCC;EAAS,CACd,CAAC;AAEN,CAAC","ignoreList":[]}
@@ -0,0 +1,20 @@
1
+ import { codegenNativeComponent } from 'react-native';
2
+ import type { ViewProps } from 'react-native';
3
+ // @ts-ignore
4
+ import type { DirectEventHandler, Int32 } from 'react-native/Libraries/Types/CodegenTypes';
5
+
6
+ interface HighlightedWord {
7
+ index: Int32;
8
+ highlightColor: string;
9
+ }
10
+
11
+ interface NativeProps extends ViewProps {
12
+ text: string;
13
+ highlightedWords?: ReadonlyArray<HighlightedWord>;
14
+ menuOptions?: ReadonlyArray<string>;
15
+ onWordPress?: DirectEventHandler<{ word: string }>;
16
+ onSelection?: DirectEventHandler<{ selectedText: string; eventType: string }>;
17
+ indicatorWordIndex?: Int32;
18
+ }
19
+
20
+ export default codegenNativeComponent<NativeProps>('AdvancedTextView');
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ export { AdvancedText } from "./AdvancedText.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["AdvancedText"],"sourceRoot":"..\\..\\src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,mBAAgB","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,21 @@
1
+ import type { NativeSyntheticEvent, ViewProps } from 'react-native';
2
+ interface HighlightedWord {
3
+ index: number;
4
+ highlightColor: string;
5
+ }
6
+ interface NativeProps extends ViewProps {
7
+ text: string;
8
+ highlightedWords?: ReadonlyArray<HighlightedWord>;
9
+ menuOptions?: ReadonlyArray<string>;
10
+ onWordPress?: (event: NativeSyntheticEvent<{
11
+ word: string;
12
+ }>) => void;
13
+ onSelection?: (event: NativeSyntheticEvent<{
14
+ selectedText: string;
15
+ eventType: string;
16
+ }>) => void;
17
+ indicatorWordIndex?: number;
18
+ }
19
+ export declare const AdvancedText: React.FC<NativeProps>;
20
+ export {};
21
+ //# sourceMappingURL=AdvancedText.d.ts.map
@@ -0,0 +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;IAClD,WAAW,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACpC,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,oBAAoB,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,KAAK,IAAI,CAAC;IACtE,WAAW,CAAC,EAAE,CACZ,KAAK,EAAE,oBAAoB,CAAC;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,KACrE,IAAI,CAAC;IACV,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAoB9C,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { ViewProps } from 'react-native';
2
+ import type { DirectEventHandler, Int32 } from 'react-native/Libraries/Types/CodegenTypes';
3
+ interface HighlightedWord {
4
+ index: Int32;
5
+ highlightColor: string;
6
+ }
7
+ interface NativeProps extends ViewProps {
8
+ text: string;
9
+ highlightedWords?: ReadonlyArray<HighlightedWord>;
10
+ menuOptions?: ReadonlyArray<string>;
11
+ onWordPress?: DirectEventHandler<{
12
+ word: string;
13
+ }>;
14
+ onSelection?: DirectEventHandler<{
15
+ selectedText: string;
16
+ eventType: string;
17
+ }>;
18
+ indicatorWordIndex?: Int32;
19
+ }
20
+ declare const _default: import("react-native/types_generated/Libraries/Utilities/codegenNativeComponent").NativeComponentType<NativeProps>;
21
+ export default _default;
22
+ //# sourceMappingURL=AdvancedTextViewNativeComponent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AdvancedTextViewNativeComponent.d.ts","sourceRoot":"","sources":["../../../src/AdvancedTextViewNativeComponent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,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"}
@@ -0,0 +1,2 @@
1
+ export { AdvancedText } from './AdvancedText';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,175 @@
1
+ {
2
+ "name": "react-native-advanced-text",
3
+ "version": "0.1.1",
4
+ "description": " Advanced text component for React Native with custom select options.",
5
+ "main": "./lib/module/index.js",
6
+ "types": "./lib/typescript/src/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "source": "./src/index.tsx",
10
+ "types": "./lib/typescript/src/index.d.ts",
11
+ "default": "./lib/module/index.js"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "files": [
16
+ "src",
17
+ "lib",
18
+ "android",
19
+ "ios",
20
+ "cpp",
21
+ "*.podspec",
22
+ "react-native.config.js",
23
+ "!ios/build",
24
+ "!android/build",
25
+ "!android/gradle",
26
+ "!android/gradlew",
27
+ "!android/gradlew.bat",
28
+ "!android/local.properties",
29
+ "!**/__tests__",
30
+ "!**/__fixtures__",
31
+ "!**/__mocks__",
32
+ "!**/.*"
33
+ ],
34
+ "scripts": {
35
+ "example": "yarn workspace react-native-advanced-text-example",
36
+ "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
37
+ "prepare": "bob build",
38
+ "typecheck": "tsc",
39
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
40
+ "release": "release-it --only-version",
41
+ "test": "jest"
42
+ },
43
+ "keywords": [
44
+ "react-native",
45
+ "ios",
46
+ "android"
47
+ ],
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "git+https://github.com/AminAllahham/react-native-advanced-text.git"
51
+ },
52
+ "author": "Amin Al-lahham <amin.allahham9@gmail.com> (https://github.com/AminAllahham)",
53
+ "license": "MIT",
54
+ "bugs": {
55
+ "url": "https://github.com/AminAllahham/react-native-advanced-text/issues"
56
+ },
57
+ "homepage": "https://github.com/AminAllahham/react-native-advanced-text#readme",
58
+ "publishConfig": {
59
+ "registry": "https://registry.npmjs.org/"
60
+ },
61
+ "devDependencies": {
62
+ "@commitlint/config-conventional": "^19.8.1",
63
+ "@eslint/compat": "^1.3.2",
64
+ "@eslint/eslintrc": "^3.3.1",
65
+ "@eslint/js": "^9.35.0",
66
+ "@react-native-community/cli": "20.0.1",
67
+ "@react-native/babel-preset": "0.81.1",
68
+ "@react-native/eslint-config": "^0.81.1",
69
+ "@release-it/conventional-changelog": "^10.0.1",
70
+ "@types/jest": "^29.5.14",
71
+ "@types/react": "^19.1.0",
72
+ "commitlint": "^19.8.1",
73
+ "del-cli": "^6.0.0",
74
+ "eslint": "^9.35.0",
75
+ "eslint-config-prettier": "^10.1.8",
76
+ "eslint-plugin-prettier": "^5.5.4",
77
+ "jest": "^29.7.0",
78
+ "lefthook": "^2.0.3",
79
+ "prettier": "^2.8.8",
80
+ "react": "19.1.0",
81
+ "react-native": "0.81.1",
82
+ "react-native-builder-bob": "^0.40.16",
83
+ "release-it": "^19.0.4",
84
+ "turbo": "^2.5.6",
85
+ "typescript": "^5.9.2"
86
+ },
87
+ "peerDependencies": {
88
+ "react": "*",
89
+ "react-native": "*"
90
+ },
91
+ "workspaces": [
92
+ "example"
93
+ ],
94
+ "packageManager": "yarn@4.11.0",
95
+ "react-native-builder-bob": {
96
+ "source": "src",
97
+ "output": "lib",
98
+ "targets": [
99
+ [
100
+ "module",
101
+ {
102
+ "esm": true
103
+ }
104
+ ],
105
+ [
106
+ "typescript",
107
+ {
108
+ "project": "tsconfig.build.json"
109
+ }
110
+ ]
111
+ ]
112
+ },
113
+ "codegenConfig": {
114
+ "name": "AdvancedTextViewSpec",
115
+ "type": "all",
116
+ "jsSrcsDir": "src",
117
+ "android": {
118
+ "javaPackageName": "com.advancedtext"
119
+ },
120
+ "ios": {
121
+ "componentProvider": {
122
+ "AdvancedTextView": "AdvancedTextView"
123
+ }
124
+ }
125
+ },
126
+ "prettier": {
127
+ "quoteProps": "consistent",
128
+ "singleQuote": true,
129
+ "tabWidth": 2,
130
+ "trailingComma": "es5",
131
+ "useTabs": false
132
+ },
133
+ "commitlint": {
134
+ "extends": [
135
+ "@commitlint/config-conventional"
136
+ ]
137
+ },
138
+ "release-it": {
139
+ "git": {
140
+ "commitMessage": "chore: release ${version}",
141
+ "tagName": "v${version}"
142
+ },
143
+ "npm": {
144
+ "publish": true
145
+ },
146
+ "github": {
147
+ "release": true
148
+ },
149
+ "plugins": {
150
+ "@release-it/conventional-changelog": {
151
+ "preset": {
152
+ "name": "angular"
153
+ }
154
+ }
155
+ }
156
+ },
157
+ "jest": {
158
+ "preset": "react-native",
159
+ "modulePathIgnorePatterns": [
160
+ "<rootDir>/example/node_modules",
161
+ "<rootDir>/lib/"
162
+ ]
163
+ },
164
+ "create-react-native-library": {
165
+ "languages": "kotlin-objc",
166
+ "type": "fabric-view",
167
+ "tools": [
168
+ "eslint",
169
+ "lefthook",
170
+ "release-it",
171
+ "jest"
172
+ ],
173
+ "version": "0.55.1"
174
+ }
175
+ }
@@ -0,0 +1,40 @@
1
+ import type { NativeSyntheticEvent, ViewProps } from 'react-native';
2
+ import AdvancedTextViewNativeComponent from './AdvancedTextViewNativeComponent';
3
+
4
+ interface HighlightedWord {
5
+ index: number;
6
+ highlightColor: string;
7
+ }
8
+
9
+ interface NativeProps extends ViewProps {
10
+ text: string;
11
+ highlightedWords?: ReadonlyArray<HighlightedWord>;
12
+ menuOptions?: ReadonlyArray<string>;
13
+ onWordPress?: (event: NativeSyntheticEvent<{ word: string }>) => void;
14
+ onSelection?: (
15
+ event: NativeSyntheticEvent<{ selectedText: string; eventType: string }>
16
+ ) => void;
17
+ indicatorWordIndex?: number;
18
+ }
19
+
20
+ export const AdvancedText: React.FC<NativeProps> = ({
21
+ text,
22
+ highlightedWords,
23
+ menuOptions,
24
+ onWordPress,
25
+ onSelection,
26
+ indicatorWordIndex,
27
+ ...restProps
28
+ }) => {
29
+ return (
30
+ <AdvancedTextViewNativeComponent
31
+ text={text}
32
+ highlightedWords={highlightedWords}
33
+ menuOptions={menuOptions}
34
+ onWordPress={onWordPress}
35
+ onSelection={onSelection}
36
+ indicatorWordIndex={indicatorWordIndex}
37
+ {...restProps}
38
+ />
39
+ );
40
+ };
@@ -0,0 +1,20 @@
1
+ import { codegenNativeComponent } from 'react-native';
2
+ import type { ViewProps } from 'react-native';
3
+ // @ts-ignore
4
+ import type { DirectEventHandler, Int32 } from 'react-native/Libraries/Types/CodegenTypes';
5
+
6
+ interface HighlightedWord {
7
+ index: Int32;
8
+ highlightColor: string;
9
+ }
10
+
11
+ interface NativeProps extends ViewProps {
12
+ text: string;
13
+ highlightedWords?: ReadonlyArray<HighlightedWord>;
14
+ menuOptions?: ReadonlyArray<string>;
15
+ onWordPress?: DirectEventHandler<{ word: string }>;
16
+ onSelection?: DirectEventHandler<{ selectedText: string; eventType: string }>;
17
+ indicatorWordIndex?: Int32;
18
+ }
19
+
20
+ export default codegenNativeComponent<NativeProps>('AdvancedTextView');
package/src/index.tsx ADDED
@@ -0,0 +1 @@
1
+ export { AdvancedText } from './AdvancedText';