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
39 changes: 25 additions & 14 deletions src/components/Dropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import {
Keyboard,
KeyboardEvent,
Modal,
StatusBar,
StyleSheet,
Text,
TouchableHighlight,
TouchableWithoutFeedback,
View,
ViewStyle,
StatusBar,
} from 'react-native';
import { useDetectDevice } from '../../toolkits';
import { useDeviceOrientation } from '../../useDeviceOrientation';
Expand Down Expand Up @@ -225,22 +225,22 @@ const DropdownComponent: <T>(
}, [_measure]);

useEffect(() => {
const susbcriptionKeyboardDidShow = Keyboard.addListener(
const subscriptionKeyboardDidShow = Keyboard.addListener(
'keyboardDidShow',
onKeyboardDidShow
);
const susbcriptionKeyboardDidHide = Keyboard.addListener(
const subscriptionKeyboardDidHide = Keyboard.addListener(
'keyboardDidHide',
onKeyboardDidHide
);

return () => {
if (typeof susbcriptionKeyboardDidShow?.remove === 'function') {
susbcriptionKeyboardDidShow.remove();
if (typeof subscriptionKeyboardDidShow?.remove === 'function') {
subscriptionKeyboardDidShow.remove();
}

if (typeof susbcriptionKeyboardDidHide?.remove === 'function') {
susbcriptionKeyboardDidHide.remove();
if (typeof subscriptionKeyboardDidHide?.remove === 'function') {
subscriptionKeyboardDidHide.remove();
}
};
}, [onKeyboardDidHide, onKeyboardDidShow]);
Expand All @@ -265,24 +265,35 @@ const DropdownComponent: <T>(
}, [value, data, getValue]);

const scrollIndex = useCallback(() => {
if (autoScroll && data.length > 0 && listData.length === data.length) {
if (autoScroll && data.length > 0 && listData?.length === data?.length) {
setTimeout(() => {
if (refList && refList?.current) {
const defaultValue =
typeof value === 'object' ? _.get(value, valueField) : value;

const index = _.findIndex(listData, (e: any) =>
const index = _.findIndex(listData, (e) =>
_.isEqual(defaultValue, _.get(e, valueField))
);

if (
listData.length > 0 &&
index > -1 &&
!_.isEmpty(listData.length) &&
index <= listData.length - 1
) {
refList?.current?.scrollToIndex({
index: index,
animated: false,
});
try {
refList.current.scrollToIndex({
index: index,
animated: false,
});
} catch (error) {
console.warn(`scrollToIndex error: ${error}`);
}
} else {
console.warn(
`scrollToIndex out of range: requested index ${index} is out of 0 to ${
listData.length - 1
}`
);
}
}
}, 200);
Expand Down