@chaitrabhairappa/react-native-rich-text-editor 3.1.0 → 3.2.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.
- package/android/src/main/java/com/richtext/editor/FloatingToolbar.kt +12 -12
- package/android/src/main/java/com/richtext/editor/RichTextEditorView.kt +38 -5
- package/android/src/main/java/com/richtext/editor/RichTextEditorViewManager.kt +18 -0
- package/android/src/main/java/com/richtext/editor/ToolbarIcons.kt +67 -0
- package/android/src/main/res/drawable/ic_format_align_center.xml +3 -3
- package/android/src/main/res/drawable/ic_format_align_left.xml +3 -3
- package/android/src/main/res/drawable/ic_format_align_right.xml +3 -3
- package/android/src/main/res/drawable/ic_format_bold.xml +3 -3
- package/android/src/main/res/drawable/ic_format_checklist.xml +3 -3
- package/android/src/main/res/drawable/ic_format_clear.xml +3 -3
- package/android/src/main/res/drawable/ic_format_code.xml +3 -3
- package/android/src/main/res/drawable/ic_format_heading.xml +3 -3
- package/android/src/main/res/drawable/ic_format_highlight.xml +3 -3
- package/android/src/main/res/drawable/ic_format_indent.xml +3 -3
- package/android/src/main/res/drawable/ic_format_italic.xml +3 -3
- package/android/src/main/res/drawable/ic_format_link.xml +3 -3
- package/android/src/main/res/drawable/ic_format_list_bulleted.xml +3 -3
- package/android/src/main/res/drawable/ic_format_list_numbered.xml +3 -3
- package/android/src/main/res/drawable/ic_format_media_attachment.xml +3 -3
- package/android/src/main/res/drawable/ic_format_outdent.xml +3 -3
- package/android/src/main/res/drawable/ic_format_quote.xml +3 -3
- package/android/src/main/res/drawable/ic_format_redo.xml +3 -3
- package/android/src/main/res/drawable/ic_format_strikethrough.xml +3 -3
- package/android/src/main/res/drawable/ic_format_underline.xml +3 -3
- package/android/src/main/res/drawable/ic_format_undo.xml +3 -3
- package/ios/RichTextEditorView.swift +60 -12
- package/ios/RichTextEditorViewManager.m +2 -0
- package/ios/ToolbarIcons.swift +48 -747
- package/lib/commonjs/RichTextEditorViewNativeComponent.js.map +1 -1
- package/lib/commonjs/index.js +2 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/RichTextEditorViewNativeComponent.js.map +1 -1
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/RichTextEditorViewNativeComponent.d.ts +2 -0
- package/lib/typescript/src/RichTextEditorViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +2 -0
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/RichTextEditorViewNativeComponent.ts +2 -0
- package/src/index.tsx +2 -0
- package/src/types.ts +2 -0
|
@@ -597,6 +597,54 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
|
|
|
597
597
|
}
|
|
598
598
|
}
|
|
599
599
|
|
|
600
|
+
@objc var fontFamily: String? = nil {
|
|
601
|
+
didSet {
|
|
602
|
+
applyCustomFont()
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
@objc var fontSize: CGFloat = 0 {
|
|
607
|
+
didSet {
|
|
608
|
+
if fontSize > 0 {
|
|
609
|
+
applyCustomFont()
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
private var effectiveFontSize: CGFloat {
|
|
615
|
+
return fontSize > 0 ? fontSize : 16
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
private func resolvedFont(size: CGFloat? = nil, bold: Bool = false, italic: Bool = false) -> UIFont {
|
|
619
|
+
let pointSize = size ?? effectiveFontSize
|
|
620
|
+
if let family = fontFamily, let font = UIFont(name: family, size: pointSize) {
|
|
621
|
+
var descriptor = font.fontDescriptor
|
|
622
|
+
var traits: UIFontDescriptor.SymbolicTraits = []
|
|
623
|
+
if bold { traits.insert(.traitBold) }
|
|
624
|
+
if italic { traits.insert(.traitItalic) }
|
|
625
|
+
if !traits.isEmpty, let newDescriptor = descriptor.withSymbolicTraits(traits) {
|
|
626
|
+
return UIFont(descriptor: newDescriptor, size: pointSize)
|
|
627
|
+
}
|
|
628
|
+
return font
|
|
629
|
+
}
|
|
630
|
+
if bold && italic {
|
|
631
|
+
var traits: UIFontDescriptor.SymbolicTraits = [.traitBold, .traitItalic]
|
|
632
|
+
if let descriptor = UIFont.systemFont(ofSize: pointSize).fontDescriptor.withSymbolicTraits(traits) {
|
|
633
|
+
return UIFont(descriptor: descriptor, size: pointSize)
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
if bold { return UIFont.boldSystemFont(ofSize: pointSize) }
|
|
637
|
+
if italic { return UIFont.italicSystemFont(ofSize: pointSize) }
|
|
638
|
+
return UIFont.systemFont(ofSize: pointSize)
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
private func applyCustomFont() {
|
|
642
|
+
let font = resolvedFont()
|
|
643
|
+
textView.font = font
|
|
644
|
+
textView.typingAttributes[.font] = font
|
|
645
|
+
placeholderLabel.font = font
|
|
646
|
+
}
|
|
647
|
+
|
|
600
648
|
@objc var onContentChange: RCTDirectEventBlock?
|
|
601
649
|
@objc var onSelectionChange: RCTDirectEventBlock?
|
|
602
650
|
@objc var onEditorFocus: RCTDirectEventBlock?
|
|
@@ -1004,7 +1052,7 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
|
|
|
1004
1052
|
}
|
|
1005
1053
|
isInternalChange = true
|
|
1006
1054
|
let plainAttributes: [NSAttributedString.Key: Any] = [
|
|
1007
|
-
.font:
|
|
1055
|
+
.font: resolvedFont(),
|
|
1008
1056
|
.foregroundColor: UIColor.label
|
|
1009
1057
|
]
|
|
1010
1058
|
textView.typingAttributes = plainAttributes
|
|
@@ -1040,7 +1088,7 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
|
|
|
1040
1088
|
let nextNumber = currentNumber + 1
|
|
1041
1089
|
isInternalChange = true
|
|
1042
1090
|
let plainAttributes: [NSAttributedString.Key: Any] = [
|
|
1043
|
-
.font:
|
|
1091
|
+
.font: resolvedFont(),
|
|
1044
1092
|
.foregroundColor: UIColor.label
|
|
1045
1093
|
]
|
|
1046
1094
|
textView.typingAttributes = plainAttributes
|
|
@@ -1069,7 +1117,7 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
|
|
|
1069
1117
|
}
|
|
1070
1118
|
isInternalChange = true
|
|
1071
1119
|
let plainAttributes: [NSAttributedString.Key: Any] = [
|
|
1072
|
-
.font:
|
|
1120
|
+
.font: resolvedFont(),
|
|
1073
1121
|
.foregroundColor: UIColor.label
|
|
1074
1122
|
]
|
|
1075
1123
|
textView.typingAttributes = plainAttributes
|
|
@@ -1392,7 +1440,7 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
|
|
|
1392
1440
|
let mutableAttrString = NSMutableAttributedString(attributedString: textView.attributedText)
|
|
1393
1441
|
let nsText = text as NSString
|
|
1394
1442
|
|
|
1395
|
-
let font =
|
|
1443
|
+
let font = resolvedFont()
|
|
1396
1444
|
let bulletPrefix = "• "
|
|
1397
1445
|
let bulletWidth = (bulletPrefix as NSString).size(withAttributes: [.font: font]).width
|
|
1398
1446
|
|
|
@@ -1490,7 +1538,7 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
|
|
|
1490
1538
|
}
|
|
1491
1539
|
|
|
1492
1540
|
let monoFont = UIFont.monospacedSystemFont(ofSize: 15, weight: .regular)
|
|
1493
|
-
let regularFont =
|
|
1541
|
+
let regularFont = resolvedFont()
|
|
1494
1542
|
|
|
1495
1543
|
mutableAttrString.enumerateAttribute(.font, in: range, options: []) { value, attrRange, _ in
|
|
1496
1544
|
let newFont = hasMonospace ? regularFont : monoFont
|
|
@@ -1570,8 +1618,8 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
|
|
|
1570
1618
|
}
|
|
1571
1619
|
}
|
|
1572
1620
|
|
|
1573
|
-
let headingFont =
|
|
1574
|
-
let regularFont =
|
|
1621
|
+
let headingFont = resolvedFont(size: effectiveFontSize * 1.5, bold: true)
|
|
1622
|
+
let regularFont = resolvedFont()
|
|
1575
1623
|
|
|
1576
1624
|
mutableAttrString.addAttribute(.font, value: isHeading ? regularFont : headingFont, range: lineRange)
|
|
1577
1625
|
|
|
@@ -1730,7 +1778,7 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
|
|
|
1730
1778
|
|
|
1731
1779
|
let mutableAttrString = NSMutableAttributedString(attributedString: textView.attributedText)
|
|
1732
1780
|
let plainAttributes: [NSAttributedString.Key: Any] = [
|
|
1733
|
-
.font:
|
|
1781
|
+
.font: resolvedFont(),
|
|
1734
1782
|
.foregroundColor: UIColor.label
|
|
1735
1783
|
]
|
|
1736
1784
|
|
|
@@ -1756,7 +1804,7 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
|
|
|
1756
1804
|
let plainText = (textView.text as NSString?)?.substring(with: range) ?? ""
|
|
1757
1805
|
|
|
1758
1806
|
let plainAttributes: [NSAttributedString.Key: Any] = [
|
|
1759
|
-
.font:
|
|
1807
|
+
.font: resolvedFont(),
|
|
1760
1808
|
.foregroundColor: UIColor.label
|
|
1761
1809
|
]
|
|
1762
1810
|
|
|
@@ -2300,7 +2348,7 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
|
|
|
2300
2348
|
|
|
2301
2349
|
func setContent(blocks: [[String: Any]]) {
|
|
2302
2350
|
let attributedString = NSMutableAttributedString()
|
|
2303
|
-
let font =
|
|
2351
|
+
let font = resolvedFont()
|
|
2304
2352
|
|
|
2305
2353
|
var numberedIndex = 1
|
|
2306
2354
|
for (blockIndex, block) in blocks.enumerated() {
|
|
@@ -2373,10 +2421,10 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
|
|
|
2373
2421
|
|
|
2374
2422
|
switch styleType {
|
|
2375
2423
|
case "bold":
|
|
2376
|
-
let boldFont =
|
|
2424
|
+
let boldFont = resolvedFont(size: font.pointSize, bold: true)
|
|
2377
2425
|
blockAttrString.addAttribute(.font, value: boldFont, range: range)
|
|
2378
2426
|
case "italic":
|
|
2379
|
-
let italicFont =
|
|
2427
|
+
let italicFont = resolvedFont(size: font.pointSize, italic: true)
|
|
2380
2428
|
blockAttrString.addAttribute(.font, value: italicFont, range: range)
|
|
2381
2429
|
case "underline":
|
|
2382
2430
|
blockAttrString.addAttribute(.underlineStyle, value: NSUnderlineStyle.single.rawValue, range: range)
|
|
@@ -10,6 +10,8 @@ RCT_EXPORT_VIEW_PROPERTY(showToolbar, BOOL)
|
|
|
10
10
|
RCT_EXPORT_VIEW_PROPERTY(toolbarOptions, NSArray)
|
|
11
11
|
RCT_EXPORT_VIEW_PROPERTY(initialContentJson, NSString)
|
|
12
12
|
RCT_EXPORT_VIEW_PROPERTY(variant, NSString)
|
|
13
|
+
RCT_EXPORT_VIEW_PROPERTY(fontFamily, NSString)
|
|
14
|
+
RCT_EXPORT_VIEW_PROPERTY(fontSize, CGFloat)
|
|
13
15
|
RCT_EXPORT_VIEW_PROPERTY(onContentChange, RCTDirectEventBlock)
|
|
14
16
|
RCT_EXPORT_VIEW_PROPERTY(onSelectionChange, RCTDirectEventBlock)
|
|
15
17
|
RCT_EXPORT_VIEW_PROPERTY(onEditorFocus, RCTDirectEventBlock)
|