Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename an API that has the same name as a new API in iOS SDK #1400

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ common_params:
- automattic/a8c-ci-toolkit#3.0.1
# Common environment values to use with the `env` key.
env: &common_env
IMAGE_ID: xcode-15.0.1
IMAGE_ID: xcode-15.4

# This is the default pipeline – it will build and test the app
steps:
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7.4
3.2.2
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class GenericElementConverter: ElementConverter {
attachment.rootTagName = element.name
attachment.rawHTML = serializer.serialize(element)

let content = NSMutableAttributedString(attachment: attachment, attributes: attributes)
let content = NSMutableAttributedString(attachment: attachment, attributes: attributes, aztec: ())

if element.needsClosingParagraphSeparatorIncludingDescendants() {
content.append(NSAttributedString(.paragraphSeparator, attributes: attributes))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class HRElementConverter: AttachmentElementConverter {
let attributes = combine(attributes, with: representation)
let attachment = self.attachment(for: element)

let intrinsicRepresentation = NSAttributedString(attachment: attachment, attributes: attributes)
let intrinsicRepresentation = NSAttributedString(attachment: attachment, attributes: attributes, aztec: ())
let serialization = serialize(element, intrinsicRepresentation, attributes, false)

return (attachment, serialization)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ImageElementConverter: AttachmentElementConverter {
contentSerializer serialize: ContentSerializer) -> (attachment: ImageAttachment, string: NSAttributedString) {

let attachment = self.attachment(for: element)
let intrinsicRepresentation = NSAttributedString(attachment: attachment, attributes: attributes)
let intrinsicRepresentation = NSAttributedString(attachment: attachment, attributes: attributes, aztec: ())
let serialization = serialize(element, intrinsicRepresentation, attributes, false)

return (attachment, serialization)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class VideoElementConverter: AttachmentElementConverter {
contentSerializer serialize: ContentSerializer) -> (attachment: VideoAttachment, string: NSAttributedString) {

let attachment = self.attachment(for: element)
let intrinsicRepresentation = NSAttributedString(attachment: attachment, attributes: attributes)
let intrinsicRepresentation = NSAttributedString(attachment: attachment, attributes: attributes, aztec: ())
let serialization = serialize(element, intrinsicRepresentation, attributes, false)

return (attachment, serialization)
Expand Down
12 changes: 10 additions & 2 deletions Aztec/Classes/Extensions/NSAttributedString+Attachments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ extension NSAttributedString
/// Helper Initializer: returns an Attributed String, with the specified attachment, styled with a given
/// collection of attributes.
///
@available(*, deprecated, renamed: "init(attachment:attributes:aztec:)", message: "This function has the same name as a new API in iOS 18")
public convenience init(attachment: NSTextAttachment, attributes: [NSAttributedString.Key: Any]) {
self.init(attachment: attachment, attributes: attributes, aztec: ())
}

/// Helper Initializer: returns an Attributed String, with the specified attachment, styled with a given
/// collection of attributes.
///
public convenience init(attachment: NSTextAttachment, attributes: [NSAttributedString.Key: Any], aztec: Void) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) I would suggest converting it to a factory method with a prefix: NSAttributedString.aztec_make(attachment:attributes:). Does it need to be public?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This initialiser is available to both NSAttributedString and NSMutableAttributedString. It's not very straightforward to make a static function to return an instance of its receiver.

Does it need to be public?

I'm not sure. But I don't want to change the public API as part of this PR though, which is why I marked the original function as deprecated.

var attributesWithAttachment = attributes
attributesWithAttachment[.attachment] = attachment

Expand All @@ -27,8 +35,8 @@ extension NSAttributedString
let figcaption = Figcaption(defaultFont: UIFont.systemFont(ofSize: 14), storing: nil)

let figureAttributes = attributes.appending(figure)
let finalString = NSMutableAttributedString(attachment: attachment, attributes: figureAttributes)
let finalString = NSMutableAttributedString(attachment: attachment, attributes: figureAttributes, aztec: ())

let mutableCaption = NSMutableAttributedString(attributedString: caption)
mutableCaption.append(paragraphProperty: figure)
mutableCaption.append(paragraphProperty: figcaption)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class AttributedStringSerializer {
let attachment = CommentAttachment()
attachment.text = node.comment

let content = NSMutableAttributedString(attachment: attachment, attributes: attributes)
let content = NSMutableAttributedString(attachment: attachment, attributes: attributes, aztec: ())

guard !node.needsClosingParagraphSeparator() else {
return appendParagraphSeparator(to: content, inheriting: attributes)
Expand Down
2 changes: 1 addition & 1 deletion Aztec/Classes/TextKit/TextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1472,7 +1472,7 @@ open class TextView: UITextView {
self?.undoTextReplacement(of: originalText, finalRange: finalRange)
})

let attachmentString = NSAttributedString(attachment: attachment, attributes: typingAttributes)
let attachmentString = NSAttributedString(attachment: attachment, attributes: typingAttributes, aztec: ())
storage.replaceCharacters(in: range, with: attachmentString)
selectedRange = NSMakeRange(range.location + NSAttributedString.lengthOfTextAttachment, 0)
notifyTextViewDidChange()
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ _None._

### New Features

_None._
* Mark `NSAttributedString.init(attachment:attributes:)` as deprecated, since it has the same name as a new API in iOS 18.
* Add a new `NSAttributedString.init(attachment:attributes:aztec:)` function.

### Bug Fixes

Expand Down
2 changes: 1 addition & 1 deletion Example/Example/EditorDemoController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ class EditorDemoController: UIViewController {
rightMargin -= view.safeAreaInsets.right

scrollInsets.right = -rightMargin
editorView.scrollIndicatorInsets = scrollInsets
editorView.horizontalScrollIndicatorInsets = scrollInsets
}

func updateTitleHeight() {
Expand Down
4 changes: 2 additions & 2 deletions Example/Example/UnknownEditorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ class UnknownEditorViewController: UIViewController {

/// Save Bar Button
///
fileprivate(set) var saveButton: UIBarButtonItem = {
fileprivate(set) lazy var saveButton: UIBarButtonItem = {
let saveTitle = NSLocalizedString("Save", comment: "Save Action")
return UIBarButtonItem(title: saveTitle, style: .plain, target: self, action: #selector(saveWasPressed))
}()

/// Cancel Bar Button
///
fileprivate(set) var cancelButton: UIBarButtonItem = {
fileprivate(set) lazy var cancelButton: UIBarButtonItem = {
let cancelTitle = NSLocalizedString("Cancel", comment: "Cancel Action")
return UIBarButtonItem(title: cancelTitle, style: .plain, target: self, action: #selector(cancelWasPressed))
}()
Expand Down
35 changes: 21 additions & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ GEM
jmespath (1.5.0)
json (2.6.1)
jwt (2.3.0)
language_server-protocol (3.17.0.3)
memoist (0.16.2)
mini_magick (4.11.0)
mini_mime (1.1.2)
Expand All @@ -219,34 +220,39 @@ GEM
netrc (0.11.0)
optparse (0.1.1)
os (1.1.4)
parallel (1.21.0)
parser (3.1.0.0)
parallel (1.26.2)
parser (3.3.4.2)
ast (~> 2.4.1)
racc
plist (3.6.0)
public_suffix (4.0.6)
racc (1.8.1)
rainbow (3.1.1)
rake (13.0.6)
regexp_parser (2.2.0)
regexp_parser (2.9.2)
representable (3.1.1)
declarative (< 0.1.0)
trailblazer-option (>= 0.1.1, < 0.2.0)
uber (< 0.2.0)
retriable (3.1.2)
rexml (3.2.5)
rexml (3.2.9)
strscan
rouge (2.0.7)
rubocop (1.25.1)
rubocop (1.65.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.1.0.0)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.15.1, < 2.0)
regexp_parser (>= 2.4, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.15.1)
parser (>= 3.0.1.1)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.32.0)
parser (>= 3.3.1.0)
ruby-macho (2.5.1)
ruby-progressbar (1.11.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
security (0.1.3)
Expand All @@ -258,6 +264,7 @@ GEM
simctl (1.6.8)
CFPropertyList
naturally
strscan (3.1.0)
terminal-notifier (2.0.0)
terminal-table (1.6.0)
trailblazer-option (0.1.2)
Expand All @@ -273,7 +280,7 @@ GEM
unf (0.1.4)
unf_ext
unf_ext (0.0.8)
unicode-display_width (2.1.0)
unicode-display_width (2.5.0)
webrick (1.7.0)
word_wrap (1.0.0)
xcodeproj (1.21.0)
Expand Down
6 changes: 3 additions & 3 deletions WordPressEditor/WordPressEditor.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = WordPressEditor/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -962,7 +962,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = WordPressEditor/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -990,7 +990,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = WordPressEditor/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
2 changes: 1 addition & 1 deletion fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

default_platform(:ios)

TEST_RUNTIME = 'iOS 17.0'
TEST_RUNTIME = 'iOS 17.5'
TEST_DEVICE = 'iPhone 15 Pro'

platform :ios do
Expand Down