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

docs: update deprecated usage of findNodeHandle in measureLayout #2199

Merged
merged 2 commits into from
Sep 6, 2020
Merged
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
63 changes: 58 additions & 5 deletions docs/direct-manipulation.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,67 @@ Determines the location of the given view in the window and returns the values v
- width
- height

### measureLayout(relativeToNativeNode, onSuccess, onFail)
### measureLayout(relativeToNativeComponentRef, onSuccess, onFail)

Like `measure()`, but measures the view relative to an ancestor, specified as `relativeToNativeNode`. This means that the returned x, y are relative to the origin x, y of the ancestor view.
Like `measure()`, but measures the view relative to an ancestor, specified with `relativeToNativeComponentRef` refrence. This means that the returned coordinates are relative to the origin `x`, `y` of the ancestor view.

As always, to obtain a native node handle for a component, you can use `findNodeHandle(component)`.
> Note: This method can also be called with a `relativeToNativeNode` handler (instead of reference), but this variant is deprecated.

```jsx
import { findNodeHandle } from 'react-native';
```SnackPlayer name=measureLayout%20example&supportedPlatforms=android,ios
import React, { useEffect, useRef, useState } from "react";
import { Text, View, StyleSheet } from "react-native";

const App = () => {
const textContainerRef = useRef(null);
const textRef = useRef(null);
const [measure, setMeasure] = useState(null);

useEffect(() => {
if (textRef.current && textContainerRef.current) {
textRef.current.measureLayout(
textContainerRef.current,
(left, top, width, height) => {
setMeasure({ left, top, width, height });
}
);
}
}, [measure]);

return (
<View style={styles.container}>
<View
ref={textContainerRef}
style={styles.textContainer}
>
<Text ref={textRef}>
Where am I? (relative to the text container)
</Text>
</View>
<Text style={styles.measure}>
{JSON.stringify(measure)}
</Text>
</View>
);
};

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
},
textContainer: {
backgroundColor: "#61dafb",
justifyContent: "center",
alignItems: "center",
padding: 12,
},
measure: {
textAlign: "center",
padding: 12,
},
});

export default App;
```

### focus()
Expand Down