Skip to content

Commit

Permalink
Add macOS support (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
MacTHEgenius authored Nov 27, 2024
1 parent 7f1672f commit 0495738
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 3 deletions.
10 changes: 9 additions & 1 deletion Pilot.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ Pod::Spec.new do |spec|
spec.static_framework = true
spec.source_files = "ios/**/*.swift"

spec.platform = :ios, "15.0"
spec.ios.deployment_target = "15.0"
spec.tvos.deployment_target = "15.0"
spec.osx.deployment_target = "12.0"

spec.dependency "Shared"

spec.subspec "Navigation" do |subspec|
subspec.source_files = "navigation/ios/**/*.swift"
subspec.osx.exclude_files = "navigation/ios/FullScreenNotAnimatedPresenter.swift"
end

spec.subspec "ViewModel" do |subspec|
Expand All @@ -27,6 +30,11 @@ Pod::Spec.new do |spec|

spec.subspec "Components" do |subspec|
subspec.source_files = "components/ios/base/**/*.swift"
subspec.osx.exclude_files = [
"components/ios/base/Types/PilotKeyboardType.swift",
"components/ios/base/Types/PilotKeyboardAutoCapitalization.swift",
"components/ios/base/Types/PilotTextContentType.swift"
]
subspec.dependency 'Pilot/ViewModel'
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class KotlinMultiplatformConventionPlugin : Plugin<Project> {
iosX64()
iosArm64()
iosSimulatorArm64()
macosArm64()
macosX64()

androidTarget {
publishLibraryVariants("release", "debug")
Expand Down
11 changes: 11 additions & 0 deletions components/ios/base/PilotRichTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,22 @@ public struct PilotRichTextView: View {

private func createClearImage(width: CGFloat) -> Image {
let size = CGSize(width: width, height: 1)
#if canImport(UIKit)
return Image(
uiImage: UIGraphicsImageRenderer(size: size).image { context in
context.cgContext.setFillColor(UIColor.clear.cgColor)
context.cgContext.addRect(CGRect(origin: .zero, size: size))
context.cgContext.drawPath(using: .fill)
}
)
#else
let image = NSImage(size: size, flipped: false) { rect in
guard let context = NSGraphicsContext.current?.cgContext else { return false }
context.setFillColor(.clear)
context.addRect(rect)
context.drawPath(using: .fill)
return true
}
return Image(nsImage: image)
#endif
}
4 changes: 3 additions & 1 deletion components/ios/base/PilotTextFieldView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ public struct PilotTextFieldView<Label>: View where Label: View {
pilotTextField.onReturnKeyTap()
}
.submitLabel(keyboardReturnKeyType.value.submitLabel)
#if canImport(UIKit)
.keyboardType(keyboardType.value.uiKeyboardType)
.autocapitalization(autoCapitalization.value.uiTextAutocapitalizationType)
.textContentType(contentType.value.uiTextContentType)
#endif
.disableAutocorrection(!autoCorrect.value.boolValue)
.autocapitalization(autoCapitalization.value.uiTextAutocapitalizationType)
.textFieldStyle(ExtendedTapAreaTextFieldStyle())
.onChange(of: text.value) { newValue in
textFieldText = pilotTextField.formatText(newValue)
Expand Down
8 changes: 8 additions & 0 deletions navigation/ios/NavigationContainerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ struct NavigationContainerView<
NavigationView {
unwrappedBody
}
#if os(macOS)
.navigationViewStyle(.automatic)
#else
.navigationViewStyle(.stack)
#endif
}

@ViewBuilder
Expand All @@ -58,21 +62,25 @@ struct NavigationContainerView<
onDismiss: childOnDismiss,
content: { childView }
)
#if !os(macOS)
.fullScreenCover(
isPresented: fullScreenCoverBinding,
onDismiss: childOnDismiss,
content: { childView }
)
#endif
.backportNavigationLink(isPresented: pushBinding) {
childView
}
#if canImport(UIKit)
.background(
FullScreenNotAnimatedPresenter(
isPresented: fullScreenNotAnimatedBinding,
onDismiss: childOnDismiss,
content: { childView }
)
)
#endif
.environment(\.pilotNavigationDismissTriggered, navigateState.navigationDismissTriggered)
.environment(\.presentedPilotRouteName, navigateState.child?.route?.name ?? presentedRouteName)
}
Expand Down
2 changes: 2 additions & 0 deletions navigation/ios/PilotNavigationType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ public enum PilotNavigationType<Screen, NavModifier: ViewModifier> {
case root
case push(screen: Screen, onDismiss: () -> Void)
case sheet(screen: Screen, data: NavigationTypeData<NavModifier>)
@available(iOS 15, tvOS 15, *)
case fullScreenCover(screen: Screen, data: NavigationTypeData<NavModifier>)
@available(iOS 15, tvOS 15, *)
case fullScreenNotAnimated(screen: Screen, data: NavigationTypeData<NavModifier>, popDelayInSeconds: Double?)

var screen: Screen? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package com.mirego.pilot.viewmodel

import kotlinx.coroutines.CoroutineScope

public actual val com.mirego.pilot.viewmodel.PilotViewModel.viewModelScope: CoroutineScope
public actual val PilotViewModel.viewModelScope: CoroutineScope
get() = viewModelScope

0 comments on commit 0495738

Please sign in to comment.