diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 337ef6b..8651187 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,10 +9,9 @@ on: jobs: carthage: name: Carthage - runs-on: macos-latest + runs-on: macos-15 steps: - uses: actions/checkout@v4 - - uses: AckeeCZ/load-xcode-version@v1 - name: Build run: carthage build --no-skip-current --cache-builds --use-xcframeworks - uses: actions/cache@v3 @@ -23,10 +22,9 @@ jobs: ${{ runner.os }}-carthage- spm: name: SPM - runs-on: macos-latest + runs-on: macos-15 steps: - uses: actions/checkout@v4 - - uses: AckeeCZ/load-xcode-version@v1 - name: Build run: swift build -c release - uses: actions/cache@v3 diff --git a/.github/workflows/docbuild.yml b/.github/workflows/docbuild.yml index 786afcc..e0567f9 100644 --- a/.github/workflows/docbuild.yml +++ b/.github/workflows/docbuild.yml @@ -21,12 +21,10 @@ jobs: # Must be set to this for deploying to GitHub Pages name: github-pages url: ${{ steps.deployment.outputs.page_url }} - runs-on: macos-latest + runs-on: macos-15 steps: - name: Checkout 🛎️ uses: actions/checkout@v4 - - name: Check Xcode version ✅ - uses: AckeeCZ/load-xcode-version@v1 - name: Build DocC run: | xcodebuild docbuild -scheme ACKategories \ diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 546a951..6f5f25e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -5,12 +5,11 @@ on: [workflow_call] jobs: xcodebuild: name: Xcodebuild - runs-on: macos-latest + runs-on: macos-15 env: - IOS_DEVICE: iPhone 15 Pro Max + IOS_DEVICE: iPhone 16 Pro steps: - uses: actions/checkout@v4 - - uses: AckeeCZ/load-xcode-version@v1 - name: iOS tests run: set -o pipefail && xcodebuild test -scheme ACKategories -resultBundlePath Tests-iOS.xcresult -sdk iphonesimulator -destination "platform=iOS Simulator,name=$IOS_DEVICE,OS=latest" ONLY_ACTIVE_ARCH=YES | xcpretty - uses: actions/upload-artifact@v4 @@ -48,10 +47,9 @@ jobs: path: Tests-tvOS.xcresult spm: name: SPM - runs-on: macos-latest + runs-on: macos-15 steps: - uses: actions/checkout@v4 - - uses: AckeeCZ/load-xcode-version@v1 - name: SPM build run: swift build - name: SPM tests diff --git a/ACKategories.xcodeproj/project.pbxproj b/ACKategories.xcodeproj/project.pbxproj index 3a51c83..74fa825 100644 --- a/ACKategories.xcodeproj/project.pbxproj +++ b/ACKategories.xcodeproj/project.pbxproj @@ -117,6 +117,7 @@ 69ACD71B2AFD13480021127B /* DateRandomTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69E0A6B12AFD114600C8E8D9 /* DateRandomTests.swift */; }; 69ACD71C2AFD13480021127B /* IntRandomTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69E0A6B22AFD114600C8E8D9 /* IntRandomTests.swift */; }; 69ACD71D2AFD13480021127B /* StringRandomTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69E0A6B32AFD114600C8E8D9 /* StringRandomTests.swift */; }; + 69BC15952CF8A42C00A4B55F /* View+Frame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69BC15942CF8A42700A4B55F /* View+Frame.swift */; }; 69C6BE902B0BC80E008A4ECF /* UIWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69E0A6A82AFD114600C8E8D9 /* UIWindow.swift */; }; 69DF227B2B459D0D0025C555 /* PushManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69DF22792B459D0D0025C555 /* PushManager.swift */; }; 69DF227C2B459D0D0025C555 /* UNNotificationSettingsExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69DF227A2B459D0D0025C555 /* UNNotificationSettingsExtensions.swift */; }; @@ -266,6 +267,7 @@ 69ACC1812BBDF8DC00A109DB /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = ""; }; 69ACD6C22AFD130C0021127B /* ACKategories.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ACKategories.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 69ACD6C92AFD130D0021127B /* ACKategoriesTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ACKategoriesTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 69BC15942CF8A42700A4B55F /* View+Frame.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+Frame.swift"; sourceTree = ""; }; 69DF225A2B459CC50025C555 /* PushNotifications.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = PushNotifications.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 69DF22792B459D0D0025C555 /* PushManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PushManager.swift; sourceTree = ""; }; 69DF227A2B459D0D0025C555 /* UNNotificationSettingsExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UNNotificationSettingsExtensions.swift; sourceTree = ""; }; @@ -651,6 +653,7 @@ 69E0A6032AFD10BE00C8E8D9 /* SwiftUIExtensions */ = { isa = PBXGroup; children = ( + 69BC15942CF8A42700A4B55F /* View+Frame.swift */, 69246CFA2BDFE77400AB31A1 /* SwiftUIColorsTheme.swift */, 69E0A6042AFD10BE00C8E8D9 /* FontModifier.swift */, 693B39B62BF2359B00DF7C5E /* ACKHostingController.swift */, @@ -1292,6 +1295,7 @@ 69ACD6F12AFD133A0021127B /* UIControlEvents.swift in Sources */, 69ACD6F22AFD133A0021127B /* UIDeviceExtensions.swift in Sources */, 69ACD6F32AFD133A0021127B /* UIImageExtensions.swift in Sources */, + 69BC15952CF8A42C00A4B55F /* View+Frame.swift in Sources */, 69ACD6F42AFD133A0021127B /* UILabelExtensions.swift in Sources */, 69ACD6F52AFD133A0021127B /* UINavigationControllerExtensions.swift in Sources */, 69ACD6F62AFD133A0021127B /* UISearchBarExtensions.swift in Sources */, diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e1fa2a..8052344 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ ## Next +- Add `readSize` and `readFrame` to SwiftUI views ([#150](https://github.com/AckeeCZ/ACKategories/pull/150), kudos to @olejnjak) + ## 6.15.0 - SwiftUI improvements ([#149](https://github.com/AckeeCZ/ACKategories/pull/149), kudos to @olejnjak) diff --git a/Sources/ACKategories/SwiftUIExtensions/View+Frame.swift b/Sources/ACKategories/SwiftUIExtensions/View+Frame.swift new file mode 100644 index 0000000..83f4714 --- /dev/null +++ b/Sources/ACKategories/SwiftUIExtensions/View+Frame.swift @@ -0,0 +1,42 @@ +import SwiftUI + +@available(iOS 13.0, macOS 10.15, watchOS 6.0, tvOS 13.0, *) +public extension View { + func readSize( + onChange: @escaping (CGSize) -> Void + ) -> some View { + readFrame(in: .local) { onChange($0.size) } + } + + func readFrame( + in coordinateSpace: CoordinateSpace, + onChange: @escaping (CGRect) -> Void + ) -> some View { + background( + GeometryReader { geometryProxy in + Color.clear + .preference(key: FramePreferenceKey.self, value: geometryProxy.frame(in: coordinateSpace)) + } + ) + .onPreferenceChange(FramePreferenceKey.self, perform: onChange) + } +} + +private struct FramePreferenceKey: PreferenceKey { + static var defaultValue: CGRect = .zero + static func reduce(value: inout CGRect, nextValue: () -> CGRect) { } +} + +@available(iOS 13.0, macOS 10.15, watchOS 6.0, tvOS 13.0, *) +#Preview { + Text("Hello, World!") + .readSize { + print("Size:", $0) + } + .readFrame(in: .local) { + print("Local frame:", $0) + } + .readFrame(in: .global) { + print("Global frame:", $0) + } +}