development
swift 83 lines 2.26 KB
Raw
1 import SwiftUI
2
3 extension ToolbarItemPlacement {
4 static var kleponPrimaryAction: ToolbarItemPlacement {
5 #if os(macOS)
6 return .primaryAction
7 #elseif os(tvOS) || os(visionOS)
8 return .automatic
9 #else
10 return .topBarTrailing
11 #endif
12 }
13 }
14
15 extension View {
16 @ViewBuilder
17 func kleponReadableContentWidth() -> some View {
18 #if os(iOS)
19 self.frame(maxWidth: 720)
20 #else
21 self
22 #endif
23 }
24
25 @ViewBuilder
26 func kleponInteractiveButtonStyle() -> some View {
27 #if os(tvOS) || os(visionOS)
28 self.buttonStyle(.automatic)
29 #else
30 self.buttonStyle(.plain)
31 #endif
32 }
33
34 @ViewBuilder
35 func kleponInlineNavigationTitle() -> some View {
36 #if os(iOS)
37 self.navigationBarTitleDisplayMode(.inline)
38 #else
39 self
40 #endif
41 }
42
43 @ViewBuilder
44 func kleponLargeNavigationTitle() -> some View {
45 #if os(iOS)
46 self.navigationBarTitleDisplayMode(.large)
47 #else
48 self
49 #endif
50 }
51
52 /// Make non-interactive content focusable on tvOS so the focus engine
53 /// can navigate through it and drive ScrollView scrolling.
54 /// No-op on all other platforms.
55 @ViewBuilder
56 func tvOSFocusable() -> some View {
57 #if os(tvOS)
58 self.focusable()
59 #else
60 self
61 #endif
62 }
63
64 @ViewBuilder
65 func kleponOnboardingPresentation<Content: View>(
66 isPresented: Binding<Bool>,
67 @ViewBuilder content: @escaping () -> Content
68 ) -> some View {
69 #if os(macOS) || os(tvOS) || os(visionOS)
70 self.sheet(isPresented: isPresented, content: content)
71 #elseif os(iOS)
72 // iPad uses a sheet so the sidebar remains visible behind the cover;
73 // iPhone uses fullScreenCover for the immersive first-launch feel.
74 if UIDevice.current.userInterfaceIdiom == .pad {
75 self.sheet(isPresented: isPresented, content: content)
76 } else {
77 self.fullScreenCover(isPresented: isPresented, content: content)
78 }
79 #else
80 self.fullScreenCover(isPresented: isPresented, content: content)
81 #endif
82 }
83 }