Skip to content

Commit 54dc3a0

Browse files
authored
fix uncontrolled mode (#1583)
1 parent 1894428 commit 54dc3a0

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

demo/src/screens/componentScreens/SectionsWheelPickerScreen.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,23 @@ const SectionsWheelPickerScreen = () => {
6464
{
6565
items: getItems(days),
6666
onChange: onDaysChange,
67-
selectedValue: selectedDays,
67+
initialValue: selectedDays,
6868
label: 'Days',
6969
align: numOfSections === 1 ? WheelPicker.alignments.CENTER : WheelPicker.alignments.RIGHT,
7070
style: {flex: 1}
7171
},
7272
{
7373
items: getItems(hours),
7474
onChange: onHoursChange,
75-
selectedValue: selectedHours,
75+
initialValue: selectedHours,
7676
label: 'Hrs',
7777
align: numOfSections === 2 ? WheelPicker.alignments.LEFT : WheelPicker.alignments.CENTER,
7878
style: numOfSections === 2 ? {flex: 1} : undefined
7979
},
8080
{
8181
items: getItems(minutes),
8282
onChange: onMinutesChange,
83-
selectedValue: selectedMinutes,
83+
initialValue: selectedMinutes,
8484
label: 'Mins',
8585
align: WheelPicker.alignments.LEFT,
8686
style: {flex: 1}

src/incubator/WheelPicker/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// TODO: Support style customization
2-
import {isFunction} from 'lodash';
2+
import {isFunction, isUndefined} from 'lodash';
33
import React, {useCallback, useRef, useMemo, useEffect, useState} from 'react';
44
import {TextStyle, ViewStyle, FlatList, NativeSyntheticEvent, NativeScrollEvent, StyleSheet} from 'react-native';
55
import Animated, {useSharedValue, useAnimatedScrollHandler} from 'react-native-reanimated';
@@ -139,7 +139,7 @@ const WheelPicker = ({
139139

140140
/* This effect making sure to reset index if initialValue has changed */
141141
useEffect(() => {
142-
scrollToIndex(currentIndex, true);
142+
!isUndefined(initialValue) && scrollToIndex(currentIndex, true);
143143
}, [currentIndex]);
144144

145145
const scrollToPassedIndex = useCallback(() => {

0 commit comments

Comments
 (0)