Skip to content
Open
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
12 changes: 12 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ interface SegmentedControlProps {
* Badge Text Styles
*/
badgeTextStyle?: TextStyle;
/**
* Base Test ID of component to be used for testing
*/
testIDPrefix?: string
}

const defaultShadowStyle = {
Expand All @@ -95,6 +99,8 @@ const DEFAULT_SPRING_CONFIG = {
restDisplacementThreshold: 0.001,
};

const DEFAULT_TEST_PREFIX = 'segmented-control';

const SegmentedControl: React.FC<SegmentedControlProps> = ({
segments,
currentIndex,
Expand All @@ -110,6 +116,7 @@ const SegmentedControl: React.FC<SegmentedControlProps> = ({
activeBadgeStyle,
inactiveBadgeStyle,
badgeTextStyle,
testIDPrefix = DEFAULT_TEST_PREFIX,
}: SegmentedControlProps) => {
const width = widthPercentageToDP('100%') - containerMargin * 2;
const translateValue = width / segments.length;
Expand Down Expand Up @@ -179,9 +186,11 @@ const SegmentedControl: React.FC<SegmentedControlProps> = ({

return (
<Animated.View
testID={`${testIDPrefix}-container`}
style={[styles.defaultSegmentedControlWrapper, segmentedControlWrapper]}
>
<Animated.View
testID={`${testIDPrefix}-tile`}
style={[
styles.movingSegmentStyle,
defaultShadowStyle,
Expand All @@ -196,12 +205,14 @@ const SegmentedControl: React.FC<SegmentedControlProps> = ({
{segments.map((segment, index) => {
return (
<Pressable
testID={`${testIDPrefix}-segment-${index}`}
onPress={() => memoizedTabPressCallback(index)}
key={index}
style={[styles.touchableContainer, pressableWrapper]}
>
<View style={styles.textWrapper}>
<Text
testID={`${testIDPrefix}-segment-${index}-text`}
style={[
currentIndex === index
? finalisedActiveTextStyle
Expand All @@ -212,6 +223,7 @@ const SegmentedControl: React.FC<SegmentedControlProps> = ({
</Text>
{badgeValues[index] && (
<View
testID={`${testIDPrefix}-segment-${index}-badge`}
style={[
styles.defaultBadgeContainerStyle,
currentIndex === index
Expand Down