-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
4,416 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Build and Test | ||
|
||
on: | ||
push: | ||
pull_request: | ||
schedule: | ||
- cron: "0 9 * * 1" | ||
|
||
jobs: | ||
nextstep: | ||
runs-on: macos-latest | ||
steps: | ||
- name: Select latest available Xcode | ||
uses: maxim-lobanov/[email protected] | ||
with: | ||
xcode-version: 13 | ||
- name: Checkout Repository | ||
uses: actions/checkout@v2 | ||
- name: Build Swift Debug Package | ||
run: swift build -c debug | ||
- name: Build Swift Release Package | ||
run: swift build -c release |
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,67 @@ | ||
# Xcode | ||
# | ||
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore | ||
|
||
## Build generated | ||
build/ | ||
DerivedData/ | ||
|
||
## Various settings | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
xcuserdata/ | ||
|
||
## Other | ||
*.moved-aside | ||
*.xccheckout | ||
*.xcscmblueprint | ||
|
||
## Obj-C/Swift specific | ||
*.hmap | ||
*.ipa | ||
*.dSYM.zip | ||
*.dSYM | ||
|
||
## Playgrounds | ||
timeline.xctimeline | ||
playground.xcworkspace | ||
|
||
# Swift Package Manager | ||
# | ||
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. | ||
# Packages/ | ||
# Package.pins | ||
.build/ | ||
|
||
# CocoaPods | ||
# | ||
# We recommend against adding the Pods directory to your .gitignore. However | ||
# you should judge for yourself, the pros and cons are mentioned at: | ||
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control | ||
# | ||
# Pods/ | ||
|
||
# Carthage | ||
# | ||
# Add this line if you want to avoid checking in source code from Carthage dependencies. | ||
# Carthage/Checkouts | ||
|
||
Carthage/Build | ||
|
||
# fastlane | ||
# | ||
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the | ||
# screenshots whenever they are needed. | ||
# For more information about the recommended setup visit: | ||
# https://docs.fastlane.tools/best-practices/source-control/#source-control | ||
|
||
fastlane/report.xml | ||
fastlane/Preview.html | ||
fastlane/screenshots | ||
fastlane/test_output |
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,12 @@ | ||
// swift-tools-version:5.5 | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "ViewController", | ||
platforms: [ .macOS(.v11), .iOS(.v15) ], | ||
products: [ .library(name: "ViewController", targets: [ "ViewController" ]) ], | ||
targets: [ | ||
.target(name: "ViewController") | ||
] | ||
) |
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,179 @@ | ||
# ViewController | ||
|
||
ViewController's for SwiftUI. | ||
|
||
WIP. | ||
|
||
The core idea is that the `ViewController` is owning, or at least driving, | ||
the View(s). Not the other way around. | ||
|
||
|
||
## How to Use | ||
|
||
More details will be posted but to get started. | ||
|
||
### Step A: Setup Project and Root VC | ||
|
||
- create a SwiftUI project in Xcode (iOS is tested better) | ||
- add the `ViewController` package, | ||
e.g. via `[email protected]:ZeeZide/ViewController.git` | ||
- create a new RootViewController, e.g. `HomePage.swift`: | ||
```swift | ||
import ViewController | ||
|
||
class HomePage: ViewController { | ||
|
||
struct ContentView: View { | ||
|
||
var body: some View { | ||
VStack { | ||
Text("Welcome to MWC!") | ||
.font(.title) | ||
.padding() | ||
|
||
Spacer() | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
- Instantiate that in the scene view, the `ContentView.swift` | ||
generated by Xcode: | ||
```swift | ||
import ViewController | ||
|
||
struct ContentView: View { | ||
var body: some View { | ||
MainViewController(HomePage()) | ||
} | ||
} | ||
``` | ||
- Compile and Run, should show the HomePage | ||
|
||
### Step B: Add a presented VC and navigate to it | ||
|
||
- create a new ViewController, e.g. `Settings.swift`: | ||
```swift | ||
import ViewController | ||
|
||
class Settings: ViewController { | ||
|
||
struct ContentView: View { | ||
|
||
var body: some View { | ||
VStack { | ||
Text("Welcome to Settings!") | ||
.font(.title) | ||
.padding() | ||
|
||
Spacer() | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
- Add an action to present the `Settings` from the `HomePage`: | ||
```swift | ||
import ViewController | ||
|
||
class HomePage: ViewController { | ||
|
||
func configureApp() { | ||
show(Settings()) // or `present(Settings())` | ||
} | ||
|
||
struct ContentView: View { | ||
|
||
@EnvironmentObject private var viewController : HomePage | ||
|
||
var body: some View { | ||
VStack { | ||
Text("Welcome to MWC!") | ||
.font(.title) | ||
.padding() | ||
|
||
Divider() | ||
|
||
Button(action: viewController.configureApp) { | ||
Label("Configure", systemImage: "gear") | ||
} | ||
|
||
Spacer() | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
Pressing the button should show the settings in a sheet. | ||
|
||
|
||
### Step C: Add a NavigationController for Navigation :-) | ||
|
||
- Wrap the HomePage in a `NavigationController`, in the scene view: | ||
```swift | ||
import ViewController | ||
|
||
struct ContentView: View { | ||
var body: some View { | ||
MainViewController(NavigationController(rootViewController: HomePage())) | ||
} | ||
} | ||
``` | ||
|
||
Note pressing the button does a navigation. Things like this should also | ||
work: | ||
```swift | ||
func presentInSheet() { | ||
let vc = SettingsPage() | ||
vc.modalPresentationStyle = .sheet | ||
present(vc) | ||
} | ||
``` | ||
|
||
|
||
### Adding a `PushLink` | ||
|
||
The presentations so far make use of a hidden link. To explicitly | ||
inline a `NavigationLink`, use `PushLink`, which wraps that. | ||
|
||
- Add a `PushLink` (until I get an `NavigationLink` init extension working) | ||
to present the `Settings` from the `HomePage`: | ||
```swift | ||
import ViewController | ||
|
||
class HomePage: ViewController { | ||
|
||
struct ContentView: View { | ||
|
||
var body: some View { | ||
VStack { | ||
Text("Welcome to MWC!") | ||
.font(.title) | ||
.padding() | ||
|
||
Divider() | ||
|
||
PushLink("Open Settings", to: Settings()) | ||
|
||
Spacer() | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
|
||
### Who | ||
|
||
ViewController is brought to you by [ZeeZide](https://zeezide.de). | ||
We like feedback, GitHub stars, cool contract work, | ||
presumably any form of praise you can think of. | ||
|
||
**Want to support my work**? | ||
Buy an app: | ||
[Past for iChat](https://apps.apple.com/us/app/past-for-ichat/id1554897185), | ||
[SVG Shaper](https://apps.apple.com/us/app/svg-shaper-for-swiftui/id1566140414), | ||
[Shrugs](https://shrugs.app/), | ||
[HMScriptEditor](https://apps.apple.com/us/app/hmscripteditor/id1483239744). | ||
You don't have to use it! 😀 |
Oops, something went wrong.