-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
0.17.8: fix keyboard shortcuts on monterey
- Loading branch information
Showing
6 changed files
with
153 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Backport.swift | ||
// Copyright (c) 2022, zhiayang | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// https://developer.apple.com/forums/thread/689189 | ||
|
||
import SwiftUI | ||
import Foundation | ||
|
||
struct Backport<Content: View> | ||
{ | ||
let content: Content | ||
} | ||
|
||
extension View | ||
{ | ||
var montereyCompat: Backport<Self> { | ||
Backport(content: self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// KeyboardShortcut.swift | ||
// Copyright (c) 2022, zhiayang | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import SwiftUI | ||
import Foundation | ||
|
||
extension Backport | ||
{ | ||
@ViewBuilder func keyboardShortcut(key: Character) -> some View | ||
{ | ||
if #available(macOS 11.0, *) | ||
{ | ||
content.keyboardShortcut(KeyEquivalent(key), modifiers: []) | ||
} | ||
else | ||
{ | ||
self.content | ||
} | ||
} | ||
} | ||
|
||
struct ShortcutMaker: View | ||
{ | ||
let shortcuts: [Character] | ||
let action: () -> Void | ||
|
||
var body: some View { | ||
ZStack { | ||
ForEach(self.shortcuts, id: \.self) { key in | ||
Button(action: self.action) { | ||
EmptyView() | ||
} | ||
.montereyCompat | ||
.keyboardShortcut(key: key) | ||
.buttonStyle(.borderless) | ||
.fixedSize() | ||
.frame(width: 0.0, height: 0.0) | ||
.padding(0) | ||
.clipped() | ||
.hidden() | ||
} | ||
} | ||
.fixedSize() | ||
.frame(width: 0.0, height: 0.0) | ||
.padding(0) | ||
.clipped() | ||
.hidden() | ||
} | ||
} |