feat: Implement subviews layout in header for iOS stack v5#3868
Draft
kmichalikk wants to merge 19 commits intomainfrom
Draft
feat: Implement subviews layout in header for iOS stack v5#3868kmichalikk wants to merge 19 commits intomainfrom
kmichalikk wants to merge 19 commits intomainfrom
Conversation
9f7743a to
3126537
Compare
d8a04d2 to
2571b25
Compare
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.
Closes https://github.com/software-mansion/react-native-screens-labs/issues/856
Description
This PR adds basic support for header configuration under new stack v5 on iOS. The primary focus here is to support the layout of custom react views inside the header. The following places could host a custom view:
leftBarButtonItems: multiple items, any of which can be react viewrightBarButtonItems: same as abovetitleView: custom view to replace the regular titlesubtitleView: to replace subview, below the titlelarbeSubtitleView: custom view below large titleThey are expected to be laid out seemlessly along native elements & with shadow state position matching the native hierarchy.
The configuration flow in new implementation follows roughly this diagram:
It was decided to give each item (no matter if it ends up as custom view or regular label button) a react native component. This way, each change to the props of each item maintains the same update flow: whenever props are updated, the menu item gets invalidated, which notifies the header config, which triggers the rebuild.
Caution
Optimization of the menu rebuild is not handled in this PR. For now, each invalidation triggers full menu rebuild. Same goes for any other optimization. This is an MVP implementation which will be iterated upon.
Caution
For now, no configuration is allowed for back button. Value of
leftItemsSupplementBackButtonis hardcoded toYESso no matter if left items are present or not, the back button is present. In fact, if the back button is not present, back gestures don't work - also tested on native app. So it's set to always be visible. DOUBLE CAUTION: default iOS gesture recognizer has this behavior. If we add a custom recognizer delegate, presence of back button won't affect the ability to swipe to pop.Caution
HeaderConfig is not exposed outside StackContainer. Testing the header requires modifying the values directly in StackContainer. The API is not final and is subject to change any time.
Important
I hadn't really considered item menus implementation (shown by long pressing items, if configured). Menus can hold native items (custom views don't work), and can be nested. The "configure-by-native-component" flow would be awkward for such menus. We need a better API for this. I hope it to be seamless with the API proposed here.
Important
Let's make sure we are okay with the proposed implementation. I want to have the same item configuration logic for toolbar in the future.
Before & after - visual documentation
stack-v5-header.mov
Test plan
For now, there are props: title, left and right items, titleItem, subtitleItem, largeSubtitleItem, largeTitleEnabled. TitleItem should take precedence over title. The title controls both regular and large title.
There are regular label buttons and custom view buttons. There are also spacers (fixed, fixed + width, flexible; for header, only fixed works on iOS 26, fixed with width works on iOS 18, flexible will work on toolbar when it will be introduced).
Setting the props should work. Mixing custom and regular buttons should work. See StackContainer.tsx for available item configuration. The shadow tree position should match whatever is visible on the screen. Button in, out, click events should work (added console.log())
Checklist