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

iOS 14 deprecation cleanup #3098

Merged
merged 10 commits into from
Jul 26, 2024
7 changes: 0 additions & 7 deletions Core/DefaultVariantManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@ public struct VariantIOS: Variant {
.contains(where: { Locale.current.regionCode == $0 }) }

static let inEnglish = { return Locale.current.languageCode == "en" }

static let iOS15 = { () -> Bool in
if #available(iOS 15, *) {
return true
}
return false
}
}

/// This variant is used for returning users to separate them from really new users.
Expand Down
4 changes: 0 additions & 4 deletions Core/PixelEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,6 @@ extension Pixel {

case downloadsSharingPredownloadedLocalFile

case downloadAttemptToOpenBLOBviaJS

case jsAlertShown

case featureFlaggingInternalUserAuthenticated
Expand Down Expand Up @@ -920,8 +918,6 @@ extension Pixel.Event {

case .downloadsSharingPredownloadedLocalFile: return "m_downloads_sharing_predownloaded_local_file"

case .downloadAttemptToOpenBLOBviaJS: return "m_download_attempt_to_open_blob_js"

case .jsAlertShown: return "m_js_alert_shown"

case .featureFlaggingInternalUserAuthenticated: return "m_internal-user_authenticated"
Expand Down
4 changes: 0 additions & 4 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,6 @@
F15531962BF215F60029ED04 /* SubscriptionTestingUtilities in Frameworks */ = {isa = PBXBuildFile; productRef = F15531952BF215F60029ED04 /* SubscriptionTestingUtilities */; };
F1564F032B7B915F00D454A6 /* AppDelegate+SKAD4.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1564F022B7B915F00D454A6 /* AppDelegate+SKAD4.swift */; };
F15D43201E706CC500BF2CDC /* AutocompleteViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F15D431F1E706CC500BF2CDC /* AutocompleteViewController.swift */; };
F15E9F3E2BEE128200DEFDDE /* SubscriptionManageriOS14.swift in Sources */ = {isa = PBXBuildFile; fileRef = F15E9F3D2BEE128200DEFDDE /* SubscriptionManageriOS14.swift */; };
F1617C131E572E0300DEDCAF /* TabSwitcherViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1617C121E572E0300DEDCAF /* TabSwitcherViewController.swift */; };
F1617C151E57336D00DEDCAF /* TabManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1617C141E57336D00DEDCAF /* TabManager.swift */; };
F1617C191E573EA800DEDCAF /* TabSwitcherDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1617C181E573EA800DEDCAF /* TabSwitcherDelegate.swift */; };
Expand Down Expand Up @@ -2667,7 +2666,6 @@
F1564F022B7B915F00D454A6 /* AppDelegate+SKAD4.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "AppDelegate+SKAD4.swift"; sourceTree = "<group>"; };
F159BDA31F0BDB5A00B4A01D /* TabViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TabViewController.swift; sourceTree = "<group>"; };
F15D431F1E706CC500BF2CDC /* AutocompleteViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AutocompleteViewController.swift; sourceTree = "<group>"; };
F15E9F3D2BEE128200DEFDDE /* SubscriptionManageriOS14.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionManageriOS14.swift; sourceTree = "<group>"; };
F1617C121E572E0300DEDCAF /* TabSwitcherViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TabSwitcherViewController.swift; sourceTree = "<group>"; };
F1617C141E57336D00DEDCAF /* TabManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TabManager.swift; sourceTree = "<group>"; };
F1617C181E573EA800DEDCAF /* TabSwitcherDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TabSwitcherDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4749,7 +4747,6 @@
children = (
F1FDC92F2BF4E0B3006B1435 /* SubscriptionEnvironment+Default.swift */,
D60170BB2BA32DD6001911B5 /* Subscription.swift */,
F15E9F3D2BEE128200DEFDDE /* SubscriptionManageriOS14.swift */,
D6D95CE42B6DA3F200960317 /* AsyncHeadlessWebview */,
D664C7952B289AA000CBFA76 /* Subscription.storekit */,
D664C7932B289AA000CBFA76 /* ViewModel */,
Expand Down Expand Up @@ -6699,7 +6696,6 @@
3132FA2627A0784600DD7A12 /* FilePreviewHelper.swift in Sources */,
9820FF502244FECC008D4782 /* UIScrollViewExtension.swift in Sources */,
8540BD5423D8D5080057FDD2 /* PreserveLoginsAlert.swift in Sources */,
F15E9F3E2BEE128200DEFDDE /* SubscriptionManageriOS14.swift in Sources */,
1E87615928A1517200C7C5CE /* PrivacyDashboardViewController.swift in Sources */,
6F03CAFE2C32DD08004179A8 /* HomePageMessagesConfiguration.swift in Sources */,
EE9D68D12AE00CF300B55EF4 /* NetworkProtectionVPNSettingsView.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/ActionMessageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class ActionMessageView: UIView {
presentationLocation: PresentationLocation = .withBottomBar(andAddressBarBottom: false),
onAction: @escaping () -> Void = {},
onDidDismiss: @escaping () -> Void = {}) {
guard let window = UIApplication.shared.windows.filter({ $0.isKeyWindow }).first else { return }
guard let window = UIApplication.shared.firstKeyWindow else { return }

dismissAllMessages()

Expand Down
10 changes: 1 addition & 9 deletions DuckDuckGo/AdAttribution/AdAttributionFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ struct DefaultAdAttributionFetcher: AdAttributionFetcher {
}

func fetch() async -> AdServicesAttributionResponse? {
guard #available(iOS 14.3, *) else {
return nil
}

var lastToken: String?

for _ in 0..<Constant.maxRetries {
Expand Down Expand Up @@ -123,11 +119,7 @@ struct DefaultAdAttributionFetcher: AdAttributionFetcher {

extension AdAttributionFetcher {
static func fetchAttributionToken() throws -> String {
if #available(iOS 14.3, *) {
return try AAAttribution.attributionToken()
} else {
throw AdAttributionFetcherError.attributionUnsupported
}
return try AAAttribution.attributionToken()
}
}

Expand Down
13 changes: 2 additions & 11 deletions DuckDuckGo/AnimatableTypingText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,8 @@ struct AnimatableTypingText: View {
.frame(maxWidth: .infinity, alignment: .leading)
.visibility(.invisible)

if #available(iOS 15, *) {
Text(AttributedString(model.typedAttributedText))
.frame(maxWidth: .infinity, alignment: .leading)
} else {
Text(model.typedAttributedText.string)
.frame(maxWidth: .infinity, alignment: .leading)
}
Text(AttributedString(model.typedAttributedText))
.frame(maxWidth: .infinity, alignment: .leading)
}
.onChange(of: startAnimating.wrappedValue, perform: { shouldAnimate in
if shouldAnimate {
Expand Down Expand Up @@ -128,10 +123,6 @@ final class AnimatableTypingTextModel: ObservableObject {
private func showCharacter() {

func attributedTypedString(forTypedChars typedChars: [String.Element]) -> NSAttributedString {
guard #available(iOS 15, *) else {
return NSAttributedString(string: String(typedChars))
}

let chars = Array(text)
let untypedChars = chars[typedChars.count ..< chars.count]
let combined = NSMutableAttributedString(string: String(typedChars))
Expand Down
8 changes: 3 additions & 5 deletions DuckDuckGo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ import WebKit
}

private func tryToObtainOverlayWindow() {
for window in UIApplication.shared.windows where window.rootViewController is BlankSnapshotViewController {
for window in UIApplication.shared.foregroundSceneWindows where window.rootViewController is BlankSnapshotViewController {
overlayWindow = window
return
}
Expand Down Expand Up @@ -1007,10 +1007,8 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
Task {
if case .success(let hasEntitlements) = await accountManager.hasEntitlement(forProductName: .networkProtection),
hasEntitlements {
if #available(iOS 15, *) {
let networkProtectionRoot = NetworkProtectionRootViewController()
presentSettings(with: networkProtectionRoot)
}
let networkProtectionRoot = NetworkProtectionRootViewController()
presentSettings(with: networkProtectionRoot)
} else {
(window?.rootViewController as? MainViewController)?.segueToPrivacyPro()
}
Expand Down
16 changes: 6 additions & 10 deletions DuckDuckGo/AppDependencyProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,12 @@ class AppDependencyProvider: DependencyProvider {
entitlementsCache: entitlementsCache,
subscriptionEndpointService: subscriptionService,
authEndpointService: authService)
if #available(iOS 15.0, *) {
subscriptionManager = DefaultSubscriptionManager(storePurchaseManager: DefaultStorePurchaseManager(),
accountManager: accountManager,
subscriptionEndpointService: subscriptionService,
authEndpointService: authService,
subscriptionEnvironment: subscriptionEnvironment)
} else {
// This is used just for iOS <15, it's a sort of mocked environment that will not be used.
subscriptionManager = SubscriptionManageriOS14(accountManager: accountManager)
}

subscriptionManager = DefaultSubscriptionManager(storePurchaseManager: DefaultStorePurchaseManager(),
accountManager: accountManager,
subscriptionEndpointService: subscriptionService,
authEndpointService: authService,
subscriptionEnvironment: subscriptionEnvironment)

let subscriptionFeatureAvailability: SubscriptionFeatureAvailability = DefaultSubscriptionFeatureAvailability(
privacyConfigurationManager: ContentBlocking.shared.privacyConfigurationManager,
Expand Down
32 changes: 12 additions & 20 deletions DuckDuckGo/AutofillLoginDetailsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct AutofillLoginDetailsView: View {
viewModel.selectedCell = nil
}))
.listStyle(.insetGrouped)
.animation(.easeInOut)
.animation(.easeInOut, value: viewModel.viewMode)
}

private var editingContentView: some View {
Expand Down Expand Up @@ -191,27 +191,19 @@ struct AutofillLoginDetailsView: View {
usernameCell()
} footer: {
if !viewModel.isSignedIn {
if #available(iOS 15, *) {
var attributedString: AttributedString {
let text = String(format: UserText.autofillSignInToManageEmail, UserText.autofillEnableEmailProtection)
var attributedString = AttributedString(text)
if let range = attributedString.range(of: UserText.autofillEnableEmailProtection) {
attributedString[range].foregroundColor = Color(ThemeManager.shared.currentTheme.buttonTintColor)
}
return attributedString
var attributedString: AttributedString {
let text = String(format: UserText.autofillSignInToManageEmail, UserText.autofillEnableEmailProtection)
var attributedString = AttributedString(text)
if let range = attributedString.range(of: UserText.autofillEnableEmailProtection) {
attributedString[range].foregroundColor = Color(ThemeManager.shared.currentTheme.buttonTintColor)
}
Text(attributedString)
.font(.footnote)
.lineLimit(nil)
.multilineTextAlignment(.leading)
.fixedSize(horizontal: false, vertical: true)
} else {
Text(String(format: UserText.autofillSignInToManageEmail, UserText.autofillEnableEmailProtection))
.font(.footnote)
.lineLimit(nil)
.multilineTextAlignment(.leading)
.fixedSize(horizontal: false, vertical: true)
return attributedString
}
Text(attributedString)
.font(.footnote)
.lineLimit(nil)
.multilineTextAlignment(.leading)
.fixedSize(horizontal: false, vertical: true)
}
}
.onTapGesture {
Expand Down
12 changes: 5 additions & 7 deletions DuckDuckGo/AutofillLoginDetailsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,11 @@ extension AutofillLoginDetailsViewController {
navigationController?.navigationBar.barTintColor = theme.barBackgroundColor
navigationController?.navigationBar.tintColor = theme.navigationBarTintColor

if #available(iOS 15.0, *) {
let appearance = UINavigationBarAppearance()
appearance.shadowColor = .clear
appearance.backgroundColor = theme.backgroundColor
let appearance = UINavigationBarAppearance()
appearance.shadowColor = .clear
appearance.backgroundColor = theme.backgroundColor

navigationController?.navigationBar.standardAppearance = appearance
navigationController?.navigationBar.scrollEdgeAppearance = appearance
}
navigationController?.navigationBar.standardAppearance = appearance
navigationController?.navigationBar.scrollEdgeAppearance = appearance
}
}
9 changes: 3 additions & 6 deletions DuckDuckGo/AutofillLoginPromptViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ class AutofillLoginPromptViewController: UIViewController {
if #available(iOS 16.0, *) {
return true
}
if #available(iOS 15.0, *),
let presentationController = presentationController as? UISheetPresentationController {
if let presentationController = presentationController as? UISheetPresentationController {
if presentationController.selectedDetentIdentifier == nil &&
presentationController.detents.contains(.medium()) {
return false
Expand Down Expand Up @@ -178,10 +177,8 @@ extension AutofillLoginPromptViewController: AutofillLoginPromptViewModelDelegat
}

func autofillLoginPromptViewModelDidRequestExpansion(_ viewModel: AutofillLoginPromptViewModel) {
if #available(iOS 15.0, *) {
dismiss(animated: true) {
self.completion?(nil, true)
}
dismiss(animated: true) {
self.completion?(nil, true)
}
}

Expand Down
28 changes: 12 additions & 16 deletions DuckDuckGo/AutofillLoginSettingsListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -466,15 +466,13 @@ final class AutofillLoginSettingsListViewController: UIViewController {
}
)

if #available(iOS 15.0, *) {
if let presentationController = authConfirmationPromptViewController.presentationController as? UISheetPresentationController {
if #available(iOS 16.0, *) {
presentationController.detents = [.custom(resolver: { _ in
AutofillViews.deleteAllPromptMinHeight
})]
} else {
presentationController.detents = [.medium()]
}
if let presentationController = authConfirmationPromptViewController.presentationController as? UISheetPresentationController {
if #available(iOS 16.0, *) {
presentationController.detents = [.custom(resolver: { _ in
AutofillViews.deleteAllPromptMinHeight
})]
} else {
presentationController.detents = [.medium()]
}
}

Expand Down Expand Up @@ -961,14 +959,12 @@ extension AutofillLoginSettingsListViewController {
navigationController?.navigationBar.barTintColor = theme.barBackgroundColor
navigationController?.navigationBar.tintColor = theme.navigationBarTintColor

if #available(iOS 15.0, *) {
let appearance = UINavigationBarAppearance()
appearance.shadowColor = .clear
appearance.backgroundColor = theme.backgroundColor
let appearance = UINavigationBarAppearance()
appearance.shadowColor = .clear
appearance.backgroundColor = theme.backgroundColor

navigationController?.navigationBar.standardAppearance = appearance
navigationController?.navigationBar.scrollEdgeAppearance = appearance
}
navigationController?.navigationBar.standardAppearance = appearance
navigationController?.navigationBar.scrollEdgeAppearance = appearance

tableView.reloadData()
}
Expand Down
1 change: 0 additions & 1 deletion DuckDuckGo/CompleteDownloadRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ struct CompleteDownloadRow: View {
}
.accessibilityLabel(UserText.actionShare)
.buttonStyle(.plain)
.animation(nil)
Copy link
Contributor Author

@samsymons samsymons Jul 24, 2024

Choose a reason for hiding this comment

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

@miasma13 This API usage doesn't map neatly into the new SwiftUI animation API. I couldn't figure out what animation we were suppressing with it, since this action is showing a system Share sheet which will always animate. With that in mind, I've removed it, but let me know if you recall why this exists - I believe we could add it back, using the following code:

.animation(nil, value: UUID())

Copy link
Contributor

Choose a reason for hiding this comment

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

Did a quick test of the download list with that line removed and didn't found any odd behavior. There is a slim chance that it was to suppress for some odd behaviour when run on old iOS (13 or 14 at that time).
I am fine with the removal.

.background(
GeometryReader { geometryProxy in
Color.clear
Expand Down
24 changes: 4 additions & 20 deletions DuckDuckGo/DownloadsList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,7 @@ struct DownloadsList: View {

private var doneButton: some View {
Button(action: {
if #available(iOS 15.0, *) {
presentationMode.wrappedValue.dismiss()
} else {
// Because: presentationMode.wrappedValue.dismiss() for view wrapped in NavigationView() does not work in iOS 14 and lower
if var topController = UIApplication.shared.windows.first!.rootViewController {
while let presentedViewController = topController.presentedViewController {
topController = presentedViewController
}
topController.dismiss(animated: true)
}
}
presentationMode.wrappedValue.dismiss()
},
label: { Text(UserText.navigationTitleDone).foregroundColor(.barButton).bold() })
.opacity(editMode == .inactive ? 1.0 : 0.0)
Expand Down Expand Up @@ -81,15 +71,9 @@ struct DownloadsList: View {

@ViewBuilder
private var listWithBottomToolbar: some View {
if #available(iOS 15.0, *) {
listWithBackground.toolbar {
ToolbarItemGroup(placement: .bottomBar) {
toolbarButtons
}
}
} else {
listWithBackground.toolbar {
toolbarContent
listWithBackground.toolbar {
ToolbarItemGroup(placement: .bottomBar) {
toolbarButtons
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/DownloadsListHostingController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class DownloadsListHostingController: UIHostingController<DownloadsList> {
let activityViewController = UIActivityViewController(activityItems: [url], applicationActivities: nil)

if UIDevice.current.userInterfaceIdiom == .pad {
activityViewController.popoverPresentationController?.sourceView = UIApplication.shared.windows.first
activityViewController.popoverPresentationController?.sourceView = UIApplication.shared.firstKeyWindow
activityViewController.popoverPresentationController?.permittedArrowDirections = .right
activityViewController.popoverPresentationController?.sourceRect = rect
}
Expand Down
Loading
Loading