From 024ce829c4eae5894ec1b2754092d0fe37344310 Mon Sep 17 00:00:00 2001 From: Bryan Keller Date: Tue, 16 Apr 2024 13:13:31 -0700 Subject: [PATCH] Fix visionOS SwiftUI bar interaction --- CHANGELOG.md | 1 + Sources/EpoxyBars/BarInstaller/BarStackView.swift | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff4767e3..beebca81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 approach to resolve an issue that could cause collection view cells to layout with unexpected dimensions - Made new layout-based SwiftUI cell rendering option the default. +- Fixed interaction of SwiftUI bars on visionOS ## [0.10.0](https://github.com/airbnb/epoxy-ios/compare/0.9.0...0.10.0) - 2023-06-29 diff --git a/Sources/EpoxyBars/BarInstaller/BarStackView.swift b/Sources/EpoxyBars/BarInstaller/BarStackView.swift index 1ec3e6fb..d431b7f9 100644 --- a/Sources/EpoxyBars/BarInstaller/BarStackView.swift +++ b/Sources/EpoxyBars/BarInstaller/BarStackView.swift @@ -295,7 +295,10 @@ public class BarStackView: UIStackView, EpoxyableView { for (index, wrapper) in zOrderedWrappers.enumerated() { // We pick 1000 as a sensible max to decrement from since we would never have that may bars. // We don't decrement from 0 since that causes bars to be invisible for some reason. - wrapper.layer.zPosition = CGFloat(1000 - index) + // Due to a bug on visionOS, we need to clamp this to be between -1 and 1, otherwise + // interaction breaks for SwiftUI views. + // http://openradar.appspot.com/radar?id=5534724382523392 + wrapper.layer.zPosition = CGFloat(1000 - index) / 1000 wrapper.zOrder = zOrder } }