react-native-highlight-text-view 0.1.11 → 0.1.12

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.
@@ -264,22 +264,44 @@ class HighlightTextView : AppCompatEditText {
264
264
  }
265
265
 
266
266
  private fun updateFont() {
267
- val style = when (currentFontWeight) {
268
- "bold", "700", "800", "900" -> Typeface.BOLD
269
- "100", "200", "300" -> Typeface.NORMAL // Android doesn't have lighter than normal
270
- else -> Typeface.NORMAL
267
+ // Parse font weight to integer (100-900)
268
+ val weight = when (currentFontWeight) {
269
+ "100" -> 100
270
+ "200" -> 200
271
+ "300" -> 300
272
+ "400", "normal" -> 400
273
+ "500" -> 500
274
+ "600" -> 600
275
+ "700", "bold" -> 700
276
+ "800" -> 800
277
+ "900" -> 900
278
+ else -> 400
271
279
  }
272
280
 
273
- val typeface = if (currentFontFamily != null) {
281
+ // Get base typeface
282
+ val baseTypeface = if (currentFontFamily != null) {
274
283
  when (currentFontFamily?.lowercase()) {
275
- "system" -> Typeface.create(Typeface.DEFAULT, style)
276
- "sans-serif" -> Typeface.create(Typeface.SANS_SERIF, style)
277
- "serif" -> Typeface.create(Typeface.SERIF, style)
278
- "monospace" -> Typeface.create(Typeface.MONOSPACE, style)
279
- else -> Typeface.create(currentFontFamily, style)
284
+ "system" -> Typeface.DEFAULT
285
+ "sans-serif" -> Typeface.SANS_SERIF
286
+ "serif" -> Typeface.SERIF
287
+ "monospace" -> Typeface.MONOSPACE
288
+ else -> try {
289
+ Typeface.create(currentFontFamily, Typeface.NORMAL)
290
+ } catch (e: Exception) {
291
+ Typeface.DEFAULT
292
+ }
280
293
  }
281
294
  } else {
282
- Typeface.create(Typeface.DEFAULT, style)
295
+ Typeface.DEFAULT
296
+ }
297
+
298
+ // Apply font weight - use API 28+ method for better weight support
299
+ val typeface = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
300
+ Typeface.create(baseTypeface, weight, false)
301
+ } else {
302
+ // Fallback for older Android versions
303
+ val style = if (weight >= 600) Typeface.BOLD else Typeface.NORMAL
304
+ Typeface.create(baseTypeface, style)
283
305
  }
284
306
 
285
307
  this.typeface = typeface
@@ -128,7 +128,7 @@ class HighlightTextViewManager : SimpleViewManager<HighlightTextView>(),
128
128
  @ReactProp(name = "fontSize")
129
129
  override fun setFontSize(view: HighlightTextView?, value: String?) {
130
130
  value?.toFloatOrNull()?.let { size ->
131
- view?.textSize = size
131
+ view?.setTextSize(android.util.TypedValue.COMPLEX_UNIT_SP, size)
132
132
  }
133
133
  }
134
134
 
@@ -89,6 +89,7 @@ using namespace facebook::react;
89
89
  CGFloat _backgroundInsetLeft;
90
90
  CGFloat _backgroundInsetRight;
91
91
  CGFloat _lineHeight;
92
+ CGFloat _fontSize;
92
93
  NSString * _fontFamily;
93
94
  NSString * _fontWeight;
94
95
  BOOL _isUpdatingText;
@@ -120,6 +121,7 @@ using namespace facebook::react;
120
121
  _backgroundInsetLeft = 0.0;
121
122
  _backgroundInsetRight = 0.0;
122
123
  _lineHeight = 0.0; // 0 means use default line height
124
+ _fontSize = 32.0; // Default font size
123
125
  _fontFamily = nil;
124
126
  _fontWeight = @"normal";
125
127
  _currentVerticalAlignment = nil;
@@ -280,6 +282,7 @@ using namespace facebook::react;
280
282
  NSString *fontSizeStr = [[NSString alloc] initWithUTF8String: newViewProps.fontSize.c_str()];
281
283
  CGFloat fontSize = [fontSizeStr floatValue];
282
284
  if (fontSize > 0) {
285
+ _fontSize = fontSize;
283
286
  [self updateFont];
284
287
  }
285
288
  }
@@ -459,7 +462,7 @@ Class<RCTComponentViewProtocol> HighlightTextViewCls(void)
459
462
 
460
463
  - (void)updateFont
461
464
  {
462
- CGFloat fontSize = _textView.font.pointSize;
465
+ CGFloat fontSize = _fontSize > 0 ? _fontSize : 32.0;
463
466
  UIFont *newFont = nil;
464
467
 
465
468
  // Parse font weight
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-highlight-text-view",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "A native text input for React Native that supports inline text highlighting",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",