Skip to content
Open
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
15 changes: 12 additions & 3 deletions src/SelectDropdown.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {forwardRef, useImperativeHandle} from 'react';
import {View, Text, TouchableOpacity, FlatList} from 'react-native';
import {View, Text, TouchableOpacity, FlatList, Platform} from 'react-native';
import styles from './styles';
import {isExist} from './helpers/isExist';
import {mergeStyles} from './helpers/mergeStyles';
Expand Down Expand Up @@ -59,7 +59,7 @@ const SelectDropdown = (
) => {
const disabledInternalSearch = !!onChangeSearchInputText;
/* ******************* hooks ******************* */
const {dropdownButtonRef, dropDownFlatlistRef} = useRefs();
const {dropdownButtonRef, dropDownFlatlistRef, dropdownSearchInputRef} = useRefs();
const {
dataArr, //
selectedItem,
Expand Down Expand Up @@ -122,11 +122,20 @@ const SelectDropdown = (
onSelect && onSelect(item, indexInOriginalArr);
selectItem(indexInOriginalArr);
};
const onShowModal = () => {
if (search && dropdownSearchInputRef.current !== null && Platform.OS === 'android') {
setTimeout(() => {
dropdownSearchInputRef.current.blur();
dropdownSearchInputRef.current.focus();
}, 100);
}
};
/* ******************** Render Methods ******************** */
const renderSearchView = () => {
return (
search && (
<Input
ref={dropdownSearchInputRef}
searchViewWidth={buttonLayout.w}
value={searchTxt}
valueColor={searchInputTxtColor}
Expand Down Expand Up @@ -171,7 +180,7 @@ const SelectDropdown = (
const renderDropdown = () => {
return (
isVisible && (
<DropdownModal statusBarTranslucent={statusBarTranslucent} visible={isVisible} onRequestClose={onRequestClose}>
<DropdownModal statusBarTranslucent={statusBarTranslucent} visible={isVisible} onRequestClose={onRequestClose} onShow={onShowModal}>
<DropdownOverlay onPress={closeDropdown} backgroundColor={dropdownOverlayColor} />
<DropdownWindow layoutStyle={dropdownWindowStyle}>
<FlatList
Expand Down
6 changes: 4 additions & 2 deletions src/components/DropdownModal.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import {Modal} from 'react-native';

const DropdownModal = ({visible, statusBarTranslucent, onRequestClose, children}) => {
const DropdownModal = ({visible, statusBarTranslucent, onRequestClose, onShow, children}) => {
const defaults = {
statusBarTranslucent: statusBarTranslucent || false,
};
Expand All @@ -12,7 +12,9 @@ const DropdownModal = ({visible, statusBarTranslucent, onRequestClose, children}
animationType="none"
transparent={true}
statusBarTranslucent={defaults.statusBarTranslucent}
visible={visible}>
visible={visible}
onShow={onShow}
>
{children}
</Modal>
);
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useRefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import {useRef} from 'react';
export const useRefs = () => {
const dropdownButtonRef = useRef(); // button ref to get positions
const dropDownFlatlistRef = useRef(null); // ref to the drop down flatlist
const dropdownSearchInputRef = useRef(null); // ref to the search input

return {
dropdownButtonRef,
dropDownFlatlistRef,
dropdownSearchInputRef,
};
};