Skip to content

Commit ae019a0

Browse files
committed
fix: icons alignment
1 parent 22de99e commit ae019a0

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

src/components/Appbar/Appbar.tsx

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,14 @@ const Appbar = ({
211211

212212
React.Children.forEach(children, (child) => {
213213
if (React.isValidElement(child)) {
214+
const isLeading = child.props.isLeading === true;
215+
214216
if (child.type === AppbarContent) {
215217
hasAppbarContent = true;
216-
} else if (hasAppbarContent) {
217-
rightItemsCount++;
218-
} else {
218+
} else if (isLeading || !hasAppbarContent) {
219219
leftItemsCount++;
220+
} else {
221+
rightItemsCount++;
220222
}
221223
}
222224
});
@@ -254,18 +256,32 @@ const Appbar = ({
254256
{...rest}
255257
>
256258
{shouldAddLeftSpacing ? <View style={spacingStyle} /> : null}
257-
{(!isV3 || isMode('small') || isMode('center-aligned')) &&
258-
renderAppbarContent({
259-
children: [
259+
{(!isV3 || isMode('small') || isMode('center-aligned')) && (
260+
<>
261+
{/* Render only the back action at first place */}
262+
{renderAppbarContent({
263+
children,
264+
isDark,
265+
theme,
266+
isV3,
267+
renderOnly: ['Appbar.BackAction'],
268+
shouldCenterContent: isV3CenterAlignedMode || shouldCenterContent,
269+
})}
270+
{/* Render the rest of the content except the back action */}
271+
{renderAppbarContent({
260272
// Filter appbar actions - first leading icons, then trailing icons
261-
...filterAppbarActions(children, true),
262-
...filterAppbarActions(children),
263-
],
264-
isDark,
265-
theme,
266-
isV3,
267-
shouldCenterContent: isV3CenterAlignedMode || shouldCenterContent,
268-
})}
273+
children: [
274+
...filterAppbarActions(children, true),
275+
...filterAppbarActions(children),
276+
],
277+
isDark,
278+
theme,
279+
isV3,
280+
renderExcept: ['Appbar.BackAction'],
281+
shouldCenterContent: isV3CenterAlignedMode || shouldCenterContent,
282+
})}
283+
</>
284+
)}
269285
{(isMode('medium') || isMode('large')) && (
270286
<View
271287
style={[

src/components/Appbar/AppbarAction.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export type Props = React.ComponentPropsWithoutRef<typeof IconButton> & {
4848
/**
4949
* @supported Available in v5.x with theme version 3
5050
*
51-
* Whether it's the leading button.
51+
* Whether it's the leading button. Note: If `Appbar.BackAction` is present, it will be rendered before any `isLeading` icons.
5252
*/
5353
isLeading?: boolean;
5454
style?: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;

src/components/__tests__/Appbar/__snapshots__/Appbar.test.tsx.snap

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,9 @@ exports[`Appbar passes additional props to AppbarBackAction, AppbarContent and A
652652
"paddingHorizontal": 0,
653653
},
654654
[
655-
false,
655+
{
656+
"marginLeft": 12,
657+
},
656658
false,
657659
undefined,
658660
],

0 commit comments

Comments
 (0)