MCPcopy Create free account
hub / github.com/callstack/react-native-paper / renderAppbarContent

Function renderAppbarContent

src/components/Appbar/utils.ts:132–192  ·  view source on GitHub ↗
({
  children,
  isDark,
  shouldCenterContent = false,
  isV3,
  renderOnly,
  renderExcept,
  mode = 'small',
  theme,
}: RenderAppbarContentProps)

Source from the content-addressed store, hash-verified

130};
131
132export const renderAppbarContent = ({
133 children,
134 isDark,
135 shouldCenterContent = false,
136 isV3,
137 renderOnly,
138 renderExcept,
139 mode = 'small',
140 theme,
141}: RenderAppbarContentProps) => {
142 return React.Children.toArray(children as React.ReactNode | React.ReactNode[])
143 .filter((child) => child != null && typeof child !== 'boolean')
144 .filter((child) =>
145 // @ts-expect-error: TypeScript complains about the type of type but it doesn't matter
146 renderExcept ? !renderExcept.includes(child.type.displayName) : child
147 )
148 .filter((child) =>
149 // @ts-expect-error: TypeScript complains about the type of type but it doesn't matter
150 renderOnly ? renderOnly.includes(child.type.displayName) : child
151 )
152 .map((child, i) => {
153 if (
154 !React.isValidElement<AppbarChildProps>(child) ||
155 ![
156 'Appbar.Content',
157 'Appbar.Action',
158 'Appbar.BackAction',
159 'Tooltip',
160 ].includes(
161 // @ts-expect-error: TypeScript complains about the type of type but it doesn't matter
162 child.type.displayName
163 )
164 ) {
165 return child;
166 }
167
168 const props: {
169 color?: string;
170 style?: StyleProp<ViewStyle>;
171 mode?: AppbarModes;
172 theme?: ThemeProp;
173 } = {
174 theme,
175 color: getAppbarColor({ color: child.props.color, isDark, isV3 }),
176 };
177
178 // @ts-expect-error: TypeScript complains about the type of type but it doesn't matter
179 if (child.type.displayName === 'Appbar.Content') {
180 props.mode = mode;
181 props.style = [
182 isV3
183 ? i === 0 && !shouldCenterContent && styles.v3Spacing
184 : i !== 0 && styles.v2Spacing,
185 shouldCenterContent && styles.centerAlignedContent,
186 child.props.style,
187 ];
188 props.color;
189 }

Callers 3

AppbarFunction · 0.90
Appbar.test.tsxFile · 0.90
renderResultFunction · 0.90

Calls 1

getAppbarColorFunction · 0.85

Tested by 1

renderResultFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…