Skip to content

Commit db761ed

Browse files
committed
Document new elements
1 parent d90dfc6 commit db761ed

File tree

2 files changed

+190
-3
lines changed

2 files changed

+190
-3
lines changed

versioned_docs/version-7.x/elements.md

+184-3
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,60 @@ It accepts the following props:
148148

149149
#### `headerTitle`
150150

151-
String or a function that returns a React Element to be used by the header. Defaults to scene `title`. When a function is specified, it receives an object containing `allowFontScaling`, `tintColor`, `style` and `children` properties. The `children` property contains the title string.
151+
String or a function that returns a React Element to be used by the header. Defaults to scene `title`.
152+
153+
When a function is specified, it receives an object containing following properties:
154+
155+
- `allowFontScaling`: Whether it scale to respect Text Size accessibility settings.
156+
- `tintColor`: Text color of the header title.
157+
- `style`: Style object for the `Text` component.
158+
- `children`: The title string (from `title` in `options`).
159+
160+
<Tabs groupId="config" queryString="config">
161+
<TabItem value="static" label="Static" default>
162+
163+
```js
164+
const RootStack = createNativeStackNavigator({
165+
screens: {
166+
Home: {
167+
screen: HomeScreen,
168+
options: {
169+
headerTitle: ({ allowFontScaling, tintColor, style, children }) => (
170+
<Text
171+
style={[style, { color: tintColor }]}
172+
allowFontScaling={allowFontScaling}
173+
>
174+
{children}
175+
</Text>
176+
),
177+
},
178+
},
179+
},
180+
});
181+
```
182+
183+
</TabItem>
184+
<TabItem value="dynamic" label="Dynamic">
185+
186+
```js
187+
<Stack.Screen
188+
name="Home"
189+
component={HomeScreen}
190+
options={{
191+
headerTitle: ({ allowFontScaling, tintColor, style, children }) => (
192+
<Text
193+
style={[style, { color: tintColor }]}
194+
allowFontScaling={allowFontScaling}
195+
>
196+
{children}
197+
</Text>
198+
),
199+
}}
200+
/>
201+
```
202+
203+
</TabItem>
204+
</Tabs>
152205

153206
#### `headerTitleAlign`
154207

@@ -161,11 +214,21 @@ Defaults to `center` on iOS and `left` on Android.
161214

162215
#### `headerTitleAllowFontScaling`
163216

164-
Whether header title font should scale to respect Text Size accessibility settings. Defaults to false.
217+
Whether header title font should scale to respect Text Size accessibility settings. Defaults to `false`.
165218

166219
#### `headerLeft`
167220

168-
Function which returns a React Element to display on the left side of the header. You can use it to implement your custom left button, for example:
221+
Function which returns a React Element to display on the left side of the header.
222+
223+
It receives an object containing following properties:
224+
225+
- `tintColor`: The color of the icon and label.
226+
- `pressColor`: The color of the material ripple (Android >= 5.0 only).
227+
- `pressOpacity`: The opacity of the button when it's pressed (Android < 5.0, and iOS).
228+
- `labelVisible`: Whether the label text is visible. Defaults to `true` on iOS and `false` on Android.
229+
- `href`: The URL to open when the button is pressed on the Web.
230+
231+
You can use it to implement your custom left button, for example:
169232

170233
<Tabs groupId="config" queryString="config">
171234
<TabItem value="static" label="Static" default>
@@ -214,6 +277,55 @@ const RootStack = createNativeStackNavigator({
214277

215278
Function which returns a React Element to display on the right side of the header.
216279

280+
It receives an object containing following properties:
281+
282+
- `tintColor`: The color of the icon and label.
283+
- `pressColor`: The color of the material ripple (Android >= 5.0 only).
284+
- `pressOpacity`: The opacity of the button when it's pressed (Android < 5.0, and iOS).
285+
286+
<Tabs groupId="config" queryString="config">
287+
<TabItem value="static" label="Static" default>
288+
289+
```js
290+
const RootStack = createNativeStackNavigator({
291+
screens: {
292+
Home: {
293+
screen: HomeScreen,
294+
options: {
295+
headerLeft: (props) => (
296+
<MyButton {...props} onPress={() => {
297+
// Do something
298+
}}>
299+
)
300+
}
301+
}
302+
}
303+
})
304+
```
305+
306+
</TabItem>
307+
<TabItem value="dynamic" label="Dynamic">
308+
309+
```js
310+
<Stack.Screen
311+
name="Home"
312+
component={HomeScreen}
313+
options={{
314+
headerLeft: (props) => (
315+
<MyButton
316+
{...props}
317+
onPress={() => {
318+
// Do something
319+
}}
320+
/>
321+
),
322+
}}
323+
/>
324+
```
325+
326+
</TabItem>
327+
</Tabs>
328+
217329
#### `headerShadowVisible`
218330

219331
Whether to hide the elevation shadow (Android) or the bottom border (iOS) on the header.
@@ -447,6 +559,36 @@ Usage:
447559
<HeaderTitle>Hello</HeaderTitle>
448560
```
449561

562+
### `HeaderButton`
563+
564+
A component used to show a button in header. It can be used for both left and right buttons. It accepts the following props:
565+
566+
- `onPress` - Callback to call when the button is pressed.
567+
- `href` - The `href` to use for the anchor tag on web.
568+
- `disabled` - Boolean which controls whether the button is disabled.
569+
- `accessibilityLabel` - Accessibility label for the button for screen readers.
570+
- `testID` - ID to locate this button in tests.
571+
- `tintColor` - Tint color for the header button.
572+
- `pressColor` - Color for material ripple (Android >= 5.0 only).
573+
- `pressOpacity` - Opacity when the button is pressed if material ripple isn't supported by the platform.
574+
- `style` - Style object for the button.
575+
- `children` - Content to render for the button. Usually the icon.
576+
577+
Usage:
578+
579+
```js
580+
<HeaderButton
581+
accessibilityLabel="More options"
582+
onPress={() => console.log('button pressed')}
583+
>
584+
<MaterialCommunityIcons
585+
name="dots-horizontal-circle-outline"
586+
size={24}
587+
color={tintColor}
588+
/>
589+
</HeaderButton>
590+
```
591+
450592
### `HeaderBackButton`
451593

452594
A component used to show the back button header. It's the default for [`headerLeft`](#headerleft) in the [stack navigator](stack-navigator.md). It accepts the following props:
@@ -490,6 +632,45 @@ A component which provides an abstraction on top of [`Pressable`](https://reactn
490632
- `pressColor` - Color of material ripple on Android when it's pressed
491633
- `pressOpacity` - Opacity when it's pressed if material ripple isn't supported by the platform
492634

635+
### `Button`
636+
637+
A component that renders a button. In addition to [`PlatformPressable`](#platformpressable)'s props, it accepts following additional props:
638+
639+
- `variant` - Variant of the button. Possible values are:
640+
- `tinted` (default)
641+
- `plain`
642+
- `filled`
643+
- `color` - Color of the button. Defaults to the [theme](themes.md)'s primary color.
644+
- `children` - Content to render inside the button.
645+
646+
In addition, the button integrates with React Navigation and accepts the same props as [`useLinkProps`](use-link-props.md#options) hook.
647+
648+
It can be used to navigate between screens by specifying a screen name and params:
649+
650+
```js
651+
<Button title="Go to Profile" screen="Profile" params={{ userId: 'jane' }} />
652+
```
653+
654+
Or as a regular button:
655+
656+
```js
657+
<Button title="Press me" onPress={() => console.log('button pressed')} />
658+
```
659+
660+
### `Label`
661+
662+
The `Label` component is used to render small text. It is used in [Bottom Tab Navigator](bottom-tab-navigator.md) to render the label for each tab.
663+
664+
In addition to the standard [`Text`](https://reactnative.dev/docs/text) props, it accepts the following props:
665+
666+
- `tintColor` - Color of the label. Defaults to the [theme](themes.md)'s text color.
667+
668+
Usage:
669+
670+
```jsx
671+
<Label>Home</Label>
672+
```
673+
493674
### `ResourceSavingView`
494675

495676
A component which aids in improving performance for inactive screens by utilizing [`removeClippedSubviews`](https://reactnative.dev/docs/view#removeclippedsubviews). It accepts a `visible` prop to indicate whether a screen should be clipped.

versioned_docs/version-7.x/upgrading-from-6.x.md

+6
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,8 @@ It can also be used as a regular button:
742742
743743
The button follows the [Material Design 3 guidelines](https://m3.material.io/components/buttons/overview).
744744
745+
See [`Button`](elements.md#button) for usage.
746+
745747
#### `HeaderButton`
746748
747749
The `HeaderButton` component can be used to render buttons in the header with appropriate styling:
@@ -763,6 +765,8 @@ headerRight: ({ tintColor }) => (
763765
),
764766
```
765767
768+
See [`HeaderButton`](elements.md#headerbutton) for usage.
769+
766770
#### `Label`
767771
768772
The `Label` component can be used to render label text, such as the label in a tab bar button:
@@ -771,6 +775,8 @@ The `Label` component can be used to render label text, such as the label in a t
771775
<Label>Home</Label>
772776
```
773777
778+
See [`Label`](elements.md#label) for usage.
779+
774780
### `react-native-drawer-layout` package
775781
776782
The drawer implementation used in `@react-navigation/drawer` is now available as a standalone package called `react-native-drawer-layout`. This makes it easier to use the drawer implementation even if you're not using React Navigation, or if you want to use it without a navigator.

0 commit comments

Comments
 (0)