Skip to content

Commit

Permalink
Fix an issue with site icons cropped in share extensions (#23950)
Browse files Browse the repository at this point in the history
  • Loading branch information
kean authored Jan 6, 2025
2 parents 9edac5f + 0862ef1 commit 6e32673
Show file tree
Hide file tree
Showing 22 changed files with 150 additions and 177 deletions.
11 changes: 10 additions & 1 deletion Modules/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,15 @@ let package = Package(
.target(name: "WordPressSharedObjC", resources: [.process("Resources")], swiftSettings: [.swiftLanguageMode(.v5)]),
.target(name: "WordPressShared", dependencies: [.target(name: "WordPressSharedObjC")], resources: [.process("Resources")], swiftSettings: [.swiftLanguageMode(.v5)]),
.target(name: "WordPressTesting", resources: [.process("Resources")]),
.target(name: "WordPressUI", dependencies: [.target(name: "WordPressShared")], resources: [.process("Resources")], swiftSettings: [.swiftLanguageMode(.v5)]),
.target(
name: "WordPressUI",
dependencies: [
"AsyncImageKit",
.target(name: "WordPressShared")
],
resources: [.process("Resources")],
swiftSettings: [.swiftLanguageMode(.v5)]
),
.testTarget(name: "JetpackStatsWidgetsCoreTests", dependencies: [.target(name: "JetpackStatsWidgetsCore")], swiftSettings: [.swiftLanguageMode(.v5)]),
.testTarget(name: "DesignSystemTests", dependencies: [.target(name: "DesignSystem")], swiftSettings: [.swiftLanguageMode(.v5)]),
.testTarget(name: "WordPressFluxTests", dependencies: ["WordPressFlux"], swiftSettings: [.swiftLanguageMode(.v5)]),
Expand Down Expand Up @@ -193,6 +201,7 @@ enum XcodeSupport {
.xcodeTarget("XcodeTarget_StatsWidget", dependencies: [
"JetpackStatsWidgetsCore",
"WordPressShared",
"WordPressUI",
.product(name: "CocoaLumberjackSwift", package: "CocoaLumberjack"),
.product(name: "WordPressAPI", package: "wordpress-rs"),
.product(name: "ColorStudio", package: "color-studio"),
Expand Down
58 changes: 0 additions & 58 deletions Modules/Sources/WordPressUI/Extensions/UIImageView+Blavatar.swift

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"images" : [
{
"filename" : "Vector.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true,
"template-rendering-intent" : "template"
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import UIKit
import SwiftUI
import AsyncImageKit
import DesignSystem
import WordPressShared

struct SiteIconView: View {
let viewModel: SiteIconViewModel
public struct SiteIconView: View {
public let viewModel: SiteIconViewModel

@Environment(\.siteIconBackgroundColor) private var backgroundColor

var body: some View {
public init(viewModel: SiteIconViewModel) {
self.viewModel = viewModel
}

public var body: some View {
contents
.clipShape(RoundedRectangle(cornerRadius: 6))
}
Expand Down Expand Up @@ -56,7 +58,7 @@ struct SiteIconView: View {

private var failureStateView: some View {
backgroundColor.overlay {
Image.DS.icon(named: .vector)
Image("vector", bundle: .module)
.resizable()
.frame(width: 18, height: 18)
.tint(Color(.tertiaryLabel))
Expand All @@ -69,18 +71,52 @@ private struct SiteIconViewBackgroundColorKey: EnvironmentKey {
}

extension EnvironmentValues {
var siteIconBackgroundColor: Color {
public var siteIconBackgroundColor: Color {
get { self[SiteIconViewBackgroundColorKey.self] }
set { self[SiteIconViewBackgroundColorKey.self] = newValue }
}
}

// MARK: - SiteIconViewModel

public struct SiteIconViewModel {
public var imageURL: URL?
public var firstLetter: Character?
public var size: Size
public var host: MediaHostProtocol?

public enum Size {
case small
case regular
case large

public var width: CGFloat {
switch self {
case .small: 28
case .regular: 40
case .large: 72
}
}

public var size: CGSize {
CGSize(width: width, height: width)
}
}

public init(imageURL: URL? = nil, firstLetter: Character? = nil, size: Size = .regular, host: MediaHostProtocol? = nil) {
self.imageURL = imageURL
self.firstLetter = firstLetter
self.size = size
self.host = host
}
}

// MARK: - SiteIconHostingView (UIKit)

final class SiteIconHostingView: UIView {
public final class SiteIconHostingView: UIView {
private let viewModel = SiteIconHostingViewModel()

override init(frame: CGRect) {
public override init(frame: CGRect) {
super.init(frame: frame)

let host = UIHostingController(rootView: _SiteIconHostingView(viewModel: viewModel))
Expand All @@ -90,11 +126,11 @@ final class SiteIconHostingView: UIView {
host.view.pinSubviewToAllEdges(self)
}

required init?(coder: NSCoder) {
public required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

func setIcon(with viewModel: SiteIconViewModel) {
public func setIcon(with viewModel: SiteIconViewModel) {
self.viewModel.icon = viewModel
}
}
Expand Down
2 changes: 1 addition & 1 deletion RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* [*] Fix an issue with Referrers in Stats showing invalid icons [#23943]
* [*] Update site menu style on iPhone [#23944]
* [*] Integrate zoom transitions in Themes, Reader [#23945, #23947]

* [*] Fix an issue with site icons cropped in share extensions [#23950]

25.6
-----
Expand Down
1 change: 1 addition & 0 deletions WordPress/Classes/Models/ReaderPost+Swift.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import WordPressUI

extension ReaderPost {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Gridicons
import UIKit
import DesignSystem
import SwiftUI
import WordPressUI

@objc protocol BlogDetailHeaderViewDelegate {
func makeSiteIconMenu() -> UIMenu?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import UIKit
import WordPressUI

final class SiteDetailsSiteIconView: UIView {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import SwiftUI
import WordPressUI
import WordPressShared

struct BlogListSiteView: View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,12 @@ import SwiftUI
import WordPressShared
import WordPressKit
import AsyncImageKit
import WordPressUI

struct SiteIconViewModel {
var imageURL: URL?
var firstLetter: Character?
var size: Size
var host: MediaHost?

enum Size {
case small
case regular
case large

var width: CGFloat {
switch self {
case .small: 28
case .regular: 40
case .large: 72
}
}

var size: CGSize {
CGSize(width: width, height: width)
}
}

extension SiteIconViewModel {
init(blog: Blog, size: Size = .regular) {
self.size = size
self.init(size: size)

self.firstLetter = blog.title?.first

if blog.hasIcon, let icon = blog.icon {
Expand All @@ -39,7 +18,8 @@ struct SiteIconViewModel {
}

init(readerSiteTopic: ReaderSiteTopic, size: Size = .regular) {
self.size = size
self.init(size: size)

self.firstLetter = readerSiteTopic.title.first
self.imageURL = SiteIconViewModel.makeReaderSiteIconURL(
iconURL: readerSiteTopic.siteBlavatar,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Gutenberg
import Aztec
import WordPressFlux
import WordPressShared
import WordPressUI
import React
import AutomatticTracks
import Combine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,15 @@ private extension NotificationSettingsViewController {
labelView.translatesAutoresizingMaskIntoConstraints = false

let textProvider = JetpackBrandingTextProvider(screen: JetpackBadgeScreen.notificationsSettings)
let badgeView = JetpackButton.makeBadgeView(title: textProvider.brandingText(),
topPadding: FooterMetrics.jetpackBadgeTopPadding,
bottomPadding: FooterMetrics.jetpackBadgeBottomPatting,
target: self,
selector: #selector(jetpackButtonTapped))
let badgeView = JetpackButton.makeBadgeView(
title: textProvider.brandingText(),
topPadding: FooterMetrics.jetpackBadgeTopPadding,
bottomPadding: FooterMetrics.jetpackBadgeBottomPatting,
target: self,
selector: #selector(
jetpackButtonTapped
)
)
badgeView.translatesAutoresizingMaskIntoConstraints = false

let stackView = UIStackView(arrangedSubviews: [labelView, badgeView])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Foundation
import SwiftUI
import WordPressUI

struct NotificationSettingsSiteView: View {
let viewModel: NotificationSettingsSiteViewModel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import UIKit
import WordPressUI

final class PrepublishingHeaderView: UIView {
private let blogImageView = SiteIconHostingView()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import SwiftUI
import UIKit
import Combine
import WordPressUI
import WordPressShared
import AsyncImageKit

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import SwiftUI
import WordPressUI
import WordPressKit

struct ReaderFeedCell: View {
Expand All @@ -25,7 +26,7 @@ struct ReaderFeedCell: View {

extension SiteIconViewModel {
init(feed: ReaderFeed, size: Size = .regular) {
self.size = size
self.init(size: size)
if let iconURL = feed.blavatarURL {
self.imageURL = SiteIconViewModel.optimizedURL(for: iconURL.absoluteString, imageSize: size.size)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import SwiftUI
import WordPressUI

struct ReaderSubscriptionCell: View {
let site: ReaderSiteTopic
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import SwiftUI
import AsyncImageKit
import WordPressUI

struct ReaderSiteIconView: View, Hashable {
let site: ReaderSiteTopic
Expand Down
Loading

0 comments on commit 6e32673

Please sign in to comment.