Skip to content

Commit

Permalink
✈️ Migrate to SwiftUI 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
unixzii committed Jul 17, 2020
1 parent 11e961b commit 34f315a
Show file tree
Hide file tree
Showing 17 changed files with 92 additions and 651 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,6 @@ fastlane/test_output
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/

# macOS
.DS_Store
50 changes: 0 additions & 50 deletions AppKitSupports/AppKitSupports.swift

This file was deleted.

34 changes: 0 additions & 34 deletions AppKitSupports/AppKitSupportsImpl.swift

This file was deleted.

26 changes: 0 additions & 26 deletions AppKitSupports/Info.plist

This file was deleted.

22 changes: 0 additions & 22 deletions AppKitSupportsShim/Info.plist

This file was deleted.

9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@ This is a simple game to demonstrate the new SwiftUI framework.
## Supported Platforms

* iOS 13.0+
* macOS 10.15+ (Available in 2 versions)

## Notes about "UIKit for Mac"

**("UIKit for Mac" version is deprecated, and the AppKit version is recommanded)**

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.
* macOS 10.15+
* macOS 11+ (macCatalyst version)

## License

Expand Down
Binary file modified Screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 20 additions & 16 deletions SwiftUI2048-mac/GameMainHostingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,30 @@ class GameMainHostingView: NSHostingView<GameViewWrapper> {
return
}

switch event.keyCode {
case 125:
self.gameLogic.move(.down)
return
case 123:
self.gameLogic.move(.left)
return
case 124:
self.gameLogic.move(.right)
return
case 126:
self.gameLogic.move(.up)
return
default:
return
withTransaction(Transaction(animation: .spring())) {
switch event.keyCode {
case 125:
self.gameLogic.move(.down)
return
case 123:
self.gameLogic.move(.left)
return
case 124:
self.gameLogic.move(.right)
return
case 126:
self.gameLogic.move(.up)
return
default:
return
}
}
}

func newGame() {
gameLogic.newGame()
withTransaction(Transaction(animation: .spring())) {
gameLogic.newGame()
}
}

}
Loading

0 comments on commit 34f315a

Please sign in to comment.