Skip to content

Add View.onPreferenceChange support#937

Merged
Kyle-Ye merged 5 commits into
mainfrom
feature/os_preference_change
Jul 15, 2026
Merged

Add View.onPreferenceChange support#937
Kyle-Ye merged 5 commits into
mainfrom
feature/os_preference_change

Conversation

@Kyle-Ye

@Kyle-Ye Kyle-Ye commented Jul 15, 2026

Copy link
Copy Markdown
Member

Summary

  • add View.onPreferenceChange(_:perform:) with preference value-change tracking and cycle handling
  • add the private transactional preference-change overload that forwards the producing Transaction
  • update preference-writing integration for the new action path
  • add separate examples and UI test cases for the public and transactional APIs
  • preserve shared availability configurations in the generated Example targets

This supersedes #926 and incorporates the initial implementation by @Dark-Existed.

Closes #925

Validation

  • xcodebuild build -workspace Example/Example.xcworkspace -scheme OSUI_Example -configuration OpenSwiftUIDebug -destination 'generic/platform=iOS Simulator' CODE_SIGNING_ALLOWED=NO
  • xcodebuild build -workspace Example/Example.xcworkspace -scheme SUI_Example -configuration SwiftUIDebug -destination 'generic/platform=iOS Simulator' CODE_SIGNING_ALLOWED=NO
  • UI tests not run

@github-actions github-actions Bot added area: data-flow State, binding, environment, preference, observation, or property data flow. area: example Example apps, previews, sample projects, screenshots, or demo assets. area: tests Test suites, UI tests, fixtures, snapshots, and test support code. area: view View APIs, modifiers, AnyView, ForEach, DynamicView, and related behavior. type: feature New API, behavior, platform support, or user-facing capability. labels Jul 15, 2026
@Kyle-Ye Kyle-Ye marked this pull request as ready for review July 15, 2026 17:08
@Kyle-Ye Kyle-Ye changed the title Complete View.onPreferenceChange support Add View.onPreferenceChange support Jul 15, 2026
@augmentcode

augmentcode Bot commented Jul 15, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: This PR completes View.onPreferenceChange support in OpenSwiftUI, including a transactional overload that forwards the producing Transaction.

Changes:

  • Adds `View.onPreferenceChange(_:perform:)` with value-change tracking, reset-seed handling, and update-cycle detection.
  • Introduces a transactional preference action modifier/binder that delivers both the new preference value and the corresponding `Transaction`.
  • Updates preference-writing and scene preference integration to support the new preference-action path.
  • Adds separate Example views plus UI tests for the public API and the transactional SPI API.
  • Tweaks Example project file inclusion to keep shared availability configuration inputs stable.

Technical Notes: Action dispatch is enqueued via Update.enqueueAction, and cycle detection is reset on viewPhase.resetSeed to help prevent preference-driven update loops.

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 1 suggestion posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

@_exported import SwiftUI

@available(iOS 18.2, macOS 15.2, *)
@frozen public struct TransactionalPreferenceActionModifier<Key> : SwiftUI.ViewModifier where Key : SwiftUI.PreferenceKey, Key.Value : Swift.Equatable {

@augmentcode augmentcode Bot Jul 15, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@available(iOS 18.2, macOS 15.2, *) makes this symbol effectively available on tvOS/watchOS/visionOS at all versions; consider adding explicit availability for the other Apple platforms (or marking them unavailable) to avoid cross-platform build mismatches. (Also applies to the similar availability usage in the transactional example/test in this PR.)

Severity: medium

Other Locations
  • Example/Shared/ViewModifier/TransactionalPreferenceActionModifierExample.swift:14
  • Example/OpenSwiftUIUITests/Modifier/ViewModifier/PreferenceActionModifierUITests.swift:50

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

@Kyle-Ye Kyle-Ye merged commit 95a6131 into main Jul 15, 2026
5 of 8 checks passed
@Kyle-Ye Kyle-Ye deleted the feature/os_preference_change branch July 15, 2026 17:25
@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 96 lines in your changes missing coverage. Please review.
✅ Project coverage is 25.87%. Comparing base (e2c69fa) to head (504f026).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...ore/Data/Preference/PreferenceActionModifier.swift 0.00% 88 Missing ⚠️
...difier/SceneModifier/PreferenceSceneModifier.swift 0.00% 3 Missing ⚠️
...re/Data/Preference/PreferenceWritingModifier.swift 0.00% 3 Missing ⚠️
...difier/ViewModifier/PreferenceActionModifier.swift 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #937      +/-   ##
==========================================
- Coverage   25.92%   25.87%   -0.05%     
==========================================
  Files         721      723       +2     
  Lines       50788    50878      +90     
==========================================
- Hits        13165    13163       -2     
- Misses      37623    37715      +92     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: data-flow State, binding, environment, preference, observation, or property data flow. area: example Example apps, previews, sample projects, screenshots, or demo assets. area: tests Test suites, UI tests, fixtures, snapshots, and test support code. area: view View APIs, modifiers, AnyView, ForEach, DynamicView, and related behavior. type: feature New API, behavior, platform support, or user-facing capability.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add View.onPreferenceChange Support

1 participant