Protocols
The following protocols are available globally.
-
An object capable of resolving text asynchronously to another representation. New representation may contain change in attributes or the string itself.
See moreDeclaration
Swift
public protocol AsyncTextResolving
-
Describes an object (typically attachment view) that may change size during the layout pass
See moreDeclaration
Swift
public protocol DynamicBoundsProviding : AnyObject
-
Denotes an
See moreAttachment
content view that observes background color changes incontainerEditorView
Declaration
Swift
public protocol BackgroundColorObserving : UIView
-
Describes an object capable of providing offsets for the
Attachment
. The value is used to offset theAttachment
when rendered alongside the text. This may be used to align the content baselines inAttachment
content to that of it’s container’s content baselines.Note
This function may be called m0re than once in the same rendering pass. Changing offsets does not resize the container i.e. unlike how container resizes to fit the attachment, if the offset is change such that the attachment ends up rendering outside the bounds of it’s container, it will not resize the container.Attention
While offset can be provided for any type ofAttachment
i.e. Inline or Block, it is recommended that offset be provided only for Inline. If an offset is provided for Block attachment, it is possible that the attachment starts overlapping the content inEditor
in the following line since the offset does not affect the line height.Declaration
Swift
public protocol AttachmentOffsetProviding : AnyObject
-
Describes an object that fulfils requirements to enable asynchronous rendering of attachments in the
See moreEditorView
Declaration
Swift
public protocol AsyncAttachmentRenderingDelegate : AnyObject
-
Marker protocol for attachment views that may need to defer completion of rendering in asynchronous mode until the view bounds are changed. This may be important for cases like
GridView
that does not directly contain the Editors within but instead hosts another view that in turn hosts multiple editors i.e. one per cell. Conformance to this protocol defers invoking thedidRenderAttachment
onAsyncAttachmentRenderingDelegate
until the view size are changed to a non-zero value. In absence of this,didRenderAttachment
is invoked as soon as the attachment is rendered in the editor.Important
In almost all the cases where theEditorView
is hosted directly inside the attachment, this conformance is not required and not advised. When used in such cases, the async rendering may result in unexpected results. This is advisable only in case thedidRenderAttachment
is getting triggered sooner than the layout of view within theAttachment
is able to complete.Declaration
Swift
public protocol AsyncDeferredRenderable
-
Describes an object capable of gaining focus.
Note
If a content view in anAttachment
is madeFocusable
,setFocus
will automatically be called when the attachment with a focusable view is added to the editor.Declaration
Swift
public protocol Focusable
-
Describes an object capable of providing numbers to be displayed when
See moreisLineNumbersEnabled
is set totrue
inEditorView
Declaration
Swift
public protocol LineNumberProvider : AnyObject
-
Describes an object capable of providing style and formatting information for rendering lists in
See moreEditorView
.Declaration
Swift
public protocol EditorListFormattingProvider : AnyObject
-
Represents a Sequence generator that can return a value based on given index. Besides other possible uses, this is used in Lists for generation of bullets/numbering.
See moreDeclaration
Swift
public protocol SequenceGenerator
-
An object capable of decoding attributes for use in
See moreNSAttributedString
Declaration
Swift
public protocol AttributesDecoding
-
An object capable of decoding the given type of content into
See moreNSAttributedString
for using inEditorView
or theRendererView
.Declaration
Swift
public protocol EditorContentDecoding
-
Identifies a content type within the
See moreEditor
Declaration
Swift
public protocol EditorContentIdentifying
-
Undocumented
See moreDeclaration
Swift
public protocol AttachmentTypeIdentifying
-
Describes a view contained in
See moreAttachment
that contains a singleEditorView
. This is a helper protocol that can be applied to the view so that basic properties and functions are made available on the view as passthrough.Declaration
Swift
public protocol EditorContentView : Focusable
-
Describes an object interested in observing the bounds of a view.
Attachment
isBoundsObserving
and reacts to changes in the bounds of views hosted within theAttachment
. Any view contained in theAttachment
that is capable of changing its bounds must define and setBoundsObserving
toAttachment
.Usage Example
See moreclass MyAttachmentView: UIView { weak var boundsObserver: BoundsObserving? override var bounds: CGRect { didSet { guard oldValue != bounds else { return } boundsObserver?.didChangeBounds(bounds) } } } let myView = MyAttachmentView() let attachment = Attachment(myView, size: .matchContent) myView.boundsObserver = attachment
Declaration
Swift
public protocol BoundsObserving : AnyObject
-
Describes an object interested in listening to events raised from EditorView
See moreDeclaration
Swift
public protocol EditorViewDelegate : AnyObject
-
Describes a command that can be executed on
See moreEditorView
. A command may be invoked directly on theeditor
by providing an instance. However, in a typical usage scenario, these should be invoked viaEditorCommandExecutor
which manages all theEditorView
s in the view including the ones that are contained in the attachments.Declaration
Swift
public protocol EditorCommand : AnyObject
-
Undocumented
See moreDeclaration
Swift
public protocol EditorCommandExecutorDelegate : AnyObject
-
Describes an encoder for a content type in Editor. This can be used in conjunction with
AnyEditorTextEncoding
to register various encoders for each of the supported content types. ### Usage Example ###struct ParagraphEncoder: EditorTextEncoding { func encode(name: EditorContent.Name, string: NSAttributedString) -> JSON { var paragraph = JSON() paragraph.type = name.rawValue if let style = string.attribute(.paragraphStyle, at: 0, effectiveRange: nil) as? NSParagraphStyle { paragraph[style.key] = style.value } paragraph.contents = contentsFrom(string) return paragraph } }
See also
EditorContentEncoder
Declaration
Swift
public protocol EditorTextEncoding
-
Describes an object capable of encoding contents of at
See moreAttachment
Declaration
Swift
public protocol AttachmentEncoding
-
An object capable of encoding
See moreEditorContent
to given type.Declaration
Swift
public protocol EditorContentEncoding
-
A generic encoder for encoding
EditorContent
. You may create encoders for individual types of contents in theEditor
, and useEditorContentEncoder
to register and encode the all the contents of the givenEditorView
.Usage Example
See moretypealias JSON = [String: Any] struct JSONEncoder: EditorContentEncoder { let textEncoders: [EditorContent.Name: AnyEditorTextEncoding<JSON>] = [ .paragraph: AnyEditorTextEncoding(ParagraphEncoder()), .text: AnyEditorTextEncoding(TextEncoder()) ] let attachmentEncoders: [EditorContent.Name: AnyEditorContentAttachmentEncoding<JSON>] = [ .panel: AnyEditorContentAttachmentEncoding(PanelEncoder()), .media: AnyEditorContentAttachmentEncoding(MediaEncoder()), ] } // Get the encoded content from the editor let encodedContent = editor.transformContents(using: JSONEncoder())
Declaration
Swift
public protocol EditorContentEncoder : EditorContentEncoding
-
An object capable of intercepting and modifying the text and attributes in an
See moreEditorView
when registered with theEditorView
.Declaration
Swift
public protocol TextProcessing