Skip to content

Conversation

@eliperkins
Copy link
Contributor

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 fix-custom-bar-button-items branch from ecf2228 to 298e9b9 Compare February 13, 2019 22:44
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 fix-custom-bar-button-items branch from 298e9b9 to 2147db1 Compare February 13, 2019 22:45
@guyca guyca requested a review from yogevbd February 14, 2019 08:06
@yogevbd yogevbd merged commit 362606b into wix:master Feb 14, 2019
vshkl pushed a commit to vshkl/react-native-navigation that referenced this pull request Feb 5, 2020
…#4732)

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants