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
23 changes: 11 additions & 12 deletions src/SegmentedControl/SegmentedControl.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import React, { createContext, useState, useEffect } from 'react';
import { LayoutChangeEvent, StyleProp, View, ViewStyle } from 'react-native';
import React, { createContext, useEffect, useState } from 'react';
import { LayoutChangeEvent, View, ViewStyle } from 'react-native';
import { PanGestureHandler, PanGestureHandlerGestureEvent } from 'react-native-gesture-handler';
import Animated, { Easing } from 'react-native-reanimated';
import { timing } from 'react-native-redash';
import {
PanGestureHandler,
PanGestureHandlerGestureEvent,
} from 'react-native-gesture-handler';

import { Segment, SegmentProps } from '../Segment';
import { clamp } from '../utils';
import styles from './SegmentedControlStyles';
Expand All @@ -18,7 +16,8 @@ export interface SegmentedControlProps {
| React.ReactElement<SegmentProps>
| React.ReactElement<SegmentProps>[];
onChangeValue?: (name: string) => void;
style?: StyleProp<ViewStyle>;
sliderStyle?: ViewStyle;
style?: ViewStyle;
}

export const SegmentedContext = createContext<{
Expand All @@ -32,6 +31,7 @@ export const SegmentedControl = ({
inactiveTintColor = '#000000',
initialSelectedName,
onChangeValue,
sliderStyle,
style,
}: SegmentedControlProps): JSX.Element => {
const [_initialized, _setInitialized] = useState(false);
Expand Down Expand Up @@ -133,15 +133,12 @@ export const SegmentedControl = ({
value={{ selectedName: _activeName, onChange: handleChangeValue }}
>
<PanGestureHandler onGestureEvent={handleGestureEvent}>
<View
onLayout={handleLayout}
style={[styles.container, style as ViewStyle]}
>
<View onLayout={handleLayout} style={[styles.container, style]}>
{typeof _activeName !== 'undefined' && (
<Animated.View
testID="SegmentedControl_Slider"
style={[
styles.slider,
styles.sliderDefault,
{
width: _sliderWidth,
transform: [
Expand All @@ -150,6 +147,8 @@ export const SegmentedControl = ({
},
],
},
sliderStyle,
styles.slider,
]}
/>
)}
Expand Down
4 changes: 3 additions & 1 deletion src/SegmentedControl/SegmentedControlStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const styles = StyleSheet.create({
position: 'absolute',
top: 0,
left: 0,
zIndex: 1,
},
sliderDefault: {
height: '86%',
backgroundColor: 'white',
borderRadius: 7,
Expand All @@ -21,7 +24,6 @@ const styles = StyleSheet.create({
shadowColor: '#a2a2a2',
shadowOpacity: 0.5,
shadowRadius: 2,
zIndex: 1,
},
dividerContainer: {
paddingTop: 7,
Expand Down