add support for macOS#16
Conversation
|
Welp. This is randomly working/not-working. I need to investigate a bit more |
|
I think the issue of sometimes working is already addressed in the README and was discussed in #13 Two solutions I have come up with to enable zoom on macOS:
private func handleScrollEvent(_ event: NSEvent) {
let currentTime = Date()
let timeDifference = currentTime.timeIntervalSince(lastScrollTime)
if timeDifference > 0.1 {
scrollMagnitude = 0
}
scrollMagnitude += event.deltaY
let scaleFactor: CGFloat = 1 + (scrollMagnitude * 0.001)
handleMagnification(value: MagnificationGesture.Value(scaleFactor))
viewModel.lastScale = viewModel.scale
viewModel.lastOffset = viewModel.offset
lastScrollTime = currentTime
}
private func handleKeyEvent(_ event: NSEvent) {
if event.modifierFlags.contains(.command) {
switch event.keyCode {
case 24: // Command +
handleMagnification(value: MagnificationGesture.Value(1.1))
viewModel.lastScale = viewModel.scale
viewModel.lastOffset = viewModel.offset
case 27: // Command -
handleMagnification(value: MagnificationGesture.Value(0.9))
viewModel.lastScale = viewModel.scale
viewModel.lastOffset = viewModel.offset
default:
break
}
}
} |
|
Thanks for the PR and effort @navanchauhan! I've been pretty busy these past days but I will take a detailed look at your code and test it soon! |
|
@navanchauhan I have another suggestion how to solve the zooming issue on Mac:
Especially since it is intuitive. As a user I might not be familiar with the cmd option and also not have a mouse wheel. This might be the easiest solution to the issue. What do you think? |
|
That is a really good suggestion. While I am at it, I might even add buttons for rotating the image |
|
I was able to fix the issue where the circular crop was not working properly on macOS. Now, I just need to add buttons and clean up the code a bit. I should have time this next week (or this weekend itself) to clean up and commit |
|
@navanchauhan hey it's been a while 😅 any update on your behalf for this issue? |
|
I completely forgot about this. I just saw this while cleaning up my inbox... Let me resurrect this PR and try to find some time next week |
- Add macOS 13+ as supported platform in Package.swift - Introduce PlatformImage typealias (UIImage/NSImage) for cross-platform compatibility - Add conditional compilation for UIKit/AppKit in CropViewModel, SwiftyCrop, and CropView - Implement macOS-specific cropping using NSImage, NSBezierPath, and lockFocus - Add PlatformImageView for cross-platform image rendering - Update Liquid Glass availability to include macOS 26.0 - Update Demo app with macOS support (sheet vs fullScreenCover, NSScreen, default window size)
| Toggle("Rotate image (buttons)", isOn: $rotateImageWithButtons) | ||
|
|
||
| if #available(iOS 26, *) { | ||
| if #available(iOS 26, visionOS 26, macOS 26, *) { |
There was a problem hiding this comment.
Since Liquid Design is on by default on visionOS, I am not sure if we should add this here or not 🤷
There was a problem hiding this comment.
I think it's fine - since this is only the demo view :)
|
Thanks @navanchauhan this looks great - just tested it on my mac running Sequoia. I will test it on my other mac with MacOS 26 tonight and leave you my review! |
|
Looks good! I will highjack your PR and add you as a contributor :) |
PlatformImagethat uses UIKit or AppKit depending on what it can importTheoretically, magnification and rotation should work on macOS but doesn't for some reason (and doesn't throw any errors either). I might update both gesture to their newer counterparts