Skip to content

Commit 525a5cd

Browse files
authored
Create README.md
1 parent e976930 commit 525a5cd

1 file changed

Lines changed: 214 additions & 0 deletions

File tree

README.md

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
## SwiftUI-HiddenAPI
2+
3+
This package allows you to use various hidden SwiftUI features.
4+
5+
### Why is it an xcframework?
6+
This exposes functions in SwiftUI for the hidden features that are not in the swiftinterface files.
7+
Modifications to the libraries are needed to make the Swift compiler see these symbols, which is why this is built outside of SPM and linked to the main snapshots package as a binaryTarget.
8+
For a more in-depth explanation, see [here](https://github.com/EmergeTools/SnapshotPreviews-iOS/tree/main/PreviewsSupport).
9+
10+
### Warning
11+
These features are not exposed by the stable interface and may be removed or changed in OS version updates.
12+
13+
### Overview
14+
All exposed functions are behind the `hidden` variable. This way, when Apple makes them public, no name clashes occur.
15+
16+
17+
#### WithCurrentWindow
18+
Get the current NSWindow / UIWindow from the environment.
19+
20+
```swift
21+
struct WithCurrentWindowTestView: View {
22+
@Environment(\.hidden.withCurrentWindow) var withCurrentWindow
23+
24+
var body: some View {
25+
Text("Hello")
26+
.task {
27+
withCurrentWindow { window in
28+
guard let window else { return }
29+
print("Hello from \(window.title)")
30+
}
31+
}
32+
}
33+
}
34+
```
35+
36+
#### OpenSettings
37+
Open SwiftUI Settings, just like you would open a window.
38+
Works on macOS 14.0, 13.0, and below.
39+
40+
```swift
41+
struct OpenSettingsTestView: View {
42+
@Environment(\.hidden.openSettings) var openSettings
43+
44+
var body: some View {
45+
Button("Open Settings") {
46+
openSettings()
47+
}
48+
}
49+
}
50+
```
51+
52+
#### AppActions
53+
Open SwiftUI Windows, Documents, and Settings outside Views.
54+
55+
```swift
56+
class AppActionsTestDelegate: NSObject, NSApplicationDelegate {
57+
func applicationDidFinishLaunching(_ notification: Notification) {
58+
AppActions.openSettings()
59+
AppActions.openWindow(id: "TestWindow")
60+
}
61+
}
62+
```
63+
64+
#### FloatingWindowStyle
65+
```swift
66+
struct FloatingWindowStyleTestScene: Scene {
67+
var body: some Scene {
68+
WindowGroup {
69+
Text("Hello")
70+
}
71+
.windowStyle(.hidden.floating)
72+
}
73+
}
74+
```
75+
76+
#### Scene modifiers
77+
Example:
78+
```swift
79+
struct WindowBackgroundTestScene: Scene {
80+
var body: some Scene {
81+
WindowGroup {
82+
Text("Hello")
83+
}
84+
.hidden.windowBackground(.regularMaterial)
85+
}
86+
}
87+
```
88+
89+
```swift
90+
/// Customize the window background. Use `.clear` for a transparent window, use `.*Material` for a blurred background
91+
func windowBackground(_ shape: some ShapeStyle) -> some Scene
92+
```
93+
94+
```swift
95+
/// Disable automatic window opening behavior..
96+
/// For example, when set to `.hidden`, launching the app or clicking the app icon won't create a new window of that scene.
97+
/// Note that previously created windows may reappear.
98+
func defaultVisibility(_ visibility: Visibility) -> some Scene
99+
```
100+
101+
```swift
102+
/// Determine if a window should be closed when the user tries to close the window.
103+
/// Returning `true` will close the window, `false` will keep the window open.
104+
func windowShouldClose(_ perform: @escaping () -> Bool) -> some Scene
105+
```
106+
107+
#### View modifiers
108+
Example:
109+
```swift
110+
struct OpenSettingsTestView: View {
111+
var body: some View {
112+
Form {
113+
List {
114+
Text("Hello")
115+
}
116+
.hidden.accessoryBar {
117+
HStack(spacing: .zero) {
118+
Button("Add", systemImage: "plus") {}
119+
Divider()
120+
Button("Remove", systemImage: "minus") {}
121+
}
122+
}
123+
}
124+
.formStyle(.grouped)
125+
}
126+
}
127+
128+
```
129+
130+
```swift
131+
/// Apply a variable blur overlay to a view.
132+
func variableBlur(maxRadius: CGFloat, mask: Image, opaque: Bool) -> some View
133+
```
134+
135+
```swift
136+
/// Change the toolbar behavior when the window is fullscreen.
137+
/// `.showsWithWindow` is the default behavior. `.showsWithMenuBar` will hide the toolbar when fullscreen.
138+
func fullScreenToolbarBehavior(_ behavior: FullScreenToolbarBehavior) -> some View
139+
```
140+
141+
```swift
142+
/// Get a trigger when a row has been selected by the user, and gets clicked again.
143+
/// This differs from a TapGesture, as there is no time limit between the clicks.
144+
func onReselect(enabled: Bool, perform: (() -> ())?) -> some View
145+
```
146+
147+
```swift
148+
/// Adjust the padding around a Form with FormStyle `.grouped`
149+
func formInsets(_ edges: Edge.Set, _ value: CGFloat) -> some View
150+
func formInsets(_ edges: Edge.Set, _ value: EdgeInsets) -> some View
151+
```
152+
153+
```swift
154+
/// Adjust the inset of an individual row in a Form with FormStyle `.grouped`
155+
func formRowInsets(_ insets: EdgeInsets?) -> some View
156+
```
157+
158+
```swift
159+
/// Set the indentation level of a Form row.
160+
func formRowIndentationLevel(_ level: Int?) -> some View
161+
```
162+
163+
```swift
164+
/// Change the background color of a Form.
165+
func formBackground<S: ShapeStyle>(_ shape: S?) -> some View
166+
```
167+
168+
```swift
169+
/// Change the background color of an individual row in a Form.
170+
func formRowBackground<S: ShapeStyle>(_ shape: S?) -> some View
171+
```
172+
173+
```swift
174+
/// Change the background color of a section.
175+
func sectionBackground(_ visibility: Visibility) -> some View
176+
```
177+
178+
```swift
179+
/// Add a trailing info icon to a Form row.
180+
/// As an example, see system bluetooth settings.
181+
func formInfoAction(action: @escaping () -> Void) -> some View
182+
```
183+
184+
```swift
185+
/// Change the visibility of the trailing info icon in a Form row.
186+
func formRowInfoVisibility(_ visibility: Visibility) -> some View
187+
```
188+
189+
```swift
190+
/// Add a trailing Form row view, which becomes visible when hovered over the row.
191+
/// As an example, see system wifi settings.
192+
func formAccessory(@ViewBuilder accessories: () -> some View) -> some View
193+
```
194+
195+
```swift
196+
/// Change the visibility of the trailing Form row view.
197+
func formAccessoryVisibility(_ visibility: Visibility) -> some View
198+
```
199+
200+
```swift
201+
/// Add a bottom row to a Form.
202+
func bottomBar(@ViewBuilder content: () -> some View) -> some View
203+
```
204+
205+
```swift
206+
/// Add a sticky footer to List or Table. The List or Table needs to be wrapped in a Form with style `grouped`.
207+
/// As an example, see system privacy settings -> accessibility
208+
func accessoryBar(@ViewBuilder content: () -> some View) -> some View
209+
```
210+
211+
```swift
212+
/// Control the visibility of the list reorder controls. Untested.
213+
func listReorderControlVisibility(_ visibility: ListAccessoryVisibility) -> some View
214+
```

0 commit comments

Comments
 (0)