Skip to content

Commit 3a1e4bd

Browse files
authored
SegmentedControl - initialIndex update (#2963)
1 parent 76dbe27 commit 3a1e4bd

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/components/segmentedControl/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import _ from 'lodash';
2-
import React, {useRef, useCallback} from 'react';
2+
import React, {useRef, useCallback, useEffect} from 'react';
33
import {StyleSheet, StyleProp, ViewStyle, TextStyle, LayoutChangeEvent} from 'react-native';
44
import Reanimated, {
55
Easing,
@@ -114,6 +114,10 @@ const SegmentedControl = (props: SegmentedControlProps) => {
114114
const segmentedControlHeight = useSharedValue(0);
115115
const segmentsCounter = useRef(0);
116116

117+
useEffect(() => {
118+
animatedSelectedIndex.value = initialIndex;
119+
}, [initialIndex, animatedSelectedIndex]);
120+
117121
// eslint-disable-next-line react-hooks/exhaustive-deps
118122
const changeIndex = useCallback(_.throttle(() => {
119123
onChangeIndex?.(animatedSelectedIndex.value);

0 commit comments

Comments
 (0)