Docs for new DOM APIs#4783
Conversation
✅ Deploy Preview for react-native ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for react-native ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
9528808 to
55fe11c
Compare
| export default ViewWithRefs; | ||
| ``` | ||
|
|
||
| Note that some built-in components are only a container for other components (including native components). For example, `ScrollView` internally renders a native scroll view and a native view, which are accessible through the ref is provides using methods like `getNativeScrollRef()` and `getInnerViewRef()`. |
There was a problem hiding this comment.
which are accessible through the
refis provides using methods likegetNativeScrollRef()andgetInnerViewRef().
There is something wrong in this sentence
There was a problem hiding this comment.
through the
refit provides...
Will fix :)
|
|
||
| export default ViewWithRefs; | ||
| ``` | ||
|
|
There was a problem hiding this comment.
Can you put the box below inside an :::info box?
| - [`offsetWidth`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetWidth) | ||
| - Methods | ||
| - [`blur()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/blur). | ||
| - ℹ️ This method was also [available](/docs/next/legacy/direct-manipulation#blur) in the legacy architecture. |
There was a problem hiding this comment.
Not sure this is worth mentioning anymore
| - [Text](/docs/next/text-nodes): text nodes represent raw text content on the tree (similar to [`Text`](https://developer.mozilla.org/en-US/docs/Web/API/Text) nodes on Web). They are not directly accessible via `refs`, but can be accessed using methods like [`childNodes`](https://developer.mozilla.org/en-US/docs/Web/API/Node/childNodes) on element refs. | ||
| - [Documents](/docs/next/document-nodes): document nodes represent a complete native view tree (similar to [`Document`](https://developer.mozilla.org/en-US/docs/Web/API/Document) nodes on Web). Like text nodes, they can only be accessed through other nodes, using properties like [`ownerDocument`](https://developer.mozilla.org/en-US/docs/Web/API/Node/ownerDocument). | ||
|
|
||
| As on Web, these nodes can be used to traverse the rendered UI tree, access layout information or execute imperative operations like `focus`. **Unlike on Web, they do not allow mutation** (e.g.: [`node.appendChild`](https://developer.mozilla.org/en-US/docs/Web/API/Node/appendChild)), as the tree contents are fully managed by the React renderer. |
There was a problem hiding this comment.
Unlike on Web, they do not allow mutation
Can you put this in a separate line + add it in a admonition box (like a :::warning one or so)?
There was a problem hiding this comment.
Yeah, but will use info instead of warning. We're already explaining the methods we support, and none of the mutating ones are even defined.
8eb45e8 to
2db9536
Compare
2db9536 to
94c9fca
Compare
cortinico
left a comment
There was a problem hiding this comment.
LGTM. Left a couple of comments
| ### Legacy API | ||
|
|
||
| - [`measure()`](/docs/next/legacy/direct-manipulation#measurecallback) | ||
| - [`measureInWindow()`](/docs/next/legacy/direct-manipulation#measureinwindowcallback) | ||
| - [`measureLayout()`](/docs/next/legacy/direct-manipulation#measurelayoutrelativetonativecomponentref-onsuccess-onfail) | ||
| - [`setNativeProps()`](/docs/next/legacy/direct-manipulation#setnativeprops-with-touchableopacity) |
There was a problem hiding this comment.
Should those be removed altogether?
There was a problem hiding this comment.
Not if you want to keep backwards compatibility.
|
|
||
| --- | ||
|
|
||
| ### `modalRef` |
There was a problem hiding this comment.
Why is this called modalRef and not ref as all the others?
There was a problem hiding this comment.
I saw that as the name of the prop in the component, but I checked again and it's exposed as both. Will keep ref instead.
94c9fca to
d4cee9f
Compare
|
|
||
| return ( | ||
| <View ref={instance => { | ||
| if (instance != null) { |
There was a problem hiding this comment.
Can we use callback refs with a cleanup instead of the legacy null check?
| style={styles.content} | ||
| ref={(instance) => { | ||
| // `instance` is an object implementing the interface described here, | ||
| // or `null` when the component is unmounted. |
There was a problem hiding this comment.
Same here: return a cleanup instead (and all the docs, won't comment each one).
|
|
||
| As on Web, these nodes can be used to traverse the rendered UI tree, access layout information or execute imperative operations like `focus`. | ||
|
|
||
| :::info |
|
|
||
| ### `ref` | ||
|
|
||
| A ref setter that will be assigned an [element node](element-nodes) when mounted. |
There was a problem hiding this comment.
Is this an element node or should it be a text node?
There was a problem hiding this comment.
It's an element node. This would be equivalent to a paragraph node on Web, not to its underlying text node.
I can clarify that in the docs.
rickhanlonii
left a comment
There was a problem hiding this comment.
LGTM, left some notes
This adds the initial documentation for the new Web DOM APIs in React Native, that will be shipped as stable in React Native v0.82.