@chaitrabhairappa/react-native-rich-text-editor 3.1.0 → 3.3.0

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.
Files changed (44) hide show
  1. package/README.md +5 -0
  2. package/android/src/main/java/com/richtext/editor/FloatingToolbar.kt +12 -12
  3. package/android/src/main/java/com/richtext/editor/RichTextEditorView.kt +42 -5
  4. package/android/src/main/java/com/richtext/editor/RichTextEditorViewManager.kt +27 -0
  5. package/android/src/main/java/com/richtext/editor/ToolbarIcons.kt +67 -0
  6. package/android/src/main/res/drawable/ic_format_align_center.xml +3 -3
  7. package/android/src/main/res/drawable/ic_format_align_left.xml +3 -3
  8. package/android/src/main/res/drawable/ic_format_align_right.xml +3 -3
  9. package/android/src/main/res/drawable/ic_format_bold.xml +3 -3
  10. package/android/src/main/res/drawable/ic_format_checklist.xml +3 -3
  11. package/android/src/main/res/drawable/ic_format_clear.xml +3 -3
  12. package/android/src/main/res/drawable/ic_format_code.xml +3 -3
  13. package/android/src/main/res/drawable/ic_format_heading.xml +3 -3
  14. package/android/src/main/res/drawable/ic_format_highlight.xml +3 -3
  15. package/android/src/main/res/drawable/ic_format_indent.xml +3 -3
  16. package/android/src/main/res/drawable/ic_format_italic.xml +3 -3
  17. package/android/src/main/res/drawable/ic_format_link.xml +3 -3
  18. package/android/src/main/res/drawable/ic_format_list_bulleted.xml +3 -3
  19. package/android/src/main/res/drawable/ic_format_list_numbered.xml +3 -3
  20. package/android/src/main/res/drawable/ic_format_media_attachment.xml +3 -3
  21. package/android/src/main/res/drawable/ic_format_outdent.xml +3 -3
  22. package/android/src/main/res/drawable/ic_format_quote.xml +3 -3
  23. package/android/src/main/res/drawable/ic_format_redo.xml +3 -3
  24. package/android/src/main/res/drawable/ic_format_strikethrough.xml +3 -3
  25. package/android/src/main/res/drawable/ic_format_underline.xml +3 -3
  26. package/android/src/main/res/drawable/ic_format_undo.xml +3 -3
  27. package/ios/RichTextEditorView.swift +66 -12
  28. package/ios/RichTextEditorViewManager.m +3 -0
  29. package/ios/ToolbarIcons.swift +48 -747
  30. package/lib/commonjs/RichTextEditorViewNativeComponent.js.map +1 -1
  31. package/lib/commonjs/index.js +3 -0
  32. package/lib/commonjs/index.js.map +1 -1
  33. package/lib/module/RichTextEditorViewNativeComponent.js.map +1 -1
  34. package/lib/module/index.js +3 -0
  35. package/lib/module/index.js.map +1 -1
  36. package/lib/typescript/src/RichTextEditorViewNativeComponent.d.ts +3 -0
  37. package/lib/typescript/src/RichTextEditorViewNativeComponent.d.ts.map +1 -1
  38. package/lib/typescript/src/index.d.ts.map +1 -1
  39. package/lib/typescript/src/types.d.ts +3 -0
  40. package/lib/typescript/src/types.d.ts.map +1 -1
  41. package/package.json +1 -1
  42. package/src/RichTextEditorViewNativeComponent.ts +3 -0
  43. package/src/index.tsx +3 -0
  44. package/src/types.ts +3 -0
@@ -557,6 +557,12 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
557
557
  }
558
558
  }
559
559
 
560
+ @objc var selectable: Bool = true {
561
+ didSet {
562
+ textView.isSelectable = selectable
563
+ }
564
+ }
565
+
560
566
  @objc var maxHeight: CGFloat = 0 {
561
567
  didSet {
562
568
  if maxHeight > 0 {
@@ -597,6 +603,54 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
597
603
  }
598
604
  }
599
605
 
606
+ @objc var fontFamily: String? = nil {
607
+ didSet {
608
+ applyCustomFont()
609
+ }
610
+ }
611
+
612
+ @objc var fontSize: CGFloat = 0 {
613
+ didSet {
614
+ if fontSize > 0 {
615
+ applyCustomFont()
616
+ }
617
+ }
618
+ }
619
+
620
+ private var effectiveFontSize: CGFloat {
621
+ return fontSize > 0 ? fontSize : 16
622
+ }
623
+
624
+ private func resolvedFont(size: CGFloat? = nil, bold: Bool = false, italic: Bool = false) -> UIFont {
625
+ let pointSize = size ?? effectiveFontSize
626
+ if let family = fontFamily, let font = UIFont(name: family, size: pointSize) {
627
+ var descriptor = font.fontDescriptor
628
+ var traits: UIFontDescriptor.SymbolicTraits = []
629
+ if bold { traits.insert(.traitBold) }
630
+ if italic { traits.insert(.traitItalic) }
631
+ if !traits.isEmpty, let newDescriptor = descriptor.withSymbolicTraits(traits) {
632
+ return UIFont(descriptor: newDescriptor, size: pointSize)
633
+ }
634
+ return font
635
+ }
636
+ if bold && italic {
637
+ var traits: UIFontDescriptor.SymbolicTraits = [.traitBold, .traitItalic]
638
+ if let descriptor = UIFont.systemFont(ofSize: pointSize).fontDescriptor.withSymbolicTraits(traits) {
639
+ return UIFont(descriptor: descriptor, size: pointSize)
640
+ }
641
+ }
642
+ if bold { return UIFont.boldSystemFont(ofSize: pointSize) }
643
+ if italic { return UIFont.italicSystemFont(ofSize: pointSize) }
644
+ return UIFont.systemFont(ofSize: pointSize)
645
+ }
646
+
647
+ private func applyCustomFont() {
648
+ let font = resolvedFont()
649
+ textView.font = font
650
+ textView.typingAttributes[.font] = font
651
+ placeholderLabel.font = font
652
+ }
653
+
600
654
  @objc var onContentChange: RCTDirectEventBlock?
601
655
  @objc var onSelectionChange: RCTDirectEventBlock?
602
656
  @objc var onEditorFocus: RCTDirectEventBlock?
@@ -1004,7 +1058,7 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
1004
1058
  }
1005
1059
  isInternalChange = true
1006
1060
  let plainAttributes: [NSAttributedString.Key: Any] = [
1007
- .font: UIFont.systemFont(ofSize: 16),
1061
+ .font: resolvedFont(),
1008
1062
  .foregroundColor: UIColor.label
1009
1063
  ]
1010
1064
  textView.typingAttributes = plainAttributes
@@ -1040,7 +1094,7 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
1040
1094
  let nextNumber = currentNumber + 1
1041
1095
  isInternalChange = true
1042
1096
  let plainAttributes: [NSAttributedString.Key: Any] = [
1043
- .font: UIFont.systemFont(ofSize: 16),
1097
+ .font: resolvedFont(),
1044
1098
  .foregroundColor: UIColor.label
1045
1099
  ]
1046
1100
  textView.typingAttributes = plainAttributes
@@ -1069,7 +1123,7 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
1069
1123
  }
1070
1124
  isInternalChange = true
1071
1125
  let plainAttributes: [NSAttributedString.Key: Any] = [
1072
- .font: UIFont.systemFont(ofSize: 16),
1126
+ .font: resolvedFont(),
1073
1127
  .foregroundColor: UIColor.label
1074
1128
  ]
1075
1129
  textView.typingAttributes = plainAttributes
@@ -1392,7 +1446,7 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
1392
1446
  let mutableAttrString = NSMutableAttributedString(attributedString: textView.attributedText)
1393
1447
  let nsText = text as NSString
1394
1448
 
1395
- let font = UIFont.systemFont(ofSize: 16)
1449
+ let font = resolvedFont()
1396
1450
  let bulletPrefix = "• "
1397
1451
  let bulletWidth = (bulletPrefix as NSString).size(withAttributes: [.font: font]).width
1398
1452
 
@@ -1490,7 +1544,7 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
1490
1544
  }
1491
1545
 
1492
1546
  let monoFont = UIFont.monospacedSystemFont(ofSize: 15, weight: .regular)
1493
- let regularFont = UIFont.systemFont(ofSize: 16)
1547
+ let regularFont = resolvedFont()
1494
1548
 
1495
1549
  mutableAttrString.enumerateAttribute(.font, in: range, options: []) { value, attrRange, _ in
1496
1550
  let newFont = hasMonospace ? regularFont : monoFont
@@ -1570,8 +1624,8 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
1570
1624
  }
1571
1625
  }
1572
1626
 
1573
- let headingFont = UIFont.boldSystemFont(ofSize: 24)
1574
- let regularFont = UIFont.systemFont(ofSize: 16)
1627
+ let headingFont = resolvedFont(size: effectiveFontSize * 1.5, bold: true)
1628
+ let regularFont = resolvedFont()
1575
1629
 
1576
1630
  mutableAttrString.addAttribute(.font, value: isHeading ? regularFont : headingFont, range: lineRange)
1577
1631
 
@@ -1730,7 +1784,7 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
1730
1784
 
1731
1785
  let mutableAttrString = NSMutableAttributedString(attributedString: textView.attributedText)
1732
1786
  let plainAttributes: [NSAttributedString.Key: Any] = [
1733
- .font: UIFont.systemFont(ofSize: 16),
1787
+ .font: resolvedFont(),
1734
1788
  .foregroundColor: UIColor.label
1735
1789
  ]
1736
1790
 
@@ -1756,7 +1810,7 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
1756
1810
  let plainText = (textView.text as NSString?)?.substring(with: range) ?? ""
1757
1811
 
1758
1812
  let plainAttributes: [NSAttributedString.Key: Any] = [
1759
- .font: UIFont.systemFont(ofSize: 16),
1813
+ .font: resolvedFont(),
1760
1814
  .foregroundColor: UIColor.label
1761
1815
  ]
1762
1816
 
@@ -2300,7 +2354,7 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
2300
2354
 
2301
2355
  func setContent(blocks: [[String: Any]]) {
2302
2356
  let attributedString = NSMutableAttributedString()
2303
- let font = UIFont.systemFont(ofSize: 16)
2357
+ let font = resolvedFont()
2304
2358
 
2305
2359
  var numberedIndex = 1
2306
2360
  for (blockIndex, block) in blocks.enumerated() {
@@ -2373,10 +2427,10 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
2373
2427
 
2374
2428
  switch styleType {
2375
2429
  case "bold":
2376
- let boldFont = UIFont.boldSystemFont(ofSize: font.pointSize)
2430
+ let boldFont = resolvedFont(size: font.pointSize, bold: true)
2377
2431
  blockAttrString.addAttribute(.font, value: boldFont, range: range)
2378
2432
  case "italic":
2379
- let italicFont = UIFont.italicSystemFont(ofSize: font.pointSize)
2433
+ let italicFont = resolvedFont(size: font.pointSize, italic: true)
2380
2434
  blockAttrString.addAttribute(.font, value: italicFont, range: range)
2381
2435
  case "underline":
2382
2436
  blockAttrString.addAttribute(.underlineStyle, value: NSUnderlineStyle.single.rawValue, range: range)
@@ -4,12 +4,15 @@
4
4
 
5
5
  RCT_EXPORT_VIEW_PROPERTY(placeholder, NSString)
6
6
  RCT_EXPORT_VIEW_PROPERTY(editable, BOOL)
7
+ RCT_EXPORT_VIEW_PROPERTY(selectable, BOOL)
7
8
  RCT_EXPORT_VIEW_PROPERTY(maxHeight, CGFloat)
8
9
  RCT_EXPORT_VIEW_PROPERTY(numberOfLines, NSInteger)
9
10
  RCT_EXPORT_VIEW_PROPERTY(showToolbar, BOOL)
10
11
  RCT_EXPORT_VIEW_PROPERTY(toolbarOptions, NSArray)
11
12
  RCT_EXPORT_VIEW_PROPERTY(initialContentJson, NSString)
12
13
  RCT_EXPORT_VIEW_PROPERTY(variant, NSString)
14
+ RCT_EXPORT_VIEW_PROPERTY(fontFamily, NSString)
15
+ RCT_EXPORT_VIEW_PROPERTY(fontSize, CGFloat)
13
16
  RCT_EXPORT_VIEW_PROPERTY(onContentChange, RCTDirectEventBlock)
14
17
  RCT_EXPORT_VIEW_PROPERTY(onSelectionChange, RCTDirectEventBlock)
15
18
  RCT_EXPORT_VIEW_PROPERTY(onEditorFocus, RCTDirectEventBlock)