From 34dc26ae69a0879dc539332470eb9d3434646f49 Mon Sep 17 00:00:00 2001 From: Sergio Estevao Date: Thu, 20 Feb 2020 15:25:29 +0000 Subject: [PATCH 1/2] Remove BlockModel var and prop. This is no longer needed due to changes made in Aztec that update the typing properties correctly. --- .../ios/RNTAztecView/BlockFormatHandler.swift | 14 ------- .../ios/RNTAztecView/BlockModel.swift | 3 -- .../HeadingBlockFormatHandler.swift | 40 ------------------- .../ios/RNTAztecView/RCTAztecView.swift | 26 ++---------- .../ios/RNTAztecView/RCTAztecViewManager.m | 1 - 5 files changed, 3 insertions(+), 81 deletions(-) delete mode 100644 react-native-aztec/ios/RNTAztecView/BlockModel.swift delete mode 100644 react-native-aztec/ios/RNTAztecView/HeadingBlockFormatHandler.swift diff --git a/react-native-aztec/ios/RNTAztecView/BlockFormatHandler.swift b/react-native-aztec/ios/RNTAztecView/BlockFormatHandler.swift index 4a096e2840570..8b137891791fe 100644 --- a/react-native-aztec/ios/RNTAztecView/BlockFormatHandler.swift +++ b/react-native-aztec/ios/RNTAztecView/BlockFormatHandler.swift @@ -1,15 +1 @@ -/// Classes conforming this protocol are meant to do formatting work over an specific block. -/// It is useful when we need to force an specific typing format that Aztec is not showing by default. -/// -protocol BlockFormatHandler { - - /// Create an instance of a block formatter handler for the given block. - /// If the given block is not compatible, the init will fail. - /// - init?(block: BlockModel) - - /// Set the typing format to an specific one. - /// - func forceTypingFormat(on textView: RCTAztecView) -} diff --git a/react-native-aztec/ios/RNTAztecView/BlockModel.swift b/react-native-aztec/ios/RNTAztecView/BlockModel.swift deleted file mode 100644 index 7a8c410149a8d..0000000000000 --- a/react-native-aztec/ios/RNTAztecView/BlockModel.swift +++ /dev/null @@ -1,3 +0,0 @@ -struct BlockModel { - let tag: String -} diff --git a/react-native-aztec/ios/RNTAztecView/HeadingBlockFormatHandler.swift b/react-native-aztec/ios/RNTAztecView/HeadingBlockFormatHandler.swift deleted file mode 100644 index 44223934b11b0..0000000000000 --- a/react-native-aztec/ios/RNTAztecView/HeadingBlockFormatHandler.swift +++ /dev/null @@ -1,40 +0,0 @@ -import Aztec - -struct HeadingBlockFormatHandler: BlockFormatHandler { - private let level: Header.HeaderType - private let paragraphFormatter = HTMLParagraphFormatter(placeholderAttributes: nil) - private let headerFormatter: HeaderFormatter - - init?(block: BlockModel) { - guard let level = HeadingBlockFormatHandler.headerLevel(from: block.tag) else { - return nil - } - self.level = level - headerFormatter = HeaderFormatter(headerLevel: level) - } - - func forceTypingFormat(on textView: RCTAztecView) { - var attributes = textView.typingAttributes - - attributes = paragraphFormatter.remove(from: textView.typingAttributes) - attributes = headerFormatter.apply(to: textView.typingAttributes, andStore: nil) - - textView.typingAttributes = attributes - if let font = attributes[.font] as? UIFont { - textView.placeholderLabel.font = font - } - } - - private static func headerLevel(from levelString: String) -> Header.HeaderType? { - switch levelString { - case "h2": - return .h2 - case "h3": - return .h3 - case "h4": - return .h4 - default: - return nil - } - } -} diff --git a/react-native-aztec/ios/RNTAztecView/RCTAztecView.swift b/react-native-aztec/ios/RNTAztecView/RCTAztecView.swift index 6d4e60a3ed48b..38c8225375331 100644 --- a/react-native-aztec/ios/RNTAztecView/RCTAztecView.swift +++ b/react-native-aztec/ios/RNTAztecView/RCTAztecView.swift @@ -14,14 +14,7 @@ class RCTAztecView: Aztec.TextView { @objc var onSelectionChange: RCTBubblingEventBlock? = nil @objc var minWidth: CGFloat = 0 @objc var maxWidth: CGFloat = 0 - @objc var blockType: NSDictionary? = nil { - didSet { - guard let block = blockType, let tag = block["tag"] as? String else { - return - } - blockModel = BlockModel(tag: tag) - } - } + @objc var activeFormats: NSSet? = nil { didSet { let currentTypingAttributes = formattingIdentifiersForTypingAttributes() @@ -42,13 +35,7 @@ class RCTAztecView: Aztec.TextView { defaultParagraphStyle.alignment = textAlignment placeholderLabel.textAlignment = textAlignment } - } - - var blockModel = BlockModel(tag: "") { - didSet { - forceTypingAttributesIfNeeded() - } - } + } private var previousContentSize: CGSize = .zero @@ -614,12 +601,6 @@ class RCTAztecView: Aztec.TextView { } } - func forceTypingAttributesIfNeeded() { - if let formatHandler = HeadingBlockFormatHandler(block: blockModel) { - formatHandler.forceTypingFormat(on: self) - } - } - // MARK: - Event Propagation func propagateContentChanges() { @@ -668,8 +649,7 @@ extension RCTAztecView: UITextViewDelegate { guard isInsertingDictationResult == false else { return } - - forceTypingAttributesIfNeeded() + propagateContentChanges() updatePlaceholderVisibility() //Necessary to send height information to JS after pasting text. diff --git a/react-native-aztec/ios/RNTAztecView/RCTAztecViewManager.m b/react-native-aztec/ios/RNTAztecView/RCTAztecViewManager.m index c968ec9fcaf18..1f9d4a6a8da1e 100644 --- a/react-native-aztec/ios/RNTAztecView/RCTAztecViewManager.m +++ b/react-native-aztec/ios/RNTAztecView/RCTAztecViewManager.m @@ -11,7 +11,6 @@ @interface RCT_EXTERN_MODULE(RCTAztecViewManager, NSObject) RCT_EXPORT_VIEW_PROPERTY(onBlur, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onPaste, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onSelectionChange, RCTDirectEventBlock) -RCT_EXPORT_VIEW_PROPERTY(blockType, NSDictionary) RCT_EXPORT_VIEW_PROPERTY(activeFormats, NSSet) RCT_EXPORT_VIEW_PROPERTY(onActiveFormatsChange, RCTBubblingEventBlock) From 8e8f8be6d037a81d9e837135129ad36bec5ab90a Mon Sep 17 00:00:00 2001 From: Sergio Estevao Date: Fri, 21 Feb 2020 10:37:00 +0000 Subject: [PATCH 2/2] Remove empty file. --- react-native-aztec/ios/RNTAztecView/BlockFormatHandler.swift | 1 - 1 file changed, 1 deletion(-) delete mode 100644 react-native-aztec/ios/RNTAztecView/BlockFormatHandler.swift diff --git a/react-native-aztec/ios/RNTAztecView/BlockFormatHandler.swift b/react-native-aztec/ios/RNTAztecView/BlockFormatHandler.swift deleted file mode 100644 index 8b137891791fe..0000000000000 --- a/react-native-aztec/ios/RNTAztecView/BlockFormatHandler.swift +++ /dev/null @@ -1 +0,0 @@ -