Removed left padding on KeyboardToolbar when navigation arrows are hidden#851
Removed left padding on KeyboardToolbar when navigation arrows are hidden#851spaansba wants to merge 4 commits intokirillzyusko:mainfrom spaansba:remove-left-padding
Conversation
| paddingLeft: showArrows ? 8 : 0, | ||
| paddingRight: 8, |
There was a problem hiding this comment.
My current idea was to add View instead of <> for button group and apply a style paddingLeft there.
And accordingly I wanted to remove paddingHorizontal from container and add paddingRight: 8 to doneButtonContainer. In this case we will not need to write additional conditional code 🤔
There was a problem hiding this comment.
Can you try to make these changes and I'll run CI to see if it passes or not? 👀
There was a problem hiding this comment.
That was exactly my first idea as well!
What I think might be an even better approach is the following:
- Remove
paddingHorizontal: 8fromtoolbarstyle - Add a
Viewinstead of<>and give it the following styles:
arrowsButton: {
flexDirection: 'row',
gap: 5,
paddingHorizontal:8,
},
- Remove the done
doneButtonContainerstyles - add
paddingHorizonal: 8todoneButton - in Arrow.tsx remove
marginHorizontal: 5fromarrowUpContainer
This way both done and arrow buttons have a padding of 8 and the 2 arrow buttons still have the gap of 5 between them. Also with this if the arrow or done button gets removed the whole container is removed as well.
Also in the previous version the done button didnt have padding on the left only on the right (margin). Now it is centered in its container.
| { | ||
| quoteProps: "consistent", | ||
| trailingComma: "all", | ||
| endOfLine: "auto", |
There was a problem hiding this comment.
Had to add this otherwise every single line would error out for me.
📊 Package size report
|
| }, | ||
| arrowsButton: { | ||
| flexDirection: "row", | ||
| gap: 5, |
There was a problem hiding this comment.
I think gap was added relatively recently and I support older RN versions as well, so it's better to use paddings/margins to make sure all library users have consistent experience 😊
There was a problem hiding this comment.
Makes sense! I remove the gap and added marginRight: 2.5 and marginLeft: 2.5 on the arrowUp/down containers respectively. I also made it so the arrowContainer is a base container and the arrowUp/down add styles to the base container instead of the down container adding styles to the up container.
| alignItems: "center", | ||
| justifyContent: "center", |
There was a problem hiding this comment.
Ah you are right, thats not needed.
| }, | ||
| doneButtonContainer: { | ||
| marginRight: 8, | ||
| paddingHorizontal: DEFAULT_BUTTON_PADDING, |
There was a problem hiding this comment.
With a new approach arrow both done/arrows will have a horizontal padding, right?
I think with a previous approach only arrows had paddingRight and theoretically long content could overlap with "Done" button (since Done buttong didn't have any margin/padding from left). I think a new approach makes sense 👍
There was a problem hiding this comment.
yes with this approach both containers will have the exact amount of horizontal padding.
I tested it with long content (a custom toolbar) and there is no overlapping in this approach with or without the arrows/done button!
|
@spaansba after your changes button have different positioning: This component is a pretty precise replica of iOS toolbar and I'd like to continue to have pixel-perfect UI 🙂 |
|
interesting, Ill have a look |
|
Closing in favour of #865 |
## 📜 Description Apply arrow/done paddings on elements level, not entire container, so that conditional rendering will exclude potentially undesired paddings. ## 💡 Motivation and Context Potentially "padding by default" approach may be not desired when you want your custom element (content) to place that space. So in this PR I re-worked an approach, and if done/arrows are hidden, then `content` will fill entire container. Closes #848 Successor of #851 ## 📢 Changelog <!-- High level overview of important changes --> <!-- For example: fixed status bar manipulation; added new types declarations; --> <!-- If your changes don't affect one of platform/language below - then remove this platform/language --> ### JS - removed `paddingHorizontal` from main container; - added container for arrows and apply padding there; - apply padding (+8px) to Done button (to compensate removed padding from main container); ## 🤔 How Has This Been Tested? Tested manually on iPhone 15 Pro (iOS 17.5 Fabric). ## 📸 Screenshots (if appropriate): |No arrows|No done button|No toolbar elements|All elements| |----------|----------------|--------------------|------------| ||||| ## 📝 Checklist - [x] CI successfully passed - [x] I added new mocks and corresponding unit-tests if library API was changed

📜 Description
Remove padding when showArrows={false} on KeyboardToolbar
The KeyboardToolbar component currently applies a fixed paddingHorizontal of 8px even when showArrows is set to false. This creates an unnecessary left padding gap when arrows are hidden. This PR modifies the toolbar styling to conditionally apply paddingLeft only when arrows are visible.
💡 Motivation and Context
When setting showArrows={false}, users expect the whole container to be gone.
Closes #848
📢 Changelog
JS
🤔 How Has This Been Tested?
Tested manually with both showArrows={true} and showArrows={false} to ensure:
📸 Screenshots (if appropriate):
Before:

After:

📝 Checklist