Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v2] [iOS] Use autolayout constraints to set size of custom bar button item #4732

Merged
merged 2 commits into from Feb 14, 2019

Conversation

Projects
None yet
2 participants
@eliperkins
Copy link
Contributor

commented Feb 13, 2019

Before After
screen shot 2019-02-13 at 4 57 20 pm screen shot 2019-02-13 at 5 34 54 pm

Note the position of the custom UIBarButtonItem in the first image.

This fixes an issue where the frame for the custom view can be set to the incorrect y-offset upon setting the custom frame.

In iOS 11, this behavior changed, as UIBarButtonItem went from being using springs-and-struts for sizing, to using a UIStackView internally, and thus using Autolayout.

This lead to the superview of having a frame of (0, 22, 0, 0) at the first layout pass. From the above screenshot, when setting a breakpoint within RNNUIBarButtonItem's implementation of rootViewDidChangeIntrinsicSize::

(lldb) po rootView.superview
<_UITAMICAdaptorView: 0x7f8001507c90; frame = (0 22; 0 0); autoresizesSubviews = NO; layer = <CALayer: 0x600003b92c60>>

By moving to using NSLayoutConstaints, we can now properly size custom React Native views within UIBarButtonItems 100% of the time.

See also: https://gist.github.com/niw/569b49648fcab22124e1d12c195fe595
See also: https://stackoverflow.com/questions/10988918/change-width-of-a-uibarbuttonitem-in-a-uinavigationbar

@eliperkins eliperkins changed the title Use autolayout constraints to set size of custom bar button item [v2] [iOS] Use autolayout constraints to set size of custom bar button item Feb 13, 2019

@eliperkins eliperkins force-pushed the eliperkins:fix-custom-bar-button-items branch from ecf2228 to 298e9b9 Feb 13, 2019

Use autolayout constraints to set size of custom bar button item
This fixes an issue where the frame for the custom view can be set to the incorrect y-offset upon setting the custom frame.

In iOS 11, this behavior changed, as UIBarButtonItem went from being using springs-and-struts for sizing, to using a UIStackView, and thus using Autolayout.

This lead to the superview of having a frame of (0, 22, 0, 0) at the first layout pass.

By moving to using NSLayoutConstaints, we can now properly size our custom view.

See also: https://gist.github.com/niw/569b49648fcab22124e1d12c195fe595
See also: https://stackoverflow.com/questions/10988918/change-width-of-a-uibarbuttonitem-in-a-uinavigationbar

@eliperkins eliperkins force-pushed the eliperkins:fix-custom-bar-button-items branch from 298e9b9 to 2147db1 Feb 13, 2019

@guyca guyca requested a review from yogevbd Feb 14, 2019

@yogevbd yogevbd merged commit 362606b into wix:master Feb 14, 2019

1 check was pending

continuous-integration/jenkins/pr Build triggered for merge commit.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.