Skip to content

Commit 947192a

Browse files
author
Paweł Kata
committed
fix(appbar): integrate main changes
1 parent 3edb752 commit 947192a

8 files changed

Lines changed: 122 additions & 59 deletions

File tree

docs/component-docs.config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export type Page =
1313
source: string;
1414
component?: string;
1515
props?: string;
16+
propsSource?: string;
1617
title?: string;
1718
};
1819

@@ -32,7 +33,11 @@ type ComponentDocsConfig = {
3233

3334
const pages = {
3435
ActivityIndicator: 'ActivityIndicator',
35-
Appbar: 'Appbar/Appbar',
36+
Appbar: {
37+
source: 'Appbar/Appbar',
38+
component: 'Appbar',
39+
propsSource: 'Appbar/types',
40+
},
3641
Avatar: {
3742
AvatarIcon: 'Avatar/AvatarIcon',
3843
AvatarImage: 'Avatar/AvatarImage',

docs/plugins/component-docs/parser.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,11 +461,27 @@ export const createComponentParser = (tsconfigPath: string) => {
461461

462462
const componentName = page.component ?? getDefaultExportName(sourceFile);
463463
const component = findComponentDeclaration(sourceFile, componentName);
464+
const propsSourcePath = page.propsSource
465+
? path.join(sourceRootDir, `${page.propsSource}.ts`)
466+
: sourcePath;
467+
const propsSourceFile = page.propsSource
468+
? program.getSourceFile(propsSourcePath)
469+
: sourceFile;
470+
471+
if (!propsSourceFile || !fs.existsSync(propsSourcePath)) {
472+
return fail(
473+
propsSourcePath,
474+
'props source file was not found in the TypeScript program'
475+
);
476+
}
477+
464478
const propsType = findPropsType(
465-
sourceFile,
479+
propsSourceFile,
466480
page.props ?? DEFAULT_PROPS_TYPE
467481
);
468-
validatePropsType(sourceFile, propsType);
482+
if (!page.propsSource) {
483+
validatePropsType(propsSourceFile, propsType);
484+
}
469485
const defaults = getParameterDefaults(
470486
checker,
471487
sourceFile,
@@ -474,7 +490,7 @@ export const createComponentParser = (tsconfigPath: string) => {
474490
const props = getProps(
475491
checker,
476492
sourceRootDir,
477-
sourceFile,
493+
propsSourceFile,
478494
propsType,
479495
defaults
480496
);

docs/plugins/component-docs/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export type ComponentPageConfig = {
22
source: string;
33
component?: string;
44
props?: string;
5+
propsSource?: string;
56
title?: string;
67
};
78

src/components/Appbar/Appbar.tsx

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ const Appbar = ({
173173
}: Props) => {
174174
const theme = useInternalTheme(themeOverrides);
175175
const detectedInsets = useSafeAreaInsets();
176-
const { customBackground, restStyle, borderRadius } = React.useMemo(() => {
176+
const { customBackground, restStyle, borderStyles } = React.useMemo(() => {
177177
const flattenedStyle = StyleSheet.flatten(style);
178-
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
178+
179179
const resolvedStyle = (flattenedStyle || {}) as Exclude<
180180
typeof flattenedStyle,
181181
number
@@ -187,7 +187,7 @@ const Appbar = ({
187187
return {
188188
customBackground: backgroundColor,
189189
restStyle: remainingStyle,
190-
borderRadius: getAppbarBorders(remainingStyle),
190+
borderStyles: getAppbarBorders(remainingStyle),
191191
};
192192
}, [style]);
193193
const backgroundColor =
@@ -206,15 +206,11 @@ const Appbar = ({
206206
);
207207
const sideStyle = React.useMemo(() => ({ width: sideWidth }), [sideWidth]);
208208
const surfaceStyle = React.useMemo(
209-
() => [
210-
{
211-
backgroundColor,
212-
paddingTop: topInset,
213-
paddingHorizontal: horizontalInset,
214-
},
215-
borderRadius,
216-
],
217-
[backgroundColor, borderRadius, horizontalInset, topInset]
209+
() => ({
210+
paddingTop: topInset,
211+
paddingHorizontal: horizontalInset,
212+
}),
213+
[horizontalInset, topInset]
218214
);
219215
const appbarStyle = React.useMemo(
220216
() => [styles.appbar, { backgroundColor, minHeight }, restStyle],
@@ -228,12 +224,18 @@ const Appbar = ({
228224
? theme.colors.surfaceContainerHighest
229225
: theme.colors.surfaceContainer;
230226
const resolvedSearchStyle = React.useMemo(
231-
() => [
232-
styles.searchBar,
233-
{ backgroundColor: searchBackgroundColor },
234-
searchBar?.style,
235-
],
236-
[searchBackgroundColor, searchBar?.style]
227+
() => [styles.searchBar, searchBar?.style],
228+
[searchBar?.style]
229+
);
230+
const searchTheme = React.useMemo(
231+
() => ({
232+
...theme,
233+
colors: {
234+
...theme.colors,
235+
surfaceContainerHigh: searchBackgroundColor,
236+
},
237+
}),
238+
[searchBackgroundColor, theme]
237239
);
238240
const {
239241
accessibilityLabel: _accessibilityLabel,
@@ -286,7 +288,7 @@ const Appbar = ({
286288
elevation={0}
287289
testID={searchTestID}
288290
style={resolvedSearchStyle}
289-
theme={theme}
291+
theme={searchTheme}
290292
/>
291293
</View>
292294
</View>
@@ -388,10 +390,11 @@ const Appbar = ({
388390

389391
return (
390392
<Surface
393+
{...borderStyles}
391394
ref={ref}
392395
testID={`${testID}-root-layer`}
396+
backgroundColor={backgroundColor}
393397
elevation={0}
394-
container
395398
theme={theme}
396399
style={surfaceStyle}
397400
>

src/components/Appbar/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as React from 'react';
22
import type {
3-
Animated,
43
ColorValue,
54
GestureResponderEvent,
65
StyleProp,
@@ -26,6 +25,8 @@ export type AppbarHeadlineVariant = Exclude<AppbarVariant, 'search'>;
2625

2726
export type AppbarHeadlineAlignment = 'leading' | 'center';
2827

28+
export type AppbarStyle = Omit<ViewStyle, 'elevation'>;
29+
2930
export type AppbarTextProps = {
3031
/** Style applied to the text. */
3132
style?: StyleProp<TextStyle>;
@@ -169,7 +170,7 @@ type AppbarBaseProps = Omit<
169170
right?: number;
170171
};
171172
/** Style applied to the app bar container. */
172-
style?: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
173+
style?: StyleProp<AppbarStyle>;
173174
/** Reference for the app bar container. */
174175
ref?: React.Ref<View>;
175176
/** Theme override for the app bar. */

src/components/Appbar/utils.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Animated, ViewStyle } from 'react-native';
1+
import type { ViewStyle } from 'react-native';
22

33
import type { AppbarTrailingAction, AppbarVariant } from './types';
44

@@ -7,27 +7,31 @@ export const APPBAR_WIDE_ICON_BUTTON_SIZE = 64;
77
export const APPBAR_HEADLINE_IMAGE_HEIGHT = 32;
88
export const APPBAR_SEARCH_MAX_WIDTH = 720;
99

10-
const borderStyleProperties: readonly (keyof ViewStyle)[] = [
10+
const borderStyleProperties = [
1111
'borderRadius',
12+
'borderBottomEndRadius',
13+
'borderBottomStartRadius',
14+
'borderEndEndRadius',
15+
'borderEndStartRadius',
16+
'borderStartEndRadius',
17+
'borderStartStartRadius',
18+
'borderTopEndRadius',
19+
'borderTopStartRadius',
1220
'borderTopLeftRadius',
1321
'borderTopRightRadius',
1422
'borderBottomRightRadius',
1523
'borderBottomLeftRadius',
16-
];
24+
'borderCurve',
25+
] satisfies readonly (keyof ViewStyle)[];
1726

18-
export const getAppbarBorders = (
19-
style:
20-
| Animated.Value
21-
| Animated.AnimatedInterpolation<string | number>
22-
| Animated.WithAnimatedObject<ViewStyle>
23-
) => {
24-
const borders: Record<string, number> = {};
27+
export const getAppbarBorders = (style: ViewStyle) => {
28+
let borders: ViewStyle = {};
2529

2630
for (const property of borderStyleProperties) {
27-
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
28-
const value = style[property as keyof typeof style];
29-
if (value) {
30-
borders[property] = value;
31+
const value = style[property];
32+
33+
if (typeof value === 'number' || typeof value === 'string') {
34+
borders = { ...borders, [property]: value };
3135
}
3236
}
3337

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ describe('Appbar content', () => {
120120
expect(screen.getByTestId('appbar-content-subtitle-text')).toHaveStyle({
121121
textAlign: 'center',
122122
});
123-
expect(
124-
screen.getByTestId('leading-action-container-outer-layer').parent
125-
).toHaveStyle({ width: 96 });
126-
expect(
127-
screen.getByTestId('trailing-action-container-outer-layer').parent
128-
).toHaveStyle({ width: 96 });
123+
expect(screen.getByTestId('leading-action-container').parent).toHaveStyle({
124+
width: 96,
125+
});
126+
expect(screen.getByTestId('trailing-action-container').parent).toHaveStyle({
127+
width: 96,
128+
});
129129

130130
await rerender(
131131
<Appbar
@@ -153,12 +153,12 @@ describe('Appbar content', () => {
153153
/>
154154
);
155155

156-
expect(
157-
screen.getByTestId('leading-action-container-outer-layer').parent
158-
).toHaveStyle({ width: 96 });
159-
expect(
160-
screen.getByTestId('trailing-action-container-outer-layer').parent
161-
).toHaveStyle({ width: 96 });
156+
expect(screen.getByTestId('leading-action-container').parent).toHaveStyle({
157+
width: 96,
158+
});
159+
expect(screen.getByTestId('trailing-action-container').parent).toHaveStyle({
160+
width: 96,
161+
});
162162
expect(
163163
screen.getByTestId('brand-mark', { includeHiddenElements: true })
164164
).toBeOnTheScreen();
@@ -338,9 +338,9 @@ describe('Appbar actions', () => {
338338
expect(screen.getByTestId('expressive-action-container')).toHaveStyle({
339339
backgroundColor: color,
340340
});
341-
expect(
342-
screen.getByTestId('expressive-action-container-outer-layer')
343-
).toHaveStyle({ width: 56 });
341+
expect(screen.getByTestId('expressive-action-container')).toHaveStyle({
342+
width: 56,
343+
});
344344
}
345345
);
346346

@@ -527,9 +527,9 @@ describe('Appbar search', () => {
527527
expect(onChangeText).toHaveBeenLastCalledWith('draft');
528528
expect(searchbox).toHaveProp('value', 'draft');
529529

530-
expect(
531-
screen.getByTestId('message-search-container-outer-layer')
532-
).toHaveStyle({ width: '100%' });
530+
expect(screen.getByTestId('message-search-container')).toHaveStyle({
531+
width: '100%',
532+
});
533533
expect(screen.getByTestId('appbar-search-width-limiter')).toHaveStyle({
534534
width: '100%',
535535
maxWidth: 720,

src/components/__tests__/Appbar/utils.test.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,39 @@
11
import { describe, expect, it } from '@jest/globals';
22

3-
import { getAppbarHeight, getTrailingActionsWidth } from '../../Appbar/utils';
3+
import {
4+
getAppbarBorders,
5+
getAppbarHeight,
6+
getTrailingActionsWidth,
7+
} from '../../Appbar/utils';
8+
9+
describe('getAppbarBorders', () => {
10+
const borderStyles = {
11+
borderRadius: 0,
12+
borderBottomEndRadius: 2,
13+
borderBottomStartRadius: 3,
14+
borderEndEndRadius: 4,
15+
borderEndStartRadius: 5,
16+
borderStartEndRadius: 6,
17+
borderStartStartRadius: 7,
18+
borderTopEndRadius: 8,
19+
borderTopStartRadius: 9,
20+
borderTopLeftRadius: 10,
21+
borderTopRightRadius: 11,
22+
borderBottomRightRadius: 12,
23+
borderBottomLeftRadius: 13,
24+
borderCurve: 'continuous' as const,
25+
};
26+
27+
it('returns every border style and excludes unrelated styles', () => {
28+
expect(getAppbarBorders({ ...borderStyles, height: 60, top: 13 })).toEqual(
29+
borderStyles
30+
);
31+
});
32+
33+
it('returns an empty object when no border styles are passed', () => {
34+
expect(getAppbarBorders({ height: 60, top: 13 })).toEqual({});
35+
});
36+
});
437

538
describe('getAppbarHeight', () => {
639
it.each([

0 commit comments

Comments
 (0)