You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: versioned_docs/version-7.x/elements.md
+184-3
Original file line number
Diff line number
Diff line change
@@ -148,7 +148,60 @@ It accepts the following props:
148
148
149
149
#### `headerTitle`
150
150
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
+
<TabsgroupId="config"queryString="config">
161
+
<TabItemvalue="static"label="Static"default>
162
+
163
+
```js
164
+
constRootStack=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
+
<TabItemvalue="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>
152
205
153
206
#### `headerTitleAlign`
154
207
@@ -161,11 +214,21 @@ Defaults to `center` on iOS and `left` on Android.
161
214
162
215
#### `headerTitleAllowFontScaling`
163
216
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`.
165
218
166
219
#### `headerLeft`
167
220
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:
Function which returns a React Element to display on the right side of the header.
216
279
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
+
<TabsgroupId="config"queryString="config">
287
+
<TabItemvalue="static"label="Static"default>
288
+
289
+
```js
290
+
constRootStack=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
+
<TabItemvalue="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
+
217
329
#### `headerShadowVisible`
218
330
219
331
Whether to hide the elevation shadow (Android) or the bottom border (iOS) on the header.
@@ -447,6 +559,36 @@ Usage:
447
559
<HeaderTitle>Hello</HeaderTitle>
448
560
```
449
561
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
+
450
592
### `HeaderBackButton`
451
593
452
594
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
490
632
-`pressColor` - Color of material ripple on Android when it's pressed
491
633
-`pressOpacity` - Opacity when it's pressed if material ripple isn't supported by the platform
492
634
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
+
493
674
### `ResourceSavingView`
494
675
495
676
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.
See [`HeaderButton`](elements.md#headerbutton) for usage.
769
+
766
770
#### `Label`
767
771
768
772
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
771
775
<Label>Home</Label>
772
776
```
773
777
778
+
See [`Label`](elements.md#label) for usage.
779
+
774
780
### `react-native-drawer-layout` package
775
781
776
782
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