Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions docs/6.x/docs/guides/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,59 @@ On Android, an open menu now also keeps the back press: it calls `onDismiss`, an

### Searchbar

The `Searchbar` modes use the latest Material 3 terminology in Paper 6.x:

- **`mode="bar"`** → **`mode="contained"`**
- **`mode="view"`** → **`mode="divided"`**

```tsx
// Before (v5)
<Searchbar mode="bar" value={query} onChangeText={setQuery} />
<Searchbar mode="view" value={query} onChangeText={setQuery} />

// After (v6)
<Searchbar mode="contained" value={query} onChangeText={setQuery} />
<Searchbar mode="divided" value={query} onChangeText={setQuery} />
```

Material 3 Expressive doesn't recommend the `divided` style, so prefer
`contained` for new screens.

The input and placeholder colors were swapped. The input text now uses
`onSurface` and the placeholder uses `onSurfaceVariant`, as Material 3 specifies.
The leading icon also changed from `onSurfaceVariant` to `onSurface`. To keep
the 5.x colors, pass them through `inputStyle`, `placeholderTextColor` and
`iconColor`:

```tsx
<Searchbar
value={query}
onChangeText={setQuery}
inputStyle={{ color: colors.onSurfaceVariant }}
placeholderTextColor={colors.onSurface}
iconColor={colors.onSurfaceVariant}
/>
```

The default `contained` mode adds 24dp horizontal margins and animates them to
12dp while focused. To keep a full-width Searchbar, provide a margin for that
axis; it replaces the built-in margin and disables the focus animation:

```tsx
<Searchbar
value={query}
onChangeText={setQuery}
style={{ marginHorizontal: 0 }}
/>
```

Only a margin naming that axis - `marginHorizontal`, `marginInline`,
`marginStart`, `marginEnd`, `marginInlineStart`, `marginInlineEnd`,
`marginLeft` or `marginRight` - replaces the animated one. The `margin`
shorthand is less specific, so the horizontal margins keep animating around it.
Use `marginVertical` when you only need vertical spacing and want to keep the
animated horizontal margins.

The misspelled `traileringIcon` props have been renamed:

- **`traileringIcon`** → **`trailingIcon`**
Expand Down
5 changes: 4 additions & 1 deletion docs/component-docs.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ const pages = {
RadioButtonIOS: 'RadioButton/RadioButtonIOS',
RadioButtonItem: 'RadioButton/RadioButtonItem',
},
Searchbar: 'Searchbar',
Searchbar: {
Searchbar: 'Searchbar/Searchbar',
SearchbarResults: 'Searchbar/SearchbarResults',
},
SegmentedButtons: {
SegmentedButtons: 'SegmentedButtons/SegmentedButtons',
},
Expand Down
4 changes: 2 additions & 2 deletions docs/src/data/screenshots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ export const screenshots = {
},
'RadioButton.Item': 'screenshots/radio-item.ios.png',
Searchbar: {
bar: 'screenshots/searchbar.png',
view: 'screenshots/searchbar-view.png',
contained: 'screenshots/searchbar.png',
divided: 'screenshots/searchbar-view.png',
},
SegmentedButtons: {
'single select': 'screenshots/segmented-button-single-select.png',
Expand Down
8 changes: 4 additions & 4 deletions docs/src/data/themeColors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,11 @@ export const themeColors = {
},
Searchbar: {
'-': {
backgroundColor: 'theme.colors.elevation.level3',
placeholderTextColor: 'theme.colors.onSurface',
textColor: 'theme.colors.onSurfaceVariant',
backgroundColor: 'theme.colors.surfaceContainerHigh',
placeholderTextColor: 'theme.colors.onSurfaceVariant',
textColor: 'theme.colors.onSurface',
selectionColor: 'theme.colors.primary',
iconColor: 'theme.colors.onSurfaceVariant',
iconColor: 'theme.colors.onSurface',
trailingIconColor: 'theme.colors.onSurfaceVariant',
dividerColor: 'theme.colors.outline',
},
Expand Down
70 changes: 59 additions & 11 deletions example/src/Examples/SearchbarExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import {

import ScreenWrapper from '../ScreenWrapper';

const FRUITS = ['Apple', 'Apricot', 'Avocado', 'Banana', 'Blueberry'];

const filterFruits = (query: string) =>
FRUITS.filter((fruit) => fruit.toLowerCase().includes(query.toLowerCase()));

const SearchExample = () => {
const navigation = useNavigation('Searchbar');

Expand All @@ -29,22 +34,26 @@ const SearchExample = () => {
clickableBack: '',
clickableDrawer: '',
clickableLoading: '',
withResults: '',
dividedWithResults: '',
});

const [isResultsBarFocused, setIsResultsBarFocused] = React.useState(false);

const { colors } = useTheme();

return (
<>
<ScreenWrapper>
<List.Section title="Bar mode">
<List.Section title="Contained mode">
<Searchbar
placeholder="Search"
onChangeText={(query) =>
setSearchQuery({ ...searchQueries, searchBarMode: query })
}
value={searchQueries.searchBarMode}
style={styles.searchbar}
mode="bar"
mode="contained"
/>
<Searchbar
placeholder="Trailing icon"
Expand All @@ -59,10 +68,10 @@ const SearchExample = () => {
trailingIconAccessibilityLabel={'microphone button'}
onTrailingIconPress={() => setIsVisible(true)}
style={styles.searchbar}
mode="bar"
mode="contained"
/>
<Searchbar
mode="bar"
mode="contained"
placeholder="Trailing icon with right item"
onChangeText={(query) =>
setSearchQuery({
Expand All @@ -87,7 +96,7 @@ const SearchExample = () => {
style={styles.searchbar}
/>
<Searchbar
mode="bar"
mode="contained"
placeholder="Right item"
onChangeText={(query) =>
setSearchQuery({
Expand Down Expand Up @@ -115,12 +124,12 @@ const SearchExample = () => {
}
value={searchQueries.loadingBarMode}
style={styles.searchbar}
mode="bar"
mode="contained"
loading
trailingIcon={'microphone'}
/>
</List.Section>
<List.Section title="View mode">
<List.Section title="Divided mode">
<Searchbar
placeholder="Search"
onChangeText={(query) =>
Expand All @@ -131,7 +140,7 @@ const SearchExample = () => {
}
value={searchQueries.searchViewMode}
style={styles.searchbar}
mode="view"
mode="divided"
/>
<Searchbar
placeholder="Search without bottom line"
Expand All @@ -143,7 +152,7 @@ const SearchExample = () => {
}
value={searchQueries.searchWithoutBottomLine}
style={styles.searchbar}
mode="view"
mode="divided"
showDivider={false}
/>
<Searchbar
Expand All @@ -156,10 +165,49 @@ const SearchExample = () => {
}
value={searchQueries.loadingViewMode}
style={styles.searchbar}
mode="view"
mode="divided"
loading
/>
</List.Section>
<List.Section title="With results">
<Searchbar
placeholder="Search fruit"
onChangeText={(query) =>
setSearchQuery({ ...searchQueries, withResults: query })
}
value={searchQueries.withResults}
onFocus={() => setIsResultsBarFocused(true)}
onBlur={() => setIsResultsBarFocused(false)}
style={styles.searchbar}
mode="contained"
/>
{/* Contained results line up with the focused bar, so they show only
while it has focus. */}
{isResultsBarFocused && searchQueries.withResults ? (
<Searchbar.Results>
<List.Subheader>Results</List.Subheader>
{filterFruits(searchQueries.withResults).map((fruit) => (
<List.Item key={fruit} title={fruit} />
))}
</Searchbar.Results>
) : null}
<Searchbar
placeholder="Search fruit"
onChangeText={(query) =>
setSearchQuery({ ...searchQueries, dividedWithResults: query })
}
value={searchQueries.dividedWithResults}
mode="divided"
/>
{searchQueries.dividedWithResults ? (
<Searchbar.Results mode="divided">
<List.Subheader>Results</List.Subheader>
{filterFruits(searchQueries.dividedWithResults).map((fruit) => (
<List.Item key={fruit} title={fruit} />
))}
</Searchbar.Results>
) : null}
</List.Section>
<List.Section title="Clickable icon">
<Searchbar
placeholder="Search"
Expand Down Expand Up @@ -225,7 +273,7 @@ SearchExample.title = 'Searchbar';

const styles = StyleSheet.create({
searchbar: {
margin: 4,
marginVertical: 4,
},
});
Comment thread
MrMuzyk marked this conversation as resolved.
Resolved

Expand Down
Loading
Loading