Skip to content

Commit 9816cdc

Browse files
fix: incorrect dropdown positioning (#248)
* feat: searchable select with default option (changeset) * fix: incorrect dropdown positioning * fix: incorrect dropdown positioning --------- Co-authored-by: Dawid Gierdal <dawid.gierdal@mobilereality.pl>
1 parent 4d8ea28 commit 9816cdc

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

.changeset/red-donkeys-whisper.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@mobile-reality/react-native-select-pro': patch
3+
---
4+
5+
searchable select with default option
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@mobile-reality/react-native-select-pro': patch
3+
---
4+
5+
fix incorrect dropdown positioning

packages/react-native-select-pro/src/components/select-input/select-input.hooks.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ export const useSelectInput = () => {
3434
const hideSubscription = Keyboard.addListener('keyboardDidHide', async () => {
3535
await setOptionsListPosition();
3636
});
37+
3738
dispatch({
3839
type: 'setSearchInputRef',
3940
payload: searchInputRef,
4041
});
42+
4143
return () => {
4244
showSubscription.remove();
4345
hideSubscription.remove();

packages/react-native-select-pro/src/components/select/select.hooks.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,15 @@ export const useSelect = <T>({
7272
});
7373
};
7474

75-
const setOptionsListPosition = async () => {
75+
const calculateOptionsListPosition = async (): Promise<void> => {
7676
const { x, y, width, height } = await measureSelectInWindow();
7777
const { height: optionsListHeight } = await measureOptionsListInWindow();
78+
7879
const isOverflow = y + height + optionsListHeight > screenHeight;
7980
const top = isOverflow
8081
? y - optionsListHeight + APPROX_STATUSBAR_HEIGHT
8182
: y + height - valueY + APPROX_STATUSBAR_HEIGHT;
83+
8284
const left = I18nManager.getConstants().isRTL ? screenWidth - width - x : x;
8385

8486
dispatch({
@@ -92,6 +94,16 @@ export const useSelect = <T>({
9294
});
9395
};
9496

97+
const setOptionsListPosition = async () => {
98+
await calculateOptionsListPosition();
99+
// Callback events are sometimes called too early,
100+
// before the height value changes, so we need to
101+
// make sure that this function will be called at the end of the event loop
102+
setTimeout(async () => {
103+
await calculateOptionsListPosition();
104+
}, 10);
105+
};
106+
95107
const onPressSelectControl: OnPressSelectControlType = async () => {
96108
if (disabled) {
97109
return;

0 commit comments

Comments
 (0)