Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
stephencelis committed Jul 29, 2024
1 parent 0c6aa00 commit 40534cc
Show file tree
Hide file tree
Showing 117 changed files with 12,841 additions and 0 deletions.
5 changes: 5 additions & 0 deletions 0288-modern-uikit-pt8/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## [Point-Free](https://www.pointfree.co)

> #### This directory contains code from Point-Free Episode: [Modern UIKit: Stack Navigation, Part 2](https://www.pointfree.co/episodes/ep288-modern-uikit-stack-navigation-part-2)
>
> We round out our stack navigation tools with support for an `@Environment`-like feature for holding onto the stack’s path, a `NavigationLink`-like feature for pushing features onto the stack from anywhere, and we’ll handle every corner case from deep-linking to user dismissal.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
114 changes: 114 additions & 0 deletions 0289-modern-uikit-pt9/ModernUIKit/ModernUIKit/AppFeature.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import Perception
import SwiftUI

@Perceptible
class AppModel {
var path: [Path]
init(path: [Path] = []) {
self.path = path
}

enum Path: Hashable {
case counter(CounterModel)
case settings(SettingsModel)
}
}

struct AppView: View {
@Perception.Bindable var model: AppModel

var body: some View {
WithPerceptionTracking {
NavigationStack(path: $model.path) {
Form {
Button("Counter") {
model.path.append(.counter(CounterModel()))
}
Button("Settings") {
model.path.append(.settings(SettingsModel()))
}

NavigationLink("Counter w/ value", value: AppModel.Path.counter(CounterModel()))
}
.navigationDestination(for: AppModel.Path.self) { path in
switch path {
case let .counter(model):
CounterView(model: model)
case let .settings(model):
SettingsView(model: model)
}
}
}
}
}
}

extension NavigationStackController where Data == [AppModel.Path] {
convenience init(model: AppModel) {
@UIBindable var model = model
self.init(path: $model.path) {
RootViewController()
} destination: { path in
switch path {
case let .counter(model):
CounterViewController(model: model)
case let .settings(model):
SettingsViewController(model: model)
}
}
if #available(iOS 17.0, *) {
self.traitOverrides.path = $model.path
} else {
// Fallback on earlier versions
}
}
}

private enum PathTrait: UITraitDefinition {
static var defaultValue: UIBinding<[AppModel.Path]> {
@UIBindable var model = AppModel()
return $model.path
}
}

extension UITraitCollection {
@available(iOS 17.0, *)
var path: UIBinding<[AppModel.Path]> {
self[PathTrait.self]
}
}

@available(iOS 17.0, *)
extension UIMutableTraits {
fileprivate(set) var path: UIBinding<[AppModel.Path]> {
get { self[PathTrait.self] }
set { self[PathTrait.self] = newValue }
}
}

final class RootViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

let counterButton = UIButton(type: .system, primaryAction: UIAction { [weak self] _ in
self?.navigationController?.push(value: AppModel.Path.counter(CounterModel()))
})
counterButton.setTitle("Counter", for: .normal)
let settingsButton = UIButton(type: .system, primaryAction: UIAction { [weak self] _ in
self?.navigationController?.push(value: AppModel.Path.settings(SettingsModel()))
})
settingsButton.setTitle("Settings", for: .normal)
let stack = UIStackView(arrangedSubviews: [
counterButton,
settingsButton,
])
stack.axis = .vertical
stack.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(stack)

NSLayoutConstraint.activate([
stack.centerXAnchor.constraint(equalTo: view.centerXAnchor),
stack.centerYAnchor.constraint(equalTo: view.centerYAnchor),
])
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading

0 comments on commit 40534cc

Please sign in to comment.