fix: allows header style overriding #38
Merged
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
This change allows the
Header
styles to be fully overriden from the outside, including the internally calculated dimensions for the left, center and right containers.Motivation and Context
It's a common approach to let the consumer override the styles from the outside by placing the style prop last, so that the users of the component can do whatever they want with the internal containers, even to override the inner
width
andminWidth
that the component calculates. Besides that, it opens some other interesting options, like freely customizing theheaderStyle
with flex options to play along with its containers.As a practical example imagine the need for the title container to occupy most of the horizontal space of the header, rather than 1/3 as it is now, before this change, setting a
width
orminWidth
wouldn't have any effect, as the internal calculation will always prevail by precedence, same for flex options, as they are ignored with fixed widths.How Has This Been Tested?
I have tested these changes in my own app, where I was able to override the styles by setting the
width
andminWidth
.Types of changes
Checklist:
Screenshots
Before
After
The code for the results above:
Additional Notes (Optional)
I consider this as a breaking change because people might have set custom styles on those containers that were being ignored until now, and will from now on be properly respected.
By unsetting the
width
andminWidth
it may come with a tradeoff of poor header container alignments, like the title not being centered for uneven edges, but it's up to developer to adjust that if it's a deliberate decision to override those (like in my case). I do a custom calculation of the side container dimensions based on the larger edge width, that way it ensures that when the containers are uneven it will always make sure that the title container has the same distance to both edges and therefore the title can be center aligned if needed. This could be an interesting future improvement for the package, even more if you plan to support left aligned (android) or expanded center containers.