Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

measureInWindow doesn't work properly for multiple similar mounted components #2589

Closed
1 task done
gentlee opened this issue Oct 5, 2023 · 2 comments
Closed
1 task done
Labels

Comments

@gentlee
Copy link

gentlee commented Oct 5, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Describe the issue

After upgrading from 0.18.4 to 0.19.8 version (and tried other 0.19.x with same result), measureInWindow returns the same result for all similar mounted components.

In out case the modal is rendered in the same position for all dropdowns - at the most top dropdown.

Here on the screenshot the focused combobox was clicked, but modal appeared at the first one.

Screenshot 2023-10-05 at 18 59 13

On 0.18.4 version it works.

Expected behavior

measureInWindow works properly.

Steps to reproduce

Use this code to measure coordinates:

comboboxRef.current?.measureInWindow((x, y, width, height) => {
 ...
})

and mount several similar components at once on the page. The result will be the same for all of them.

Test case

wil provide later if needed

Additional comments

No response

@gentlee gentlee added the bug label Oct 5, 2023
@gentlee
Copy link
Author

gentlee commented Oct 5, 2023

For now workaround is using html element ref for web, provided by findNodeHandle:

measureComboboxLayout: (
  callback: (x: number, y: number, width: number, height: number) => void
) => {
  if (!comboboxHtmlRef.current) {
    return
  }
  const rect = comboboxHtmlRef.current.getBoundingClientRect()
  callback(rect.left, rect.top, rect.width, rect.height)
}

@dummy-1111
Copy link
Contributor

This issue is reproducible for the inverted FlatList

You can try the following code. Without inverted, it looks like working but doesn't work with inverted=true

import React from "react";
import { FlatList, Pressable, StyleSheet, Text, View } from "react-native";

const DATA = [
  {
    id: 'bd7acbea-c1b1-46c2-aed5-3ad53abb28ba',
    title: 'First Item',
  },
  {
    id: '3ac68afc-c605-48d3-a4f8-fbd91aa97f63',
    title: 'Second Item',
  },
];
const Item = ({title}) => {
  const ref = React.useRef(null);
  const [pos, setPos] = React.useState(0);
  const onPress = () => {
    if (ref.current) {
      ref.current.measureInWindow((x,y,w,h) => {
        setPos(y);
      });
    }
  };
  return (
    <Pressable style={styles.item} onPress={onPress} ref={ref}>
      <Text style={styles.title}>{title}: {pos}</Text>
    </Pressable>
  )
};

function App() {
  return (
    <View style={styles.app}>
      <FlatList
        data={DATA}
        renderItem={({item}) => <Item title={item.title} />}
        keyExtractor={item => item.id}
        inverted
      />
    </View>
  );
}

const styles = StyleSheet.create({
  app: {
    marginHorizontal: "auto",
    padding: 16,
    maxWidth: 500
  },
  item: {
    backgroundColor: '#f9c2ff',
    padding: 20,
    marginVertical: 8,
    marginHorizontal: 16,
  },
  title: {
    fontSize: 32,
  },
});

export default App;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants