Skip to content
Merged
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
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,41 @@ An object container
- `fontFamily`: overrides font-family of selected segment text
- `fontWeight`: overrides font-weight of selected segment text

### `tabStyle`

(Android and Web only) Styles the clickable surface which is responsible to change tabs
| Type | Required | Platform |
| ------ | -------- | -------- |
| object | No | Android, Web |

Extends [ViewStyles](https://reactnative.dev/docs/view-style-props)

## Tips and Tricks

### How can I increase the height of the tab ?

For android and IOS, simply pass `prop.style`:

```json
{
"height": number
}
```

For react-native-web, additionally pass :

```json
{
"paddingVertical": number,
or
"height": number
}
```

### Adding padding makes text disappear on Android

If padding amount exceeds the fixed height of the container, it will shrink the text. So either increase the height or reduce your padding.

## Maintainers

- [M.Haris Baig](https://github.com/harisbaig100)
Expand Down
6 changes: 6 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
NativeMethods,
Constructor,
TargetedEvent,
ViewStyle,
} from 'react-native';

export interface NativeSegmentedControlIOSChangeEvent extends TargetedEvent {
Expand Down Expand Up @@ -104,6 +105,11 @@ export interface SegmentedControlProps extends ViewProps {
* Active Font style properties of the Segmented Control
*/
activeFontStyle?: FontStyle;

/**
* Touchable style properties for Segmented Control Tab
*/
tabStyle?: ViewStyle;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions js/SegmentedControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const SegmentedControl = ({
values,
tintColor,
backgroundColor,
tabStyle,
fontStyle,
activeFontStyle,
appearance,
Expand Down Expand Up @@ -101,6 +102,7 @@ const SegmentedControl = ({
key={index}
value={value}
tintColor={tintColor}
tabStyle={tabStyle}
fontStyle={fontStyle}
activeFontStyle={activeFontStyle}
appearance={colorScheme}
Expand Down
8 changes: 5 additions & 3 deletions js/SegmentedControlTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
useColorScheme,
} from 'react-native';

import type {FontStyle} from './types';
import type {FontStyle, ViewStyle} from './types';

type Props = $ReadOnly<{|
value: string | number | Object,
Expand All @@ -25,6 +25,7 @@ type Props = $ReadOnly<{|
enabled: boolean,
fontStyle?: FontStyle,
activeFontStyle?: FontStyle,
tabStyle?: ViewStyle,
appearance?: 'dark' | 'light' | null,
|}>;

Expand All @@ -42,6 +43,7 @@ export const SegmentedControlTab = ({
fontStyle = {},
activeFontStyle = {},
appearance,
tabStyle,
}: Props): React.Node => {
const colorSchemeHook = useColorScheme();
const colorScheme = appearance || colorSchemeHook;
Expand Down Expand Up @@ -82,11 +84,11 @@ export const SegmentedControlTab = ({

return (
<TouchableOpacity
style={styles.container}
style={[styles.container, tabStyle]}
disabled={!enabled}
onPress={onSelect}
accessibilityState={{selected: selected, disabled: !enabled}}>
<View style={[styles.default]}>
<View style={styles.default}>
{typeof value === 'number' || typeof value === 'object' ? (
<Image source={value} style={styles.segmentImage} />
) : isBase64(value) ? (
Expand Down
8 changes: 8 additions & 0 deletions js/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import type {ColorValue} from 'react-native/Libraries/StyleSheet/StyleSheetTypes';
import type {SyntheticEvent} from 'react-native/Libraries/Types/CoreEventTypes';
import type {ViewProps} from 'react-native/Libraries/Components/View/ViewPropTypes';
import type {ViewStyleProp} from 'react-native/Libraries/StyleSheet/StyleSheet';

export type Event = SyntheticEvent<
$ReadOnly<{|
Expand All @@ -13,6 +14,8 @@ export type Event = SyntheticEvent<
|}>,
>;

export type ViewStyle = ViewStyleProp;

export type FontStyle = $ReadOnly<{|
/**
* Font Color of Segmented Control
Expand Down Expand Up @@ -99,4 +102,9 @@ export type SegmentedControlProps = $ReadOnly<{|
* it will override fontStyle for the selected segment
*/
activeFontStyle?: FontStyle,

/**
* Touchable style properties for Segmented Control Tab
*/
tabStyle?: ViewStyle,
|}>;