Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 6 additions & 6 deletions Scribe/AboutTab/AboutTableData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ struct AboutTableData {
sectionState: .mastodon,
externalLink: true
),
Section(
sectionTitle: NSLocalizedString("i18n.app.about.community.view_apps", value: "View all Scribe apps", comment: ""),
imageString: "scribeKeyIcon",
sectionState: .scribeApps,
externalLink: true
),
Section(
sectionTitle: NSLocalizedString("i18n.app.about.community.share_scribe", value: "Share Scribe", comment: ""),
imageString: "square.and.arrow.up",
sectionState: .shareScribe,
externalLink: true
),
// Section(
// sectionTitle: NSLocalizedString("i18n.app.about.community.view_apps", value: "View all Scribe apps", comment: ""),
// imageString: "scribeIcon",
// sectionState: .scribeApps,
// externalLink: true
// ),
Section(
sectionTitle: NSLocalizedString("i18n.app.about.community.wikimedia",
value: "Wikimedia and Scribe",
Expand Down
3 changes: 3 additions & 0 deletions Scribe/AboutTab/AboutViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ extension AboutViewController {
case .mastodon:
openURLString(urlString: "https://wikis.world/@scribe", withEncoding: false)

case .scribeApps:
openURLString(urlString: "https://scri.be/", withEncoding: false)

case .wikimedia:
if let viewController = storyboard?.instantiateViewController(
identifier: "InformationScreenVC"
Expand Down
12 changes: 12 additions & 0 deletions Scribe/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
// Override point for customization after application launch.
if #available(iOS 13.0, *) {
Copy link
Member

Choose a reason for hiding this comment

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

note: This looks like changes for your other PR, @prince-0408 :) Could we remove this from this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, on it.

let appearance = UITabBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = .white
UITabBar.appearance().standardAppearance = appearance
UITabBar.appearance().scrollEdgeAppearance = appearance
} else {
// Fallback for earlier versions: non-transparent
UITabBar.appearance().isTranslucent = false
UITabBar.appearance().barTintColor = .white // Default non-transparent color
}

return true
}

Expand Down
62 changes: 62 additions & 0 deletions Scribe/AppExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ extension UIApplication {
extension UIImage {
static func availableIconImage(with imageString: String) -> UIImage {
if let image = UIImage(named: imageString) {
if imageString == "scribeKeyIcon" {
let trimmedImage = image.trimTransparentEdges()
let targetSize = UIDevice.current.userInterfaceIdiom == .pad ? CGSize(width: 32, height: 32) : CGSize(width: 28, height: 28)
return trimmedImage.fitInSquareCanvas(size: targetSize)
}
return image
} else {
if let image = UIImage(systemName: imageString) {
Expand All @@ -28,6 +33,63 @@ extension UIImage {
}
}
}

func trimTransparentEdges() -> UIImage {
guard let cgImage = self.cgImage else { return self }
let height = cgImage.height
let width = cgImage.width
let bytesPerRow = cgImage.bytesPerRow

guard let pixelData = cgImage.dataProvider?.data else { return self }
let data: UnsafePointer<UInt8> = CFDataGetBytePtr(pixelData)
var minX = width
var maxX = 0
var minY = height
var maxY = 0

for y in 0..<height {
for x in 0..<width {
let pixelIndex = y * bytesPerRow + x * 4
let alpha = data[pixelIndex + 3]
if alpha != 0 {
minX = min(minX, x)
maxX = max(maxX, x)
minY = min(minY, y)
maxY = max(maxY, y)
}
}
}

if minX == width { // Entirely transparent
return self
}

let rect = CGRect(x: minX, y: minY, width: maxX - minX + 1, height: maxY - minY + 1)
if let croppedCGImage = cgImage.cropping(to: rect) {
return UIImage(cgImage: croppedCGImage, scale: self.scale, orientation: self.imageOrientation)
}
return self
}

func fitInSquareCanvas(size: CGSize) -> UIImage {
let renderer = UIGraphicsImageRenderer(size: size)
return renderer.image { _ in
let rect = CGRect(origin: .zero, size: size)
let aspectRatio = self.size.width / self.size.height

var targetRect: CGRect
if aspectRatio > 1 { // Landscape
let scaledWidth = size.width
let scaledHeight = size.width / aspectRatio
targetRect = CGRect(x: 0, y: (size.height - scaledHeight) / 2, width: scaledWidth, height: scaledHeight)
} else { // Portrait or Square
let scaledHeight = size.height
let scaledWidth = size.height * aspectRatio
targetRect = CGRect(x: (size.width - scaledWidth) / 2, y: 0, width: scaledWidth, height: scaledHeight)
}
self.draw(in: targetRect)
}
}
}

extension UIView {
Expand Down
1 change: 1 addition & 0 deletions Scribe/ParentTableCellModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ enum SectionState: Equatable {
case github
case matrix
case mastodon
case scribeApps
case wikimedia
case shareScribe
case rateScribe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ final class AboutTableViewCell: UITableViewCell {

if let icon = section.imageString {
iconImageView.image = UIImage.availableIconImage(with: icon)
iconImageView.contentMode = .scaleAspectFit
} else {
iconImageView.image = nil
}
Expand Down
Loading