Skip to content

Commit 34f315a

Browse files
committed
✈️ Migrate to SwiftUI 2.0
1 parent 11e961b commit 34f315a

File tree

17 files changed

+92
-651
lines changed

17 files changed

+92
-651
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,6 @@ fastlane/test_output
8080
# https://github.com/johnno1962/injectionforxcode
8181

8282
iOSInjectionProject/
83+
84+
# macOS
85+
.DS_Store

AppKitSupports/AppKitSupports.swift

Lines changed: 0 additions & 50 deletions
This file was deleted.

AppKitSupports/AppKitSupportsImpl.swift

Lines changed: 0 additions & 34 deletions
This file was deleted.

AppKitSupports/Info.plist

Lines changed: 0 additions & 26 deletions
This file was deleted.

AppKitSupportsShim/Info.plist

Lines changed: 0 additions & 22 deletions
This file was deleted.

README.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,8 @@ This is a simple game to demonstrate the new SwiftUI framework.
99
## Supported Platforms
1010

1111
* iOS 13.0+
12-
* macOS 10.15+ (Available in 2 versions)
13-
14-
## Notes about "UIKit for Mac"
15-
16-
**("UIKit for Mac" version is deprecated, and the AppKit version is recommanded)**
17-
18-
This demo has adopted "UIKit for Mac" and uses a dynamic-loaded bundle to enable the full macOS abilities (like the accessing to AppKit, which is used in the demo to handle keyboard events). Specially, this is done by just using Swift. To learn more about it, take a look at the source code of `AppKitSupports`, there is a lot of detailed comments.
12+
* macOS 10.15+
13+
* macOS 11+ (macCatalyst version)
1914

2015
## License
2116

Screenshot.png

-153 KB
Loading

SwiftUI2048-mac/GameMainHostingView.swift

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,30 @@ class GameMainHostingView: NSHostingView<GameViewWrapper> {
4949
return
5050
}
5151

52-
switch event.keyCode {
53-
case 125:
54-
self.gameLogic.move(.down)
55-
return
56-
case 123:
57-
self.gameLogic.move(.left)
58-
return
59-
case 124:
60-
self.gameLogic.move(.right)
61-
return
62-
case 126:
63-
self.gameLogic.move(.up)
64-
return
65-
default:
66-
return
52+
withTransaction(Transaction(animation: .spring())) {
53+
switch event.keyCode {
54+
case 125:
55+
self.gameLogic.move(.down)
56+
return
57+
case 123:
58+
self.gameLogic.move(.left)
59+
return
60+
case 124:
61+
self.gameLogic.move(.right)
62+
return
63+
case 126:
64+
self.gameLogic.move(.up)
65+
return
66+
default:
67+
return
68+
}
6769
}
6870
}
6971

7072
func newGame() {
71-
gameLogic.newGame()
73+
withTransaction(Transaction(animation: .spring())) {
74+
gameLogic.newGame()
75+
}
7276
}
7377

7478
}

0 commit comments

Comments
 (0)