From e9c0a8b549178f4c1f80191ee4026c2ef51b4fb3 Mon Sep 17 00:00:00 2001 From: Roman Schlagowsky Date: Mon, 23 Sep 2024 14:54:33 +0200 Subject: [PATCH] Update examples with environment objects --- Changelog.md | 11 +++++++++++ Documentation/GettingStarted.md | 2 +- Documentation/Layout/Animated.md | 3 +++ Documentation/Layout/README.md | 6 ++++++ Documentation/Layout/Stateful.md | 2 ++ README.md | 12 +++++++----- 6 files changed, 30 insertions(+), 6 deletions(-) diff --git a/Changelog.md b/Changelog.md index 365ae5d3..3973fb80 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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. 🎉 diff --git a/Documentation/GettingStarted.md b/Documentation/GettingStarted.md index 0a51f724..f113c3da 100644 --- a/Documentation/GettingStarted.md +++ b/Documentation/GettingStarted.md @@ -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") ] ``` diff --git a/Documentation/Layout/Animated.md b/Documentation/Layout/Animated.md index 6d41aaf6..ed461dec 100644 --- a/Documentation/Layout/Animated.md +++ b/Documentation/Layout/Animated.md @@ -21,6 +21,8 @@ import SwiftUI struct AnimatedStreamDeckLayout { + @Environment(\.streamDeckViewContext.device) var streamDeck + var body: some View { StreamDeckLayout { StreamDeckKeyAreaLayout { _ in @@ -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 diff --git a/Documentation/Layout/README.md b/Documentation/Layout/README.md index 368f0f5a..be0a81cb 100644 --- a/Documentation/Layout/README.md +++ b/Documentation/Layout/README.md @@ -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 diff --git a/Documentation/Layout/Stateful.md b/Documentation/Layout/Stateful.md index 0e5b9f70..3bb5fa2a 100644 --- a/Documentation/Layout/Stateful.md +++ b/Documentation/Layout/Stateful.md @@ -19,6 +19,8 @@ import SwiftUI struct StatefulStreamDeckLayout { + @Environment(\.streamDeckViewContext.device) var streamDeck + var body: some View { StreamDeckLayout { StreamDeckKeyAreaLayout { _ in diff --git a/README.md b/README.md index 47f7e396..24f7efd1 100644 --- a/README.md +++ b/README.md @@ -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") ] ``` @@ -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) }