mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Deploy website
Deploy website version based on becc1ad1560878dea23a806e8d0ba44c20dc66dc
This commit is contained in:
@@ -248,16 +248,85 @@
|
||||
<li>width</li>
|
||||
<li>height</li>
|
||||
</ul>
|
||||
<h3><a class="anchor" aria-hidden="true" id="measurelayoutrelativetonativenode-onsuccess-onfail"></a><a href="#measurelayoutrelativetonativenode-onsuccess-onfail" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>measureLayout(relativeToNativeNode, onSuccess, onFail)</h3>
|
||||
<p>Like <code>measure()</code>, but measures the view relative to an ancestor, specified as <code>relativeToNativeNode</code>. This means that the returned x, y are relative to the origin x, y of the ancestor view.</p>
|
||||
<p>As always, to obtain a native node handle for a component, you can use <code>findNodeHandle(component)</code>.</p>
|
||||
<pre><code class="hljs css language-jsx"><span class="token keyword">import</span> <span class="token punctuation">{</span> findNodeHandle <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'react-native'</span><span class="token punctuation">;</span>
|
||||
</code></pre>
|
||||
<h3><a class="anchor" aria-hidden="true" id="focus"></a><a href="#focus" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>focus()</h3>
|
||||
<h3><a class="anchor" aria-hidden="true" id="measurelayoutrelativetonativecomponentref-onsuccess-onfail"></a><a href="#measurelayoutrelativetonativecomponentref-onsuccess-onfail" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>measureLayout(relativeToNativeComponentRef, onSuccess, onFail)</h3>
|
||||
<p>Like <code>measure()</code>, but measures the view relative to an ancestor, specified with <code>relativeToNativeComponentRef</code> refrence. This means that the returned coordinates are relative to the origin <code>x</code>, <code>y</code> of the ancestor view.</p>
|
||||
<blockquote>
|
||||
<p>Note: This method can also be called with a <code>relativeToNativeNode</code> handler (instead of reference), but this variant is deprecated.</p>
|
||||
</blockquote>
|
||||
<div class="snack-player"><div class="mobile-friendly-snack" style="display: none"><pre><code class="hljs css javascript"><span class="hljs-keyword">import</span> React, { useEffect, useRef, useState } <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;
|
||||
<span class="hljs-keyword">import</span> { Text, View, StyleSheet } <span class="hljs-keyword">from</span> <span class="hljs-string">"react-native"</span>;
|
||||
|
||||
<span class="hljs-keyword">const</span> App = <span class="hljs-function">() =></span> {
|
||||
<span class="hljs-keyword">const</span> textContainerRef = useRef(<span class="hljs-literal">null</span>);
|
||||
<span class="hljs-keyword">const</span> textRef = useRef(<span class="hljs-literal">null</span>);
|
||||
<span class="hljs-keyword">const</span> [measure, setMeasure] = useState(<span class="hljs-literal">null</span>);
|
||||
|
||||
useEffect(<span class="hljs-function">() =></span> {
|
||||
<span class="hljs-keyword">if</span> (textRef.current && textContainerRef.current) {
|
||||
textRef.current.measureLayout(
|
||||
textContainerRef.current,
|
||||
<span class="hljs-function">(<span class="hljs-params">left, top, width, height</span>) =></span> {
|
||||
setMeasure({ left, top, width, height });
|
||||
}
|
||||
);
|
||||
}
|
||||
}, [measure]);
|
||||
|
||||
<span class="hljs-keyword">return</span> (
|
||||
<span class="xml"><span class="hljs-tag"><<span class="hljs-name">View</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{styles.container}</span>></span>
|
||||
<span class="hljs-tag"><<span class="hljs-name">View</span>
|
||||
<span class="hljs-attr">ref</span>=<span class="hljs-string">{textContainerRef}</span>
|
||||
<span class="hljs-attr">style</span>=<span class="hljs-string">{styles.textContainer}</span>
|
||||
></span>
|
||||
<span class="hljs-tag"><<span class="hljs-name">Text</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">{textRef}</span>></span>
|
||||
Where am I? (relative to the text container)
|
||||
<span class="hljs-tag"></<span class="hljs-name">Text</span>></span>
|
||||
<span class="hljs-tag"></<span class="hljs-name">View</span>></span>
|
||||
<span class="hljs-tag"><<span class="hljs-name">Text</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{styles.measure}</span>></span>
|
||||
{JSON.stringify(measure)}
|
||||
<span class="hljs-tag"></<span class="hljs-name">Text</span>></span>
|
||||
<span class="hljs-tag"></<span class="hljs-name">View</span>></span></span>
|
||||
);
|
||||
};
|
||||
|
||||
<span class="hljs-keyword">const</span> styles = StyleSheet.create({
|
||||
<span class="hljs-attr">container</span>: {
|
||||
<span class="hljs-attr">flex</span>: <span class="hljs-number">1</span>,
|
||||
<span class="hljs-attr">justifyContent</span>: <span class="hljs-string">"center"</span>,
|
||||
},
|
||||
<span class="hljs-attr">textContainer</span>: {
|
||||
<span class="hljs-attr">backgroundColor</span>: <span class="hljs-string">"#61dafb"</span>,
|
||||
<span class="hljs-attr">justifyContent</span>: <span class="hljs-string">"center"</span>,
|
||||
<span class="hljs-attr">alignItems</span>: <span class="hljs-string">"center"</span>,
|
||||
<span class="hljs-attr">padding</span>: <span class="hljs-number">12</span>,
|
||||
},
|
||||
<span class="hljs-attr">measure</span>: {
|
||||
<span class="hljs-attr">textAlign</span>: <span class="hljs-string">"center"</span>,
|
||||
<span class="hljs-attr">padding</span>: <span class="hljs-number">12</span>,
|
||||
},
|
||||
});
|
||||
|
||||
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> App;
|
||||
</code></pre></div><div class="desktop-friendly-snack" style="margin-top: 15px; margin-bottom: 15px"><div
|
||||
data-snack-name="measureLayout example"
|
||||
data-snack-description="Example usage"
|
||||
data-snack-code="import%20React%2C%20%7B%20useEffect%2C%20useRef%2C%20useState%20%7D%20from%20%22react%22%3B%0Aimport%20%7B%20Text%2C%20View%2C%20StyleSheet%20%7D%20from%20%22react-native%22%3B%0A%0Aconst%20App%20%3D%20()%20%3D%3E%20%7B%0A%20%20const%20textContainerRef%20%3D%20useRef(null)%3B%0A%20%20const%20textRef%20%3D%20useRef(null)%3B%0A%20%20const%20%5Bmeasure%2C%20setMeasure%5D%20%3D%20useState(null)%3B%0A%0A%20%20useEffect(()%20%3D%3E%20%7B%0A%20%20%20%20if%20(textRef.current%20%26%26%20textContainerRef.current)%20%7B%0A%20%20%20%20%20%20textRef.current.measureLayout(%0A%20%20%20%20%20%20%20%20textContainerRef.current%2C%0A%20%20%20%20%20%20%20%20(left%2C%20top%2C%20width%2C%20height)%20%3D%3E%20%7B%0A%20%20%20%20%20%20%20%20%20%20setMeasure(%7B%20left%2C%20top%2C%20width%2C%20height%20%7D)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20)%3B%0A%20%20%20%20%7D%0A%20%20%7D%2C%20%5Bmeasure%5D)%3B%0A%0A%20%20return%20(%0A%20%20%20%20%3CView%20style%3D%7Bstyles.container%7D%3E%0A%20%20%20%20%20%20%3CView%0A%20%20%20%20%20%20%20%20ref%3D%7BtextContainerRef%7D%0A%20%20%20%20%20%20%20%20style%3D%7Bstyles.textContainer%7D%0A%20%20%20%20%20%20%3E%0A%20%20%20%20%20%20%20%20%3CText%20ref%3D%7BtextRef%7D%3E%0A%20%20%20%20%20%20%20%20%20%20Where%20am%20I%3F%20(relative%20to%20the%20text%20container)%0A%20%20%20%20%20%20%20%20%3C%2FText%3E%0A%20%20%20%20%20%20%3C%2FView%3E%0A%20%20%20%20%20%20%3CText%20style%3D%7Bstyles.measure%7D%3E%0A%20%20%20%20%20%20%20%20%7BJSON.stringify(measure)%7D%0A%20%20%20%20%20%20%3C%2FText%3E%0A%20%20%20%20%3C%2FView%3E%0A%20%20)%3B%0A%7D%3B%0A%0Aconst%20styles%20%3D%20StyleSheet.create(%7B%0A%20%20container%3A%20%7B%0A%20%20%20%20flex%3A%201%2C%0A%20%20%20%20justifyContent%3A%20%22center%22%2C%0A%20%20%7D%2C%0A%20%20textContainer%3A%20%7B%0A%20%20%20%20backgroundColor%3A%20%22%2361dafb%22%2C%0A%20%20%20%20justifyContent%3A%20%22center%22%2C%0A%20%20%20%20alignItems%3A%20%22center%22%2C%0A%20%20%20%20padding%3A%2012%2C%0A%20%20%7D%2C%0A%20%20measure%3A%20%7B%0A%20%20%20%20textAlign%3A%20%22center%22%2C%0A%20%20%20%20padding%3A%2012%2C%0A%20%20%7D%2C%0A%7D)%3B%0A%0Aexport%20default%20App%3B%0A"
|
||||
data-snack-platform="web"
|
||||
data-snack-supported-platforms=android,ios
|
||||
data-snack-preview="true"
|
||||
style="
|
||||
overflow: hidden;
|
||||
background: #fafafa;
|
||||
border: 1px solid rgba(0,0,0,.16);
|
||||
border-radius: 4px;
|
||||
height: 514px;
|
||||
width: 100%;
|
||||
"
|
||||
></div></div></div><h3><a class="anchor" aria-hidden="true" id="focus"></a><a href="#focus" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>focus()</h3>
|
||||
<p>Requests focus for the given input or view. The exact behavior triggered will depend on the platform and type of view.</p>
|
||||
<h3><a class="anchor" aria-hidden="true" id="blur"></a><a href="#blur" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>blur()</h3>
|
||||
<p>Removes focus from an input or view. This is the opposite of <code>focus()</code>.</p>
|
||||
</span></div></article></div><div class="docs-prevnext"><a class="docs-prev button" href="/docs/next/native-modules-setup"><span class="arrow-prev">← </span><span>Native Modules Setup</span></a><a class="docs-next button" href="/docs/next/native-modules-android"><span>Native Modules</span><span class="arrow-next"> →</span></a></div></div></div><nav class="onPageNav"><ul class="toc-headings"><li><a href="#setnativeprops-with-touchableopacity">setNativeProps with TouchableOpacity</a></li><li><a href="#composite-components-and-setnativeprops">Composite components and setNativeProps</a></li><li><a href="#setnativeprops-to-clear-textinput-value">setNativeProps to clear TextInput value</a></li><li><a href="#avoiding-conflicts-with-the-render-function">Avoiding conflicts with the render function</a></li><li><a href="#setnativeprops--shouldcomponentupdate">setNativeProps & shouldComponentUpdate</a></li><li><a href="#other-native-methods">Other native methods</a><ul class="toc-headings"><li><a href="#measurecallback">measure(callback)</a></li><li><a href="#measureinwindowcallback">measureInWindow(callback)</a></li><li><a href="#measurelayoutrelativetonativenode-onsuccess-onfail">measureLayout(relativeToNativeNode, onSuccess, onFail)</a></li><li><a href="#focus">focus()</a></li><li><a href="#blur">blur()</a></li></ul></li></ul></nav></div><footer class="nav-footer" id="footer"><section class="sitemap"><div><h5>Docs</h5><a href="/docs/getting-started">Getting Started</a><a href="/docs/tutorial">Tutorial</a><a href="/docs/components-and-apis">Components and APIs</a><a href="/docs/more-resources">More Resources</a></div><div><h5>Community</h5><a href="/help">The React Native Community</a><a href="/showcase">Who's using React Native?</a><a href="https://stackoverflow.com/questions/tagged/react-native" target="_blank">Ask Questions on Stack Overflow</a><a href="https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md">Contributor Guide</a><a href="https://dev.to/t/reactnative" target="_blank">DEV Community</a></div><div><h5>More Resources</h5><a href="/blog">Blog</a><a href="https://twitter.com/reactnative" target="_blank">Twitter</a><a href="https://github.com/facebook/react-native" target="_blank">GitHub</a><a href="https://reactjs.org" target="_blank">React</a></div></section><a href="https://code.facebook.com/projects/" target="_blank" class="fbOpenSource"><img src="/img/oss_logo.png" alt="Facebook Open Source" width="170" height="45"/></a><section class="copyright">Copyright © 2020 Facebook Inc.</section></footer></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js"></script><script>window.fbAsyncInit = function() {FB.init({appId:'1677033832619985',xfbml:true,version:'v2.7'});};(function(d, s, id){var js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) {return;}js = d.createElement(s); js.id = id;js.src = '//connect.facebook.net/en_US/sdk.js';fjs.parentNode.insertBefore(js, fjs);}(document, 'script','facebook-jssdk'));
|
||||
</span></div></article></div><div class="docs-prevnext"><a class="docs-prev button" href="/docs/next/native-modules-setup"><span class="arrow-prev">← </span><span>Native Modules Setup</span></a><a class="docs-next button" href="/docs/next/native-modules-android"><span>Native Modules</span><span class="arrow-next"> →</span></a></div></div></div><nav class="onPageNav"><ul class="toc-headings"><li><a href="#setnativeprops-with-touchableopacity">setNativeProps with TouchableOpacity</a></li><li><a href="#composite-components-and-setnativeprops">Composite components and setNativeProps</a></li><li><a href="#setnativeprops-to-clear-textinput-value">setNativeProps to clear TextInput value</a></li><li><a href="#avoiding-conflicts-with-the-render-function">Avoiding conflicts with the render function</a></li><li><a href="#setnativeprops--shouldcomponentupdate">setNativeProps & shouldComponentUpdate</a></li><li><a href="#other-native-methods">Other native methods</a><ul class="toc-headings"><li><a href="#measurecallback">measure(callback)</a></li><li><a href="#measureinwindowcallback">measureInWindow(callback)</a></li><li><a href="#measurelayoutrelativetonativecomponentref-onsuccess-onfail">measureLayout(relativeToNativeComponentRef, onSuccess, onFail)</a></li><li><a href="#focus">focus()</a></li><li><a href="#blur">blur()</a></li></ul></li></ul></nav></div><footer class="nav-footer" id="footer"><section class="sitemap"><div><h5>Docs</h5><a href="/docs/getting-started">Getting Started</a><a href="/docs/tutorial">Tutorial</a><a href="/docs/components-and-apis">Components and APIs</a><a href="/docs/more-resources">More Resources</a></div><div><h5>Community</h5><a href="/help">The React Native Community</a><a href="/showcase">Who's using React Native?</a><a href="https://stackoverflow.com/questions/tagged/react-native" target="_blank">Ask Questions on Stack Overflow</a><a href="https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md">Contributor Guide</a><a href="https://dev.to/t/reactnative" target="_blank">DEV Community</a></div><div><h5>More Resources</h5><a href="/blog">Blog</a><a href="https://twitter.com/reactnative" target="_blank">Twitter</a><a href="https://github.com/facebook/react-native" target="_blank">GitHub</a><a href="https://reactjs.org" target="_blank">React</a></div></section><a href="https://code.facebook.com/projects/" target="_blank" class="fbOpenSource"><img src="/img/oss_logo.png" alt="Facebook Open Source" width="170" height="45"/></a><section class="copyright">Copyright © 2020 Facebook Inc.</section></footer></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js"></script><script>window.fbAsyncInit = function() {FB.init({appId:'1677033832619985',xfbml:true,version:'v2.7'});};(function(d, s, id){var js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) {return;}js = d.createElement(s); js.id = id;js.src = '//connect.facebook.net/en_US/sdk.js';fjs.parentNode.insertBefore(js, fjs);}(document, 'script','facebook-jssdk'));
|
||||
</script><script>window.twttr=(function(d,s, id){var js,fjs=d.getElementsByTagName(s)[0],t=window.twttr||{};if(d.getElementById(id))return t;js=d.createElement(s);js.id=id;js.src='https://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js, fjs);t._e = [];t.ready = function(f) {t._e.push(f);};return t;}(document, 'script', 'twitter-wjs'));</script><script>
|
||||
document.addEventListener('keyup', function(e) {
|
||||
if (e.target !== document.body) {
|
||||
|
||||
@@ -248,16 +248,85 @@
|
||||
<li>width</li>
|
||||
<li>height</li>
|
||||
</ul>
|
||||
<h3><a class="anchor" aria-hidden="true" id="measurelayoutrelativetonativenode-onsuccess-onfail"></a><a href="#measurelayoutrelativetonativenode-onsuccess-onfail" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>measureLayout(relativeToNativeNode, onSuccess, onFail)</h3>
|
||||
<p>Like <code>measure()</code>, but measures the view relative to an ancestor, specified as <code>relativeToNativeNode</code>. This means that the returned x, y are relative to the origin x, y of the ancestor view.</p>
|
||||
<p>As always, to obtain a native node handle for a component, you can use <code>findNodeHandle(component)</code>.</p>
|
||||
<pre><code class="hljs css language-jsx"><span class="token keyword">import</span> <span class="token punctuation">{</span> findNodeHandle <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'react-native'</span><span class="token punctuation">;</span>
|
||||
</code></pre>
|
||||
<h3><a class="anchor" aria-hidden="true" id="focus"></a><a href="#focus" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>focus()</h3>
|
||||
<h3><a class="anchor" aria-hidden="true" id="measurelayoutrelativetonativecomponentref-onsuccess-onfail"></a><a href="#measurelayoutrelativetonativecomponentref-onsuccess-onfail" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>measureLayout(relativeToNativeComponentRef, onSuccess, onFail)</h3>
|
||||
<p>Like <code>measure()</code>, but measures the view relative to an ancestor, specified with <code>relativeToNativeComponentRef</code> refrence. This means that the returned coordinates are relative to the origin <code>x</code>, <code>y</code> of the ancestor view.</p>
|
||||
<blockquote>
|
||||
<p>Note: This method can also be called with a <code>relativeToNativeNode</code> handler (instead of reference), but this variant is deprecated.</p>
|
||||
</blockquote>
|
||||
<div class="snack-player"><div class="mobile-friendly-snack" style="display: none"><pre><code class="hljs css javascript"><span class="hljs-keyword">import</span> React, { useEffect, useRef, useState } <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;
|
||||
<span class="hljs-keyword">import</span> { Text, View, StyleSheet } <span class="hljs-keyword">from</span> <span class="hljs-string">"react-native"</span>;
|
||||
|
||||
<span class="hljs-keyword">const</span> App = <span class="hljs-function">() =></span> {
|
||||
<span class="hljs-keyword">const</span> textContainerRef = useRef(<span class="hljs-literal">null</span>);
|
||||
<span class="hljs-keyword">const</span> textRef = useRef(<span class="hljs-literal">null</span>);
|
||||
<span class="hljs-keyword">const</span> [measure, setMeasure] = useState(<span class="hljs-literal">null</span>);
|
||||
|
||||
useEffect(<span class="hljs-function">() =></span> {
|
||||
<span class="hljs-keyword">if</span> (textRef.current && textContainerRef.current) {
|
||||
textRef.current.measureLayout(
|
||||
textContainerRef.current,
|
||||
<span class="hljs-function">(<span class="hljs-params">left, top, width, height</span>) =></span> {
|
||||
setMeasure({ left, top, width, height });
|
||||
}
|
||||
);
|
||||
}
|
||||
}, [measure]);
|
||||
|
||||
<span class="hljs-keyword">return</span> (
|
||||
<span class="xml"><span class="hljs-tag"><<span class="hljs-name">View</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{styles.container}</span>></span>
|
||||
<span class="hljs-tag"><<span class="hljs-name">View</span>
|
||||
<span class="hljs-attr">ref</span>=<span class="hljs-string">{textContainerRef}</span>
|
||||
<span class="hljs-attr">style</span>=<span class="hljs-string">{styles.textContainer}</span>
|
||||
></span>
|
||||
<span class="hljs-tag"><<span class="hljs-name">Text</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">{textRef}</span>></span>
|
||||
Where am I? (relative to the text container)
|
||||
<span class="hljs-tag"></<span class="hljs-name">Text</span>></span>
|
||||
<span class="hljs-tag"></<span class="hljs-name">View</span>></span>
|
||||
<span class="hljs-tag"><<span class="hljs-name">Text</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{styles.measure}</span>></span>
|
||||
{JSON.stringify(measure)}
|
||||
<span class="hljs-tag"></<span class="hljs-name">Text</span>></span>
|
||||
<span class="hljs-tag"></<span class="hljs-name">View</span>></span></span>
|
||||
);
|
||||
};
|
||||
|
||||
<span class="hljs-keyword">const</span> styles = StyleSheet.create({
|
||||
<span class="hljs-attr">container</span>: {
|
||||
<span class="hljs-attr">flex</span>: <span class="hljs-number">1</span>,
|
||||
<span class="hljs-attr">justifyContent</span>: <span class="hljs-string">"center"</span>,
|
||||
},
|
||||
<span class="hljs-attr">textContainer</span>: {
|
||||
<span class="hljs-attr">backgroundColor</span>: <span class="hljs-string">"#61dafb"</span>,
|
||||
<span class="hljs-attr">justifyContent</span>: <span class="hljs-string">"center"</span>,
|
||||
<span class="hljs-attr">alignItems</span>: <span class="hljs-string">"center"</span>,
|
||||
<span class="hljs-attr">padding</span>: <span class="hljs-number">12</span>,
|
||||
},
|
||||
<span class="hljs-attr">measure</span>: {
|
||||
<span class="hljs-attr">textAlign</span>: <span class="hljs-string">"center"</span>,
|
||||
<span class="hljs-attr">padding</span>: <span class="hljs-number">12</span>,
|
||||
},
|
||||
});
|
||||
|
||||
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> App;
|
||||
</code></pre></div><div class="desktop-friendly-snack" style="margin-top: 15px; margin-bottom: 15px"><div
|
||||
data-snack-name="measureLayout example"
|
||||
data-snack-description="Example usage"
|
||||
data-snack-code="import%20React%2C%20%7B%20useEffect%2C%20useRef%2C%20useState%20%7D%20from%20%22react%22%3B%0Aimport%20%7B%20Text%2C%20View%2C%20StyleSheet%20%7D%20from%20%22react-native%22%3B%0A%0Aconst%20App%20%3D%20()%20%3D%3E%20%7B%0A%20%20const%20textContainerRef%20%3D%20useRef(null)%3B%0A%20%20const%20textRef%20%3D%20useRef(null)%3B%0A%20%20const%20%5Bmeasure%2C%20setMeasure%5D%20%3D%20useState(null)%3B%0A%0A%20%20useEffect(()%20%3D%3E%20%7B%0A%20%20%20%20if%20(textRef.current%20%26%26%20textContainerRef.current)%20%7B%0A%20%20%20%20%20%20textRef.current.measureLayout(%0A%20%20%20%20%20%20%20%20textContainerRef.current%2C%0A%20%20%20%20%20%20%20%20(left%2C%20top%2C%20width%2C%20height)%20%3D%3E%20%7B%0A%20%20%20%20%20%20%20%20%20%20setMeasure(%7B%20left%2C%20top%2C%20width%2C%20height%20%7D)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20)%3B%0A%20%20%20%20%7D%0A%20%20%7D%2C%20%5Bmeasure%5D)%3B%0A%0A%20%20return%20(%0A%20%20%20%20%3CView%20style%3D%7Bstyles.container%7D%3E%0A%20%20%20%20%20%20%3CView%0A%20%20%20%20%20%20%20%20ref%3D%7BtextContainerRef%7D%0A%20%20%20%20%20%20%20%20style%3D%7Bstyles.textContainer%7D%0A%20%20%20%20%20%20%3E%0A%20%20%20%20%20%20%20%20%3CText%20ref%3D%7BtextRef%7D%3E%0A%20%20%20%20%20%20%20%20%20%20Where%20am%20I%3F%20(relative%20to%20the%20text%20container)%0A%20%20%20%20%20%20%20%20%3C%2FText%3E%0A%20%20%20%20%20%20%3C%2FView%3E%0A%20%20%20%20%20%20%3CText%20style%3D%7Bstyles.measure%7D%3E%0A%20%20%20%20%20%20%20%20%7BJSON.stringify(measure)%7D%0A%20%20%20%20%20%20%3C%2FText%3E%0A%20%20%20%20%3C%2FView%3E%0A%20%20)%3B%0A%7D%3B%0A%0Aconst%20styles%20%3D%20StyleSheet.create(%7B%0A%20%20container%3A%20%7B%0A%20%20%20%20flex%3A%201%2C%0A%20%20%20%20justifyContent%3A%20%22center%22%2C%0A%20%20%7D%2C%0A%20%20textContainer%3A%20%7B%0A%20%20%20%20backgroundColor%3A%20%22%2361dafb%22%2C%0A%20%20%20%20justifyContent%3A%20%22center%22%2C%0A%20%20%20%20alignItems%3A%20%22center%22%2C%0A%20%20%20%20padding%3A%2012%2C%0A%20%20%7D%2C%0A%20%20measure%3A%20%7B%0A%20%20%20%20textAlign%3A%20%22center%22%2C%0A%20%20%20%20padding%3A%2012%2C%0A%20%20%7D%2C%0A%7D)%3B%0A%0Aexport%20default%20App%3B%0A"
|
||||
data-snack-platform="web"
|
||||
data-snack-supported-platforms=android,ios
|
||||
data-snack-preview="true"
|
||||
style="
|
||||
overflow: hidden;
|
||||
background: #fafafa;
|
||||
border: 1px solid rgba(0,0,0,.16);
|
||||
border-radius: 4px;
|
||||
height: 514px;
|
||||
width: 100%;
|
||||
"
|
||||
></div></div></div><h3><a class="anchor" aria-hidden="true" id="focus"></a><a href="#focus" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>focus()</h3>
|
||||
<p>Requests focus for the given input or view. The exact behavior triggered will depend on the platform and type of view.</p>
|
||||
<h3><a class="anchor" aria-hidden="true" id="blur"></a><a href="#blur" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>blur()</h3>
|
||||
<p>Removes focus from an input or view. This is the opposite of <code>focus()</code>.</p>
|
||||
</span></div></article></div><div class="docs-prevnext"><a class="docs-prev button" href="/docs/next/native-modules-setup"><span class="arrow-prev">← </span><span>Native Modules Setup</span></a><a class="docs-next button" href="/docs/next/native-modules-android"><span>Native Modules</span><span class="arrow-next"> →</span></a></div></div></div><nav class="onPageNav"><ul class="toc-headings"><li><a href="#setnativeprops-with-touchableopacity">setNativeProps with TouchableOpacity</a></li><li><a href="#composite-components-and-setnativeprops">Composite components and setNativeProps</a></li><li><a href="#setnativeprops-to-clear-textinput-value">setNativeProps to clear TextInput value</a></li><li><a href="#avoiding-conflicts-with-the-render-function">Avoiding conflicts with the render function</a></li><li><a href="#setnativeprops--shouldcomponentupdate">setNativeProps & shouldComponentUpdate</a></li><li><a href="#other-native-methods">Other native methods</a><ul class="toc-headings"><li><a href="#measurecallback">measure(callback)</a></li><li><a href="#measureinwindowcallback">measureInWindow(callback)</a></li><li><a href="#measurelayoutrelativetonativenode-onsuccess-onfail">measureLayout(relativeToNativeNode, onSuccess, onFail)</a></li><li><a href="#focus">focus()</a></li><li><a href="#blur">blur()</a></li></ul></li></ul></nav></div><footer class="nav-footer" id="footer"><section class="sitemap"><div><h5>Docs</h5><a href="/docs/getting-started">Getting Started</a><a href="/docs/tutorial">Tutorial</a><a href="/docs/components-and-apis">Components and APIs</a><a href="/docs/more-resources">More Resources</a></div><div><h5>Community</h5><a href="/help">The React Native Community</a><a href="/showcase">Who's using React Native?</a><a href="https://stackoverflow.com/questions/tagged/react-native" target="_blank">Ask Questions on Stack Overflow</a><a href="https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md">Contributor Guide</a><a href="https://dev.to/t/reactnative" target="_blank">DEV Community</a></div><div><h5>More Resources</h5><a href="/blog">Blog</a><a href="https://twitter.com/reactnative" target="_blank">Twitter</a><a href="https://github.com/facebook/react-native" target="_blank">GitHub</a><a href="https://reactjs.org" target="_blank">React</a></div></section><a href="https://code.facebook.com/projects/" target="_blank" class="fbOpenSource"><img src="/img/oss_logo.png" alt="Facebook Open Source" width="170" height="45"/></a><section class="copyright">Copyright © 2020 Facebook Inc.</section></footer></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js"></script><script>window.fbAsyncInit = function() {FB.init({appId:'1677033832619985',xfbml:true,version:'v2.7'});};(function(d, s, id){var js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) {return;}js = d.createElement(s); js.id = id;js.src = '//connect.facebook.net/en_US/sdk.js';fjs.parentNode.insertBefore(js, fjs);}(document, 'script','facebook-jssdk'));
|
||||
</span></div></article></div><div class="docs-prevnext"><a class="docs-prev button" href="/docs/next/native-modules-setup"><span class="arrow-prev">← </span><span>Native Modules Setup</span></a><a class="docs-next button" href="/docs/next/native-modules-android"><span>Native Modules</span><span class="arrow-next"> →</span></a></div></div></div><nav class="onPageNav"><ul class="toc-headings"><li><a href="#setnativeprops-with-touchableopacity">setNativeProps with TouchableOpacity</a></li><li><a href="#composite-components-and-setnativeprops">Composite components and setNativeProps</a></li><li><a href="#setnativeprops-to-clear-textinput-value">setNativeProps to clear TextInput value</a></li><li><a href="#avoiding-conflicts-with-the-render-function">Avoiding conflicts with the render function</a></li><li><a href="#setnativeprops--shouldcomponentupdate">setNativeProps & shouldComponentUpdate</a></li><li><a href="#other-native-methods">Other native methods</a><ul class="toc-headings"><li><a href="#measurecallback">measure(callback)</a></li><li><a href="#measureinwindowcallback">measureInWindow(callback)</a></li><li><a href="#measurelayoutrelativetonativecomponentref-onsuccess-onfail">measureLayout(relativeToNativeComponentRef, onSuccess, onFail)</a></li><li><a href="#focus">focus()</a></li><li><a href="#blur">blur()</a></li></ul></li></ul></nav></div><footer class="nav-footer" id="footer"><section class="sitemap"><div><h5>Docs</h5><a href="/docs/getting-started">Getting Started</a><a href="/docs/tutorial">Tutorial</a><a href="/docs/components-and-apis">Components and APIs</a><a href="/docs/more-resources">More Resources</a></div><div><h5>Community</h5><a href="/help">The React Native Community</a><a href="/showcase">Who's using React Native?</a><a href="https://stackoverflow.com/questions/tagged/react-native" target="_blank">Ask Questions on Stack Overflow</a><a href="https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md">Contributor Guide</a><a href="https://dev.to/t/reactnative" target="_blank">DEV Community</a></div><div><h5>More Resources</h5><a href="/blog">Blog</a><a href="https://twitter.com/reactnative" target="_blank">Twitter</a><a href="https://github.com/facebook/react-native" target="_blank">GitHub</a><a href="https://reactjs.org" target="_blank">React</a></div></section><a href="https://code.facebook.com/projects/" target="_blank" class="fbOpenSource"><img src="/img/oss_logo.png" alt="Facebook Open Source" width="170" height="45"/></a><section class="copyright">Copyright © 2020 Facebook Inc.</section></footer></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js"></script><script>window.fbAsyncInit = function() {FB.init({appId:'1677033832619985',xfbml:true,version:'v2.7'});};(function(d, s, id){var js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) {return;}js = d.createElement(s); js.id = id;js.src = '//connect.facebook.net/en_US/sdk.js';fjs.parentNode.insertBefore(js, fjs);}(document, 'script','facebook-jssdk'));
|
||||
</script><script>window.twttr=(function(d,s, id){var js,fjs=d.getElementsByTagName(s)[0],t=window.twttr||{};if(d.getElementById(id))return t;js=d.createElement(s);js.id=id;js.src='https://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js, fjs);t._e = [];t.ready = function(f) {t._e.push(f);};return t;}(document, 'script', 'twitter-wjs'));</script><script>
|
||||
document.addEventListener('keyup', function(e) {
|
||||
if (e.target !== document.body) {
|
||||
|
||||
Reference in New Issue
Block a user