Skip to content

Commit e98fce0

Browse files
refactor: remove ToggleButton (#5095)
1 parent 6f33357 commit e98fce0

14 files changed

Lines changed: 53 additions & 964 deletions

File tree

‎docs/6.x/docs/guides/migration.md‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ The following props now accept animated styles returned from `useAnimatedStyle`.
2525
- `Searchbar`: `style`
2626
- `Snackbar`: `style`
2727
- `Surface`: `style`
28-
- `ToggleButton`: `style`
2928

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

@@ -330,3 +329,31 @@ const theme = {
330329
style={{ fontSize: 16, color: '#1C1B1F' }}
331330
/>
332331
```
332+
333+
### ToggleButton
334+
335+
`ToggleButton`, `ToggleButton.Group` and `ToggleButton.Row` were removed. For an
336+
icon-only toggle, use `IconButton` with the `selected` prop. For a set of
337+
mutually exclusive options, use `SegmentedButtons`.
338+
339+
```tsx
340+
// Before (v5)
341+
<ToggleButton.Group value={value} onValueChange={setValue}>
342+
<ToggleButton icon="format-bold" value="bold" />
343+
<ToggleButton icon="format-italic" value="italic" />
344+
</ToggleButton.Group>
345+
346+
// After (v6)
347+
<>
348+
<IconButton
349+
icon="format-bold"
350+
selected={value === 'bold'}
351+
onPress={() => setValue('bold')}
352+
/>
353+
<IconButton
354+
icon="format-italic"
355+
selected={value === 'italic'}
356+
onPress={() => setValue('italic')}
357+
/>
358+
</>
359+
```

‎docs/component-docs.config.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,6 @@ const pages = {
149149
props: 'TextInputAccessoryProps',
150150
},
151151
},
152-
ToggleButton: {
153-
ToggleButton: 'ToggleButton/ToggleButton',
154-
ToggleButtonGroup: 'ToggleButton/ToggleButtonGroup',
155-
ToggleButtonRow: 'ToggleButton/ToggleButtonRow',
156-
},
157152
Tooltip: {
158153
Tooltip: 'Tooltip/Tooltip',
159154
},

‎docs/src/data/screenshots.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,6 @@ export const screenshots = {
149149
filled: 'screenshots/text-input-filled.png',
150150
outlined: 'screenshots/text-input-outlined.png',
151151
},
152-
ToggleButton: 'screenshots/toggle-button.png',
153-
'ToggleButton.Group': 'screenshots/toggle-button-group.gif',
154-
'ToggleButton.Row': 'screenshots/toggle-button-row.gif',
155152
Tooltip: 'screenshots/tooltip.png',
156153
TouchableRipple: 'screenshots/touchable-ripple.gif',
157154
};

‎example/src/ExampleList.tsx‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import TextExample from './Examples/TextExample';
4444
import TextInputExample from './Examples/TextInputExample';
4545
import ThemeExample from './Examples/ThemeExample';
4646
import ThemingWithReactNavigation from './Examples/ThemingWithReactNavigation';
47-
import ToggleButtonExample from './Examples/ToggleButtonExample';
4847
import TooltipExample from './Examples/TooltipExample';
4948
import TouchableRippleExample from './Examples/TouchableRippleExample';
5049

@@ -83,7 +82,6 @@ export const mainExamples = {
8382
Switch: SwitchExample,
8483
Text: TextExample,
8584
TextInput: TextInputExample,
86-
ToggleButton: ToggleButtonExample,
8785
TooltipExample,
8886
TouchableRipple: TouchableRippleExample,
8987
Theme: ThemeExample,

‎example/src/Examples/ToggleButtonExample.tsx‎

Lines changed: 0 additions & 123 deletions
This file was deleted.

‎example/src/Examples/TooltipExample.tsx‎

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
FAB,
1111
IconButton,
1212
List,
13-
ToggleButton,
1413
Tooltip,
1514
Card,
1615
} from 'react-native-paper';
@@ -39,7 +38,7 @@ const formOfTransport = [
3938
const TooltipExample = () => {
4039
const navigation = useNavigation('TooltipExample');
4140

42-
const [textAlign, setTextAlign] = React.useState('bold');
41+
const [textAlign, setTextAlign] = React.useState('left');
4342
React.useLayoutEffect(() => {
4443
navigation.setOptions({
4544
header: () => (
@@ -91,22 +90,34 @@ const TooltipExample = () => {
9190
))}
9291
</View>
9392
</List.Section>
94-
<List.Section title="Toggle Buttons">
95-
<ToggleButton.Row
96-
value={textAlign}
97-
style={styles.toggleButtonRow}
98-
onValueChange={setTextAlign}
99-
>
93+
<List.Section title="Icon toggles">
94+
<View style={styles.toggleRow}>
10095
<Tooltip title="Align left">
101-
<ToggleButton icon="format-align-left" value="left" />
96+
<IconButton
97+
icon="format-align-left"
98+
mode="contained-tonal"
99+
selected={textAlign === 'left'}
100+
onPress={() => setTextAlign('left')}
101+
/>
102102
</Tooltip>
103103
<Tooltip title="Align center">
104-
<ToggleButton icon="format-align-center" value="center" />
104+
<IconButton
105+
icon="format-align-center"
106+
mode="contained-tonal"
107+
selected={textAlign === 'center'}
108+
onPress={() => setTextAlign('center')}
109+
/>
105110
</Tooltip>
106111
<Tooltip title="Align right">
107-
<ToggleButton icon="format-align-right" value="right" disabled />
112+
<IconButton
113+
icon="format-align-right"
114+
mode="contained-tonal"
115+
selected={textAlign === 'right'}
116+
disabled
117+
onPress={() => setTextAlign('right')}
118+
/>
108119
</Tooltip>
109-
</ToggleButton.Row>
120+
</View>
110121
</List.Section>
111122
<List.Section title="Avatar">
112123
<View style={styles.avatarContainer}>
@@ -178,7 +189,8 @@ const styles = StyleSheet.create({
178189
cardContainer: {
179190
margin: 16,
180191
},
181-
toggleButtonRow: {
192+
toggleRow: {
193+
flexDirection: 'row',
182194
paddingHorizontal: 16,
183195
},
184196
iconButtonContainer: {

0 commit comments

Comments
 (0)