Skip to content

Commit 7df36a4

Browse files
authored
Merge pull request #147 from onmotion/fix/measurement-inside-modal
fix: measurement inside ios modal
2 parents 46c1f51 + b68539f commit 7df36a4

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

example/components/RemoteDataSetExample.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const RemoteDataSetExample = memo((props: Omit<IAutocompleteDropdownProps
4343
useFilter={false}
4444
clearOnFocus={false}
4545
textInputProps={{
46-
placeholder: 'Start typing "est"...',
46+
placeholder: 'Start typing "lorem"...',
4747
}}
4848
onSelectItem={setSelectedItem}
4949
loading={loading}

src/AutocompleteDropdownContext.tsx

+11-5
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const AutocompleteDropdownContextProvider: FC<IAutocompleteDropdownContex
4545
undefined,
4646
)
4747
const activeInputContainerRef = useRef<View>(null)
48+
const wrapperRef = useRef<View>(null)
4849
const activeControllerRef = useRef<IAutocompleteDropdownRef | null>(null)
4950
const controllerRefs = useRef<IAutocompleteDropdownRef[]>([])
5051
const positionTrackingIntervalRef = useRef<NodeJS.Timeout>()
@@ -83,8 +84,10 @@ export const AutocompleteDropdownContextProvider: FC<IAutocompleteDropdownContex
8384
useEffect(() => {
8485
if (content) {
8586
activeInputContainerRef?.current?.measure((x, y, width, height, pageX, pageY) => {
86-
setInputMeasurements({ x: pageX, y: pageY, width, height })
87-
setShow(true)
87+
wrapperRef.current?.measure((wrapperX, wrapperY, wrapperW, wrapperH, wrapperPageX, wrapperPageY) => {
88+
setInputMeasurements({ x: pageX, y: pageY - wrapperPageY, width, height })
89+
setShow(true)
90+
})
8891
})
8992
} else {
9093
setInputMeasurements(undefined)
@@ -99,12 +102,14 @@ export const AutocompleteDropdownContextProvider: FC<IAutocompleteDropdownContex
99102
if (show && !!opacity) {
100103
positionTrackingIntervalRef.current = setInterval(() => {
101104
requestAnimationFrame(() => {
102-
activeInputContainerRef?.current &&
103-
activeInputContainerRef?.current?.measure((_x, _y, width, height, x, y) => {
105+
activeInputContainerRef?.current?.measure((_x, _y, width, height, inputPageX, inputPageY) => {
106+
wrapperRef.current?.measure((wrapperX, wrapperY, wrapperW, wrapperH, wrapperPageX, wrapperPageY) => {
107+
const currentMeasurement = { x: inputPageX, y: inputPageY - wrapperPageY, width, height }
104108
setInputMeasurements(prev =>
105-
JSON.stringify(prev) === JSON.stringify({ x, y, width, height }) ? prev : { x, y, width, height },
109+
JSON.stringify(prev) === JSON.stringify(currentMeasurement) ? prev : currentMeasurement,
106110
)
107111
})
112+
})
108113
})
109114
}, 16)
110115
} else {
@@ -132,6 +137,7 @@ export const AutocompleteDropdownContextProvider: FC<IAutocompleteDropdownContex
132137
controllerRefs,
133138
}}>
134139
<View
140+
ref={wrapperRef}
135141
style={styles.clickOutsideHandlerArea}
136142
onTouchEnd={() => {
137143
activeControllerRef.current?.close()

src/index.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,7 @@ export const AutocompleteDropdown = memo<
123123
return new Promise<void>(resolve => {
124124
setTimeout(
125125
() => {
126-
Keyboard.isVisible()
127126
const kbHeight = Keyboard.metrics()?.height || 0
128-
console.log({ kbHeight })
129127
const screenHeight = Dimensions.get('window').height
130128
setDirection((screenHeight - kbHeight) / 2 > positionY ? 'down' : 'up')
131129
resolve()

0 commit comments

Comments
 (0)