refactor: share one UIHingeInteraction factory across the iOS module and view - #12
Merged
Merged
Conversation
…and view The TurboModule and the Fabric observer view each carried their own SDK compile guard, iOS 27.1 availability check, UIHingeInteraction construction and UIHinge status mapping. A new HingesMakeInteraction helper owns all of that and hands each call site the same payload shape, matching how Android shares HingeSource. Behavior is unchanged.
janicduplessis
commented
Sep 21, 2026
| typedef void (^HingesUpdateHandler)(NSArray<NSDictionary *> *hinges); | ||
|
|
||
| /// Returns nil when the SDK or runtime has no UIHingeInteraction. | ||
| id<UIInteraction> _Nullable HingesMakeInteraction(HingesUpdateHandler handler); |
Contributor
Author
There was a problem hiding this comment.
Returning id<UIInteraction> rather than UIHingeInteraction * keeps this header buildable on SDKs that have no UIHingeInteraction declaration, so the guard stays confined to the .mm.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The iOS TurboModule and the Fabric observer view each built their own
UIHingeInteraction. Both carried the same__IPHONE_27_1compile guard, the same@available(iOS 27.1, *)check, and the sameUIHinge.statusto string mapping, so any change to the hinge mapping had to be made twice and kept in sync by hand. Android already routes both of its consumers through a singleHingeSource.Solution
ios/HingeInteraction.mmnow owns the SDK guard, the availability check, the interaction construction and the status/angle mapping, and hands the caller a plain payload array. Call sites just supply a handler.HingesMakeInteractionreturns nil when the feature is unavailable, from an old SDK or a pre-27.1 runtime; both call sites then attach nothing and keep an empty snapshot, exactly as the module already behaved when it had no root view.No behavior change.
Not covered: the only iOS reading available here is
closedat 0 degrees, so the rest of the status mapping stays exercised only by the Android end to end check. No real foldable device, and no changing angle.Test plan
iPhone Duo simulator on the iOS 27.1 runtime, built with Xcode 27.1 beta, Sensor lab:
NATIVE HINGEpill andNATIVE ANGLE 0.0° / closedcome from the Fabric view pathReact hook: 0.000 rad · Observer: 0.000 radcomes from the TurboModule path, covering both theuseHingeshook and a standalonecreateHingeObserverCompile guard: built the
Hingespod target against the iOS 27.0 SDK with the default Xcode forgeneric/platform=iOS Simulator. It compiles clean, andnm -uonHingeInteraction.olists only_objc_storeStrong, so nothing links againstUIHingeInteractionwhen the SDK lacks it.