-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Remove redundant #available(iOS 13, *)
checks
#19513
Conversation
They always return `true` since the deployment version is 13.0, and will soon become 14.0. Only one has been left, in `WidgetStyles.swift`, because it will change again when bumping the deployment target to 14+.
90e82d9
to
d209f93
Compare
You can test the changes in Jetpack from this Pull Request by:
|
You can test the changes in WordPress from this Pull Request by:
|
WordPress/Classes/ViewRelated/Blog/Blog + Me/GravatarButtonView.swift
Outdated
Show resolved
Hide resolved
} | ||
return .clear | ||
} | ||
static var ghostToolbarBackground: UIColor = UIColor(light: .clear, dark: UIColor.colorFromHex("2e2e2e")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static var ghostToolbarBackground: UIColor = UIColor(light: .clear, dark: UIColor.colorFromHex("2e2e2e")) | |
static let ghostToolbarBackground: UIColor = UIColor(light: .clear, dark: UIColor.colorFromHex("2e2e2e")) |
PS: I'm surprised that you can do that in an extension
as you can't add instance variable / storage in extension
… but not sure about add static
ones on the type, so maybe that's ok because of static
? (I must be rusty in Swift already…)
If that's not allowed, I'd assume that restriction applies equally to static let
and static var
storages, and so neither code would compile, and the solution would be to go back to a computed variable static var ghostToolbarBackground: UIColor { .init(…) }
instead. But CI seems to be compiling the code happily, so, that's probably ok after all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is allowed.
I wouldn't be surprised if it was a recent Swift change though, because I remember running into the constraint of not being able to add stored properties in extension
in the past. Or, maybe I never tried to do it with static
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't be surprised if it was a recent Swift change though, because I remember running into the constraint of not being able to add stored properties in extension in the past. Or, maybe I never tried to do it with
static
.
Might actually be a case of me never running into this with static
or always assuming it worked the same as with instance. There is at least one StackOverflow answer using static left
in an extension, dated 2014.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yeah, that makes sense I guess.
I totally get why there is this limitation for var
instance variables. But given that let
are constants, and thus not taking storage space on the instance and thus not modifying the underlying memory layout of an instance of the type, I wonder why instance constants let
are not allowed tbh (after all, they could be seen as synonyms to var potato: String { "potato" }
, at least in behavior…).
Maybe this will be allowed in a future version of Swift though?
WordPress/Classes/ViewRelated/Reader/Select Interests/ReaderInterestsStyleGuide.swift
Outdated
Show resolved
Hide resolved
WordPress/Classes/ViewRelated/Stats/Extensions/WPStyleGuide+Stats.swift
Outdated
Show resolved
Hide resolved
WordPress/Classes/ViewRelated/Stats/Today Widgets/WidgetStyles.swift
Outdated
Show resolved
Hide resolved
Co-authored-by: Olivier Halligon <olivier.halligon@automattic.com>
Maybe due to a recent Swift improvement, we are now able to declare `static var` and `static let` within an `extension`. There's no need to compute the value at runtime anymore.
if #available(iOS 13, *), editorController.originatingExtension == .saveToDraft { | ||
// iOS 13 has proper animations and presentations for share and action sheets. So the `else` case should be removed when iOS 13 is minimum. | ||
// We need to make sure we don't end up with stacked modal view controllers by using this: | ||
shareNavController.modalPresentationStyle = .overFullScreen | ||
} else { | ||
shareNavController.transitioningDelegate = extensionTransitioningManager | ||
shareNavController.modalPresentationStyle = .custom | ||
} | ||
// We need to make sure we don't end up with stacked modal view controllers by using this: | ||
shareNavController.modalPresentationStyle = .overFullScreen |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not an equivalent conversion, as you lost the if editorController.originatingExtension == .saveToDraft
condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch! Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AliSoftware I addressed this in 6d49db7
(#19513), thanks again.
I started looking at how to add a unit test to catch
this issue but I run into a number of problems.
- The code is in the WordPressShareExtension target and we cannot test
that one directly; Xcode doesn't let you create test target against
app extensions - Even if we could access the code, the logic depends on
editorController
, an instance property that sets the state based
whetherBundle.main.bundleIdentifier
contains "DraftAction". That
is something we cannot modify at test run time. - Plus a few access level constraints, but those could be easily changed. I don't think we need to worry much about
private
vsinternal
in the context of an app extension.
In short, to test this trivial behavior, we'll need to put in place a
far-from trivial test harness. The idea I have at the moment would be to
extract as much of the logic shared between WordPressShareExtension,
WordPressDraftActionExtension, and their two Jetpack counter parts into
a framework, which we could then test in isolation and design in such a
way that we don't need to inspect the bundle identifier at runtime.
It's worth saying that folks were aware of the code limitations at the
time of implementing the behavior but must have been pressed for time to
ship a bug fix, as evidenced by the comment in the editorController
implementation.
This occurred while removing `#available(iOS 13, *)` checks a few commits before this. I was too eager in my deletions. See discussion at #19513 (comment) For the record, I started looking at how to add a unit test to catch this issue but I run into a number of problems. 1. The code is in the WordPressShareExtension target and we cannot test that one directly; Xcode doesn't let you create test target against app extensions 2. Even if we could access the code, the logic depends on `editorController`, an instance property that sets the state based whether `Bundle.main.bundleIdentifier` contains "DraftAction". That is something we cannot modify at test run time. In short, to test this trivial behavior, we'll need to put in place a far-from trivial test harness. The idea I have at the moment would be to extract as much of the logic shared between WordPressShareExtension, WordPressDraftActionExtension, and their two Jetpack counter parts into a framework, which we could then test in isolation and design in such a way that we don't need to inspect the bundle identifier at runtime. It's worth saying that folks were aware of the code limitations at the time of implementing the behavior but must have been pressed for time to ship a bug fix, as evidenced by the comment in the `editorController` implementation.
} else { | ||
shareNavController.transitioningDelegate = extensionTransitioningManager | ||
shareNavController.modalPresentationStyle = .custom |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mokagio you still need to keep this else
clause and code path for the case when the source is not the SaveToDraft extension
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See why I need tests?!?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wait, and now I just read the // code comment
that was there before your change, and that said:
// iOS 13 has proper animations and presentations for share and action sheets. So the `else` case should be removed when iOS 13 is minimum.
So maybe you were right to remove the else
clause after all! 🤔 (so sorry for the back-and-forth 😅 I should be more mindful of code comments in diffs)
Though that comment still begs the question, if we remove that else
clause, are we also supposed to remove the if editorController.originatingExtension == .saveToDraft
as well, and use the same modalPresentationStyle = .custom
for all cases? Or should we still keep the if
condition and only use .custom
for SaveToDraft but not to other cases?
@bjtitus, as the author of that code back in #13146 (even if this was 3 years ago and you moved to other products since…), maybe you remember?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The release notes in that PR list
- Fixed bugs with the "Save as Draft" action extension's navigation bar colors and iPad sizing in iOS 13.
Skimming the PR description, I think the editorController.originatingExtension == .saveToDraft
check is intentional and required.
I'll verify the behavior for the two extensions and in both versions of the code and report. Stay tuned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the code at cd07203
(#19513), I'm getting the following
Save as Draft
Share
Share doesn't look right. Might need more work. The first thing I'll try will be removing the else
branch and add some break points. I'm also not sure why I'm getting that error, given the app was setup alright.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Share doesn't look right. Might need more work.
…roller` See discussion at #19513 (comment)
5f04c7f
to
cd07203
Compare
They always return `true` since the deployment version is 13.0, and will soon become 14.0. Only two have been left: - In `WidgetStyles.swift`, because it will change again when bumping the deployment target to 14+. - In `MainShareViewController.swift` because we might want to take the occasion to restructure that logic. See conversation at #19513 (comment)
Pull request was closed
They always return
true
since the deployment version is 13.0, and will soon become 14.0.Only one has been left, in
WidgetStyles.swift
, because it will change again when bumping the deployment target to 14+.I was looking at #available statements as part of #19496 and realized we still has some of these laying around.
See also #19511.
Regression Notes
RELEASE-NOTES.txt
if necessary. N.A.