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
31 changes: 30 additions & 1 deletion docs/6.x/docs/guides/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ The following props now accept animated styles returned from `useAnimatedStyle`.
- `Searchbar`: `style`
- `Snackbar`: `style`
- `Surface`: `style`
- `ToggleButton`: `style`

So you can use Reanimated's `useSharedValue` and `useAnimatedStyle` to animate these components instead of the React Native `Animated` API.

Expand Down Expand Up @@ -279,3 +278,33 @@ const theme = {
style={{ fontSize: 16, color: '#1C1B1F' }}
/>
```

### ToggleButton

`ToggleButton`, `ToggleButton.Group` and `ToggleButton.Row` were removed. For an
icon-only toggle, use `IconButton` with the `selected` prop. For a set of
mutually exclusive options, use `SegmentedButtons`.

```tsx
// Before (v5)
<ToggleButton.Group value={value} onValueChange={setValue}>
<ToggleButton icon="format-bold" value="bold" />
<ToggleButton icon="format-italic" value="italic" />
</ToggleButton.Group>

// After (v6)
<>
<IconButton
icon="format-bold"
selected={value === 'bold'}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following this loses the selected state for screen readers: IconButton's selected only changes colours, while ToggleButton passed aria-selected through. Worth adding aria-selected to the snippet, or having IconButton derive it from selected?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JKobrynski, thank you for the comment! I've updated the migration docs with aria-selected.
As for deriving it from the selected one on the IconButton, I don't think that's in scope for this PR.
I can create a separate PR for it, or we can add it as a part of the IconButton modernization to MD3 (when that PR will be ready)

onPress={() => setValue('bold')}
aria-selected={value === 'bold'}
/>
<IconButton
icon="format-italic"
selected={value === 'italic'}
onPress={() => setValue('italic')}
aria-selected={value === 'italic'}
/>
</>
```
5 changes: 0 additions & 5 deletions docs/component-docs.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,6 @@ const pages = {
props: 'TextInputAccessoryProps',
},
},
ToggleButton: {
ToggleButton: 'ToggleButton/ToggleButton',
ToggleButtonGroup: 'ToggleButton/ToggleButtonGroup',
ToggleButtonRow: 'ToggleButton/ToggleButtonRow',
},
Tooltip: {
Tooltip: 'Tooltip/Tooltip',
},
Expand Down
3 changes: 0 additions & 3 deletions docs/src/data/screenshots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@ export const screenshots = {
filled: 'screenshots/text-input-filled.png',
outlined: 'screenshots/text-input-outlined.png',
},
ToggleButton: 'screenshots/toggle-button.png',
'ToggleButton.Group': 'screenshots/toggle-button-group.gif',
'ToggleButton.Row': 'screenshots/toggle-button-row.gif',
Tooltip: 'screenshots/tooltip.png',
TouchableRipple: 'screenshots/touchable-ripple.gif',
};
2 changes: 0 additions & 2 deletions example/src/ExampleList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import TextExample from './Examples/TextExample';
import TextInputExample from './Examples/TextInputExample';
import ThemeExample from './Examples/ThemeExample';
import ThemingWithReactNavigation from './Examples/ThemingWithReactNavigation';
import ToggleButtonExample from './Examples/ToggleButtonExample';
import TooltipExample from './Examples/TooltipExample';
import TouchableRippleExample from './Examples/TouchableRippleExample';

Expand Down Expand Up @@ -83,7 +82,6 @@ export const mainExamples = {
Switch: SwitchExample,
Text: TextExample,
TextInput: TextInputExample,
ToggleButton: ToggleButtonExample,
TooltipExample,
TouchableRipple: TouchableRippleExample,
Theme: ThemeExample,
Expand Down
123 changes: 0 additions & 123 deletions example/src/Examples/ToggleButtonExample.tsx

This file was deleted.

38 changes: 25 additions & 13 deletions example/src/Examples/TooltipExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
FAB,
IconButton,
List,
ToggleButton,
Tooltip,
Card,
} from 'react-native-paper';
Expand Down Expand Up @@ -40,7 +39,7 @@ const formOfTransport = [
const TooltipExample = () => {
const navigation = useNavigation('TooltipExample');

const [textAlign, setTextAlign] = React.useState('bold');
const [textAlign, setTextAlign] = React.useState('left');
React.useLayoutEffect(() => {
navigation.setOptions({
header: () => (
Expand Down Expand Up @@ -92,22 +91,34 @@ const TooltipExample = () => {
))}
</View>
</List.Section>
<List.Section title="Toggle Buttons">
<ToggleButton.Row
value={textAlign}
style={styles.toggleButtonRow}
onValueChange={setTextAlign}
>
<List.Section title="Icon toggles">
<View style={styles.toggleRow}>
<Tooltip title="Align left">
<ToggleButton icon="format-align-left" value="left" />
<IconButton
icon="format-align-left"
mode="contained-tonal"
selected={textAlign === 'left'}
onPress={() => setTextAlign('left')}
/>
</Tooltip>
<Tooltip title="Align center">
<ToggleButton icon="format-align-center" value="center" />
<IconButton
icon="format-align-center"
mode="contained-tonal"
selected={textAlign === 'center'}
onPress={() => setTextAlign('center')}
/>
</Tooltip>
<Tooltip title="Align right">
<ToggleButton icon="format-align-right" value="right" disabled />
<IconButton
icon="format-align-right"
mode="contained-tonal"
selected={textAlign === 'right'}
disabled
onPress={() => setTextAlign('right')}
/>
</Tooltip>
</ToggleButton.Row>
</View>
</List.Section>
<List.Section title="Avatar">
<View style={styles.avatarContainer}>
Expand Down Expand Up @@ -179,7 +190,8 @@ const styles = StyleSheet.create({
cardContainer: {
margin: 16,
},
toggleButtonRow: {
toggleRow: {
flexDirection: 'row',
paddingHorizontal: 16,
},
iconButtonContainer: {
Expand Down
Loading