Skip to content

Register for trait changes instead of overriding -traitCollectionDidChange: on iOS 17+ - #60534

Open
christophpurrer wants to merge 1 commit into
react:mainfrom
christophpurrer:export-D133273358
Open

christophpurrer wants to merge 1 commit into
react:mainfrom
christophpurrer:export-D133273358

Conversation

@christophpurrer

Copy link
Copy Markdown
Contributor

Summary:
UIKit deprecated -traitCollectionDidChange: in iOS 17 in favor of -registerForTraitChanges:withAction:. Apps with a deployment target of iOS 17 or later warn about the override with -Wdeprecated-implementations.

RCTSurfaceHostingView, RCTTextInputComponentView, RCTViewComponentView and RCTView now register, on iOS and tvOS 17 and later, for the traits their override checked, with an action that holds the old body. The registration runs in each class's initializer. RCTTextInputComponentView compares against self.traitCollection rather than the global current trait collection, which UIKit sets only during -traitCollectionDidChange:. The override is kept only while the deployment target is below iOS 17; there it returns early on iOS 17 and later and otherwise calls the same action.

Behavior per OS:

  • Before iOS 17: unchanged.
  • iOS and tvOS 17 and later: the same code runs from the trait registration, for changes to the traits it checks.
  • Builds with a deployment target of iOS 17 or later no longer contain the deprecated override.

Changelog: [Internal]

Differential Revision: D133273358

…hange: on iOS 17+

Summary:
UIKit deprecated `-traitCollectionDidChange:` in iOS 17 in favor of `-registerForTraitChanges:withAction:`. Apps with a deployment target of iOS 17 or later warn about the override with `-Wdeprecated-implementations`.

`RCTSurfaceHostingView`, `RCTTextInputComponentView`, `RCTViewComponentView` and `RCTView` now register, on iOS and tvOS 17 and later, for the traits their override checked, with an action that holds the old body. The registration runs in each class's initializer. `RCTTextInputComponentView` compares against `self.traitCollection` rather than the global current trait collection, which UIKit sets only during `-traitCollectionDidChange:`. The override is kept only while the deployment target is below iOS 17; there it returns early on iOS 17 and later and otherwise calls the same action.

Behavior per OS:
- Before iOS 17: unchanged.
- iOS and tvOS 17 and later: the same code runs from the trait registration, for changes to the traits it checks.
- Builds with a deployment target of iOS 17 or later no longer contain the deprecated override.

Changelog: [Internal]

Differential Revision: D133273358
@meta-codesync

meta-codesync Bot commented Dec 4, 2026

Copy link
Copy Markdown

@christophpurrer has exported this pull request. If you are a Meta employee, you can view the originating Diff in D133273358.

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

Visual regression

No visual differences at 0d046b0dd6e8.

android: no capture

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants