Support sizing of UIKit interop views using Auto Layout#2797
Support sizing of UIKit interop views using Auto Layout#2797Vendula Švastalová (svastven) merged 19 commits into
Conversation
…ement logic for interop views
92badaf to
e4dc3b4
Compare
Ivan Matkov (MatkovIvan)
left a comment
There was a problem hiding this comment.
Public API shape looks much better now, thanks! No blockers from my side, just a few nitpicks. But please wait for iOS folks' feedback before proceeding
For "Release Notes" - please describe it as a single feature, not like 3 separate ones
e4dc3b4 to
84e4f98
Compare
| val widthConstraint = if (fixedWidth != null) { | ||
| widthAnchor.constraintEqualToConstant(fixedWidth.value.toDouble()) | ||
| } else { | ||
| widthAnchor.constraintLessThanOrEqualToConstant(maxWidth.value.toDouble()) |
There was a problem hiding this comment.
Interesting approach!
To make the constraintLessThanOrEqualToConstant works properly, it's needed to disable two of four constraints between userComponent and its parent userComponentHostView. Otherwhise it looks like a constraint conflict: userComponent has constraints to its parent, which is fixed in size (and prevent the userComponent from shrinking), also at the same time it has active constraintLessThanOrEqualToConstant - which limits the view size, but may cause conflicts with the size of the userComponentHostView.
Also, userComponent.superview?.layoutIfNeeded() might be helpful before the measurement.
There was a problem hiding this comment.
Yes, userComponentHostView should be used to measure size, not userComponent. Thanks for catching!
As for layoutIfNeeded() I found that not necessary since fitting size seems to calculate with the constraints that are active. I would use that only if we found cases that it is actually really needed. Wdyt?
| */ | ||
| @Stable | ||
| @ExperimentalComposeUiApi | ||
| class UIKitInteropRemeasureRequester @RememberInComposition constructor() { |
There was a problem hiding this comment.
I still wondering if we can detect requestRemeasure by analyzing the frame of the "weighted" userComponent size inside the userComponentHostView.
There was a problem hiding this comment.
I am writing up a more comprehensive doc where all the cases should be explained.
db476f5 to
851d33a
Compare
Adds support for sizing of UIKit interop views using Auto Layout.
Introduces
UIKitInteropElementLayoutuserComponentview into hierarchyUIKitInteropElementMeasurePolicyMeasurePolicyfor the Compose node hosting the UIKit interop viewuserComponentfitting size and providing it to Compose layoutUIKitInteropRemeasureRequesterUIKitInteropRemeasureRequesterrequestRemeasure()provides a way to request remeasurement ofUIKitVieworUIKitViewControllerbased on fitting size changes of the given interopViewModifier.remeasureRequesterFixes CMP-9123 iOS support intrinsic sizing of interop elements - UIView with NSLayoutConstraints
Testing
Adds iOS instrumented tests covering interop view behavior:
UIKitInteropRemeasureRequester(constraint constant change, text change)remeasureRequesterlifecycle (binding/unbinding when interop node is added/removed)This should be tested by QA
Release Notes
Features - iOS
rememberUIKitInteropRemeasureRequester()+Modifier.remeasureRequester(...)withUIKitInteropRemeasureRequester.requestRemeasure()for propagating UIKit-side size changes to Compose.