react-native-advanced-text 0.1.29 → 0.1.31

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.
@@ -138,6 +138,13 @@ class AdvancedTextView : TextView {
138
138
  }
139
139
  }
140
140
 
141
+ fun setAdvancedLineHeight(multiplier: Float) {
142
+ if (lineHeightMultiplier == multiplier) return
143
+ lineHeightMultiplier = multiplier
144
+ updateTextWithHighlights()
145
+ }
146
+
147
+
141
148
  fun setAdvancedFontFamily(family: String) {
142
149
  if (fontFamily == family) return
143
150
  fontFamily = family
@@ -235,6 +242,11 @@ class AdvancedTextView : TextView {
235
242
  else -> Typeface.create(fontFamily, Typeface.NORMAL)
236
243
  }
237
244
 
245
+
246
+ lineSpacingMultiplier = lineHeightMultiplier
247
+ setLineSpacing(0f, lineHeightMultiplier)
248
+
249
+
238
250
  post {
239
251
  setText(spannableString, BufferType.SPANNABLE)
240
252
  Log.d(TAG, "Text updated with ${wordPositions.size} spans")
@@ -123,6 +123,15 @@ class AdvancedTextViewManager : SimpleViewManager<AdvancedTextView>() {
123
123
  }
124
124
  }
125
125
 
126
+
127
+ @ReactProp(name = "lineHeight")
128
+ fun setLineHeight(view: AdvancedTextView?, lineHeight: Float) {
129
+ android.util.Log.d(NAME, "setLineHeight called with: $lineHeight")
130
+ if (lineHeight > 0) {
131
+ view?.setAdvancedLineHeight(lineHeight)
132
+ }
133
+ }
134
+
126
135
  override fun getExportedCustomDirectEventTypeConstants(): Map<String, Any> {
127
136
  return mapOf(
128
137
  "onWordPress" to mapOf("registrationName" to "onWordPress"),
@@ -23,6 +23,7 @@ using namespace facebook::react;
23
23
  @property (nonatomic, strong) UIColor *textColor;
24
24
  @property (nonatomic, strong) NSString *textAlign;
25
25
  @property (nonatomic, strong) NSString *fontFamily;
26
+ @property (nonatomic, assign) CGFloat lineHeight;
26
27
 
27
28
  - (void)handleCustomMenuAction:(UIMenuItem *)sender;
28
29
 
@@ -89,6 +90,7 @@ using namespace facebook::react;
89
90
  _textColor = [UIColor labelColor];
90
91
  _textAlign = @"left";
91
92
  _fontFamily = @"System";
93
+ _lineHeight = 0.0;
92
94
 
93
95
  [self setupTextView];
94
96
  [self setupGestureRecognizers];
@@ -220,6 +222,12 @@ using namespace facebook::react;
220
222
  indicatorChanged = YES;
221
223
  }
222
224
 
225
+ if (oldViewProps.lineHeight != newViewProps.lineHeight) {
226
+ NSLog(@"[AdvancedTextView] Updating lineHeight to: %f", newViewProps.lineHeight);
227
+ _lineHeight = static_cast<CGFloat>(newViewProps.lineHeight);
228
+ styleChanged = YES;
229
+ }
230
+
223
231
  if (textChanged) {
224
232
  NSString *text = [NSString stringWithUTF8String:newViewProps.text.c_str()];
225
233
  [self updateTextContent:text];
@@ -356,7 +364,25 @@ using namespace facebook::react;
356
364
  NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]
357
365
  initWithString:_textView.text];
358
366
 
367
+ if (_lineHeight > 0) {
368
+ NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
359
369
 
370
+ UIFont *font = nil;
371
+ if (_fontFamily && _fontFamily.length > 0) {
372
+ font = [UIFont fontWithName:_fontFamily size:_fontSize > 0 ? _fontSize : 16.0];
373
+ }
374
+ if (!font) {
375
+ font = [UIFont systemFontOfSize:_fontSize > 0 ? _fontSize : 16.0];
376
+ }
377
+
378
+ CGFloat lineSpacing = (_lineHeight * font.lineHeight) - font.lineHeight;
379
+ paragraphStyle.lineSpacing = lineSpacing;
380
+
381
+ [attributedString addAttribute:NSParagraphStyleAttributeName
382
+ value:paragraphStyle
383
+ range:NSMakeRange(0, attributedString.length)];
384
+ }
385
+
360
386
  UIFont *font = nil;
361
387
 
362
388
  if (_fontFamily && _fontFamily.length > 0) {
@@ -1,26 +1,27 @@
1
- /* eslint-disable prettier/prettier */
2
- import type { ViewProps } from 'react-native';
3
- import { codegenNativeComponent } from 'react-native';
4
- // @ts-ignore
5
- import type { DirectEventHandler, Int32 } from 'react-native/Libraries/Types/CodegenTypes';
6
-
7
- interface HighlightedWord {
8
- index: Int32;
9
- highlightColor: string;
10
- }
11
-
12
- export interface NativeProps extends ViewProps {
13
- text: string;
14
- highlightedWords?: ReadonlyArray<HighlightedWord>;
15
- menuOptions?: ReadonlyArray<string>;
16
- onWordPress?: DirectEventHandler<{ word: string; index: Int32 }>;
17
- onSelection?: DirectEventHandler<{ selectedText: string; event: string }>;
18
- indicatorWordIndex?: Int32;
19
- fontSize?: Int32;
20
- fontWeight?: string;
21
- color?: string;
22
- textAlign?: string;
23
- fontFamily?: string;
24
- }
25
-
26
- export default codegenNativeComponent<NativeProps>('AdvancedTextView');
1
+ /* eslint-disable prettier/prettier */
2
+ import type { ViewProps } from 'react-native';
3
+ import { codegenNativeComponent } from 'react-native';
4
+ // @ts-ignore
5
+ import type { DirectEventHandler, Int32 , Float } from 'react-native/Libraries/Types/CodegenTypes';
6
+
7
+ interface HighlightedWord {
8
+ index: Int32;
9
+ highlightColor: string;
10
+ }
11
+
12
+ export interface NativeProps extends ViewProps {
13
+ text: string;
14
+ highlightedWords?: ReadonlyArray<HighlightedWord>;
15
+ menuOptions?: ReadonlyArray<string>;
16
+ onWordPress?: DirectEventHandler<{ word: string; index: Int32 }>;
17
+ onSelection?: DirectEventHandler<{ selectedText: string; event: string }>;
18
+ indicatorWordIndex?: Int32;
19
+ fontSize?: Int32;
20
+ fontWeight?: string;
21
+ color?: string;
22
+ textAlign?: string;
23
+ fontFamily?: string;
24
+ lineHeight?: Float;
25
+ }
26
+
27
+ export default codegenNativeComponent<NativeProps>('AdvancedTextView');
@@ -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, Int32, Float } from 'react-native/Libraries/Types/CodegenTypes';
3
3
  interface HighlightedWord {
4
4
  index: Int32;
5
5
  highlightColor: string;
@@ -22,6 +22,7 @@ export interface NativeProps extends ViewProps {
22
22
  color?: string;
23
23
  textAlign?: string;
24
24
  fontFamily?: string;
25
+ lineHeight?: Float;
25
26
  }
26
27
  declare const _default: import("react-native/types_generated/Libraries/Utilities/codegenNativeComponent").NativeComponentType<NativeProps>;
27
28
  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,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"}
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,EAAG,KAAK,EAAG,MAAM,2CAA2C,CAAC;AAEpG,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;IACpB,UAAU,CAAC,EAAE,KAAK,CAAC;CACpB;;AAED,wBAAuE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-advanced-text",
3
- "version": "0.1.29",
3
+ "version": "0.1.31",
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,26 +1,27 @@
1
- /* eslint-disable prettier/prettier */
2
- import type { ViewProps } from 'react-native';
3
- import { codegenNativeComponent } from 'react-native';
4
- // @ts-ignore
5
- import type { DirectEventHandler, Int32 } from 'react-native/Libraries/Types/CodegenTypes';
6
-
7
- interface HighlightedWord {
8
- index: Int32;
9
- highlightColor: string;
10
- }
11
-
12
- export interface NativeProps extends ViewProps {
13
- text: string;
14
- highlightedWords?: ReadonlyArray<HighlightedWord>;
15
- menuOptions?: ReadonlyArray<string>;
16
- onWordPress?: DirectEventHandler<{ word: string; index: Int32 }>;
17
- onSelection?: DirectEventHandler<{ selectedText: string; event: string }>;
18
- indicatorWordIndex?: Int32;
19
- fontSize?: Int32;
20
- fontWeight?: string;
21
- color?: string;
22
- textAlign?: string;
23
- fontFamily?: string;
24
- }
25
-
26
- export default codegenNativeComponent<NativeProps>('AdvancedTextView');
1
+ /* eslint-disable prettier/prettier */
2
+ import type { ViewProps } from 'react-native';
3
+ import { codegenNativeComponent } from 'react-native';
4
+ // @ts-ignore
5
+ import type { DirectEventHandler, Int32 , Float } from 'react-native/Libraries/Types/CodegenTypes';
6
+
7
+ interface HighlightedWord {
8
+ index: Int32;
9
+ highlightColor: string;
10
+ }
11
+
12
+ export interface NativeProps extends ViewProps {
13
+ text: string;
14
+ highlightedWords?: ReadonlyArray<HighlightedWord>;
15
+ menuOptions?: ReadonlyArray<string>;
16
+ onWordPress?: DirectEventHandler<{ word: string; index: Int32 }>;
17
+ onSelection?: DirectEventHandler<{ selectedText: string; event: string }>;
18
+ indicatorWordIndex?: Int32;
19
+ fontSize?: Int32;
20
+ fontWeight?: string;
21
+ color?: string;
22
+ textAlign?: string;
23
+ fontFamily?: string;
24
+ lineHeight?: Float;
25
+ }
26
+
27
+ export default codegenNativeComponent<NativeProps>('AdvancedTextView');