Skip to content

Commit

Permalink
Update examples with environment objects
Browse files Browse the repository at this point in the history
  • Loading branch information
r-dent committed Sep 23, 2024
1 parent 644b186 commit e9c0a8b
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 6 deletions.
11 changes: 11 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [1.1.0] - 2024-09-23

Removes the need for a macro.

You can now declare your Stream Deck layouts as regular Swift UI views. There is no need to implement `StreamDeckView` anymore.

### Removed

- The dependency on [Stream Deck Kit - Macros](https://github.com/elgatosf/streamdeck-kit-macros)
- The `StreamDeckView` protocol

## [1.0.0] - 2024-08-22

This is the first official release. 🎉
Expand Down
2 changes: 1 addition & 1 deletion Documentation/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ If you want to add it to your own libraries `Package.swift`, use this code inste

```swift
dependencies: [
.package(url: "https://github.com/elgatosf/streamdeck-kit-ipad.git", upToNextMajor: "1.0.0")
.package(url: "https://github.com/elgatosf/streamdeck-kit-ipad.git", upToNextMajor: "1.1.0")
]
```

Expand Down
3 changes: 3 additions & 0 deletions Documentation/Layout/Animated.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import SwiftUI

struct AnimatedStreamDeckLayout {

@Environment(\.streamDeckViewContext.device) var streamDeck

var body: some View {
StreamDeckLayout {
StreamDeckKeyAreaLayout { _ in
Expand Down Expand Up @@ -111,6 +113,7 @@ struct AnimatedStreamDeckLayout {
@State private var targetPosition: CGPoint?

@Environment(\.streamDeckViewContext.size) var viewSize
@Environment(\.streamDeckViewContext.index) var viewIndex

var body: some View {
StreamDeckDialView { rotations in
Expand Down
6 changes: 6 additions & 0 deletions Documentation/Layout/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ import StreamDeckKit

struct StatelessStreamDeckLayout: View {

// Use the `streamDeckViewContext` environment variable to get information about
// the device, the view size or the current key index.
// Values will be different, depending on which layout level (e.g. window, key
// or background) we are.
@Environment(\.streamDeckViewContext.device) var streamDeck

var body: some View {
StreamDeckLayout {
// Define key area
Expand Down
2 changes: 2 additions & 0 deletions Documentation/Layout/Stateful.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import SwiftUI

struct StatefulStreamDeckLayout {

@Environment(\.streamDeckViewContext.device) var streamDeck

var body: some View {
StreamDeckLayout {
StreamDeckKeyAreaLayout { _ in
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ If you want to add it to your own libraries `Package.swift`, use this code inste

```swift
dependencies: [
.package(url: "https://github.com/elgatosf/streamdeck-kit-ipad.git", upToNextMajor: "1.0.0")
.package(url: "https://github.com/elgatosf/streamdeck-kit-ipad.git", upToNextMajor: "1.1.0")
]
```

Expand Down Expand Up @@ -88,19 +88,21 @@ import StreamDeckKit

struct MyFirstStreamDeckLayout: View {

@Environment(\.streamDeckViewContext.device) var streamDeck

var body: some View {
StreamDeckLayout {
// Define key area
// Use StreamDeckKeyAreaLayout for rendering separate keys
StreamDeckKeyAreaLayout { context in
StreamDeckKeyAreaLayout { keyIndex in
// Define content for each key.
// StreamDeckKeyAreaLayout provides a context for each available key,
// StreamDeckKeyAreaLayout provides an index for each available key,
// and StreamDeckKeyView provides a callback for the key action
// Example:
StreamDeckKeyView { pressed in
print("pressed \(pressed)")
print("pressed \(pressed) at index \(keyIndex)")
} content: {
Text("\(context.index)")
Text("\(keyIndex)")
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(.teal)
}
Expand Down

0 comments on commit e9c0a8b

Please sign in to comment.