Skip to content

Commit

Permalink
Remove ObjC workaround
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Müller <marcel-mueller@gmx.de>
  • Loading branch information
SystemKeeper committed Jul 28, 2024
1 parent aaf2d9d commit fc8dc74
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion NextcloudTalk/BaseChatTableViewCell+File.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ extension BaseChatTableViewCell {
if let image = UIImage(named: imageName) {
let size = CGSize(width: fileMessageCellFileMaxPreviewWidth, height: fileMessageCellFileMaxPreviewHeight)

if let renderedImage = NCUtils.renderAspectImage(image: image, ofSize: size, toOrigin: .zero) {
if let renderedImage = NCUtils.renderAspectImage(image: image, ofSize: size, centerImage: false) {
self.filePreviewImageView?.image = renderedImage

self.filePreviewImageViewHeightConstraint?.constant = renderedImage.size.height
Expand Down
2 changes: 1 addition & 1 deletion NextcloudTalk/DetailedOptionsSelectorTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"DetailOptionIdentifier"];

if (_type == DetailedOptionsSelectorTypeAccounts) {
[cell.imageView setImage:[NCUtils renderAspectImageWithImage:option.image ofSize:CGSizeMake(20, 20)]];
[cell.imageView setImage:[NCUtils renderAspectImageWithImage:option.image ofSize:CGSizeMake(20, 20) centerImage:YES]];
[cell.detailTextLabel setText:[option.subtitle stringByReplacingOccurrencesOfString:@"https://" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [option.subtitle length])]];
[cell.detailTextLabel setTextColor:[UIColor secondaryLabelColor]];
} else {
Expand Down
13 changes: 6 additions & 7 deletions NextcloudTalk/NCUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -293,19 +293,18 @@ import AVFoundation
return image
}

// Workaround for ObjC
public static func renderAspectImage(image: UIImage?, ofSize size: CGSize) -> UIImage? {
return renderAspectImage(image: image, ofSize: size, toOrigin: nil)
}

public static func renderAspectImage(image: UIImage?, ofSize size: CGSize, toOrigin origin: CGPoint?) -> UIImage? {
public static func renderAspectImage(image: UIImage?, ofSize size: CGSize, centerImage center: Bool) -> UIImage? {
guard let image else { return nil }

let newRect = CGRect(x: 0, y: 0, width: size.width, height: size.height)
UIGraphicsBeginImageContextWithOptions(newRect.size, false, 0.0)

let aspectRatio = AVMakeRect(aspectRatio: image.size, insideRect: newRect)
let targetOrigin = origin ?? CGPoint(x: newRect.maxX / 2 - aspectRatio.width / 2, y: newRect.maxY / 2 - aspectRatio.height / 2)
var targetOrigin: CGPoint = .zero

if center {
targetOrigin = CGPoint(x: newRect.maxX / 2 - aspectRatio.width / 2, y: newRect.maxY / 2 - aspectRatio.height / 2)
}

image.draw(in: CGRect(origin: targetOrigin, size: aspectRatio.size))
let newImage = UIGraphicsGetImageFromCurrentImageContext()
Expand Down
2 changes: 1 addition & 1 deletion NextcloudTalk/SettingsTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ class SettingsTableViewController: UITableViewController, UITextFieldDelegate, U
private extension UITableViewCell {
func setSettingsImage(image: UIImage?, renderingMode: UIImage.RenderingMode = .alwaysTemplate) {
// Render all images to a size of 20x20 so all cells have the same width for the imageView
self.imageView?.image = NCUtils.renderAspectImage(image: image, ofSize: .init(width: 20, height: 20))?.withRenderingMode(renderingMode)
self.imageView?.image = NCUtils.renderAspectImage(image: image, ofSize: .init(width: 20, height: 20), centerImage: true)?.withRenderingMode(renderingMode)
self.imageView?.tintColor = .secondaryLabel
self.imageView?.contentMode = .scaleAspectFit
}
Expand Down

0 comments on commit fc8dc74

Please sign in to comment.