fix: Add macOS platform support via Chameleon typealias pattern#22
fix: Add macOS platform support via Chameleon typealias pattern#22doozMen wants to merge 2 commits intopeterfriese:mainfrom
Conversation
MarkdownUI requires macOS 12.0+, but ConversationKit didn't declare a macOS platform, defaulting to 10.13. SPM 6 enforces this strictly when consumed via remote URLs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace all UIKit-specific types with cross-platform abstractions: - PlatformImage typealias (UIImage on iOS, NSImage on macOS) - Platform color extensions (separator, secondary background, gray4) - Cross-platform RoundedCorner shape replacing UIBezierPath - Availability guards for iOS 26/macOS 26 glass effects - Conditional navigationBarTitleDisplayMode for iOS only Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary of ChangesHello @doozMen, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the ConversationKit framework by adding support for the macOS platform. It leverages the Chameleon pattern to abstract platform-specific types, allowing the codebase to be shared between iOS and macOS. The changes include adding macOS as a supported platform in the package manifest, introducing platform-agnostic type aliases, and using conditional compilation to handle platform-specific code. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request successfully introduces macOS platform support to the ConversationKit library by implementing cross-platform abstractions following the Chameleon pattern. The changes include updating the Package.swift file to support macOS, replacing UIKit-specific types like "UIImage" and "UIRectCorner" with platform-agnostic equivalents, and introducing a new "PlatformTypes.swift" file to centralize these abstractions. The "RoundedCorner" shape has been refactored to use pure SwiftUI Path primitives, ensuring full cross-platform compatibility. Overall, the changes are well-executed and significantly improve the library's maintainability and platform reach.
| func path(in rect: CGRect) -> Path { | ||
| let path = UIBezierPath( | ||
| roundedRect: rect, | ||
| byRoundingCorners: corners, | ||
| cornerRadii: CGSize(width: radius, height: radius) | ||
| ) | ||
| return Path(path.cgPath) | ||
| let tl = corners.contains(.topLeft) ? radius : 0 | ||
| let tr = corners.contains(.topRight) ? radius : 0 | ||
| let bl = corners.contains(.bottomLeft) ? radius : 0 | ||
| let br = corners.contains(.bottomRight) ? radius : 0 | ||
|
|
||
| var path = Path() | ||
| path.move(to: CGPoint(x: rect.minX + tl, y: rect.minY)) | ||
| path.addLine(to: CGPoint(x: rect.maxX - tr, y: rect.minY)) | ||
| path.addArc( | ||
| tangent1End: CGPoint(x: rect.maxX, y: rect.minY), | ||
| tangent2End: CGPoint(x: rect.maxX, y: rect.minY + tr), | ||
| radius: tr) | ||
| path.addLine(to: CGPoint(x: rect.maxX, y: rect.maxY - br)) | ||
| path.addArc( | ||
| tangent1End: CGPoint(x: rect.maxX, y: rect.maxY), | ||
| tangent2End: CGPoint(x: rect.maxX - br, y: rect.maxY), | ||
| radius: br) | ||
| path.addLine(to: CGPoint(x: rect.minX + bl, y: rect.maxY)) | ||
| path.addArc( | ||
| tangent1End: CGPoint(x: rect.minX, y: rect.maxY), | ||
| tangent2End: CGPoint(x: rect.minX, y: rect.maxY - bl), | ||
| radius: bl) | ||
| path.addLine(to: CGPoint(x: rect.minX, y: rect.minY + tl)) | ||
| path.addArc( | ||
| tangent1End: CGPoint(x: rect.minX, y: rect.minY), | ||
| tangent2End: CGPoint(x: rect.minX + tl, y: rect.minY), | ||
| radius: tl) | ||
| return path |
There was a problem hiding this comment.
The "path(in rect: CGRect)" method in the "RoundedCorner" shape is quite verbose due to the repeated "addLine" and "addArc" calls for each corner. While functional, encapsulating the logic for adding a single rounded corner segment could improve readability and reduce repetition, making the code easier to maintain in the long run.
Summary
PlatformTypes.swiftwith cross-platform abstractions following the Chameleon pattern:PlatformImagetypealias,Image(platformImage:)initializer, and platform color extensionsUIImage,UIRectCorner,UIBezierPath, andColor(uiColor:)references with cross-platform equivalentsmacOS 26.0to#availablechecks alongsideiOS 26.0for glass effects.navigationBarTitleDisplayMode(.inline)in#if os(iOS)guardsTest plan
swift buildsucceeds on macOS (previously failed with UIKit import errors)swift testpasses (1 test, 0 failures)🤖 Generated with Claude Code