mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
45 lines
42 KiB
HTML
45 lines
42 KiB
HTML
<!doctype html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||
<meta name="generator" content="Docusaurus v2.0.0-alpha.66">
|
||
<link rel="alternate" type="application/rss+xml" href="/blog/rss.xml" title="React Native Blog RSS Feed">
|
||
<link rel="alternate" type="application/atom+xml" href="/blog/atom.xml" title="React Native Blog Atom Feed">
|
||
<link rel="preconnect" href="https://www.google-analytics.com">
|
||
<script>window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)},ga.l=+new Date,ga("create","UA-41298772-2","auto"),ga("send","pageview")</script>
|
||
<script async src="https://www.google-analytics.com/analytics.js"></script>
|
||
<link rel="preconnect" href="https://www.google-analytics.com">
|
||
<link rel="preconnect" href="https://www.googletagmanager.com">
|
||
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-41298772-2"></script>
|
||
<script>function gtag(){dataLayer.push(arguments)}window.dataLayer=window.dataLayer||[],gtag("js",new Date),gtag("config","UA-41298772-2",{})</script>
|
||
<link rel="search" type="application/opensearchdescription+xml" title="React Native" href="/opensearch.xml">
|
||
<script src="https://cdn.jsdelivr.net/npm/focus-visible@5.2.0/dist/focus-visible.min.js" defer="defer"></script>
|
||
<script src="https://snack.expo.io/embed.js" defer="defer"></script><title data-react-helmet="true">Layout with Flexbox · React Native</title><meta data-react-helmet="true" property="twitter:image" content="https://reactnative.dev/img/logo-og.png"><meta data-react-helmet="true" name="twitter:image:alt" content="Image for React Native"><meta data-react-helmet="true" name="docsearch:language" content="en"><meta data-react-helmet="true" name="docsearch:version" content="0.60"><meta data-react-helmet="true" name="docsearch:docusaurus_tag" content="docs-default-0.60"><meta data-react-helmet="true" property="og:image" content="https://reactnative.dev/img/logo-og.png"><meta data-react-helmet="true" name="twitter:card" content="summary"><meta data-react-helmet="true" name="twitter:image" content="https://reactnative.dev/img/logo-og.png"><meta data-react-helmet="true" property="og:title" content="Layout with Flexbox · React Native"><meta data-react-helmet="true" name="description" content="A component can specify the layout of its children using the flexbox algorithm. Flexbox is designed to provide a consistent layout on different screen sizes."><meta data-react-helmet="true" property="og:description" content="A component can specify the layout of its children using the flexbox algorithm. Flexbox is designed to provide a consistent layout on different screen sizes."><meta data-react-helmet="true" property="og:url" content="https://reactnative.dev/docs/0.60/flexbox"><link data-react-helmet="true" rel="shortcut icon" href="/img/favicon.ico"><link data-react-helmet="true" rel="preconnect" href="https://BH4D9OD16A-dsn.algolia.net" crossorigin="anonymous"><link data-react-helmet="true" rel="canonical" href="https://reactnative.dev/docs/0.60/flexbox"><link rel="stylesheet" href="/styles.fccefeba.css">
|
||
<link rel="stylesheet" href="/main.ca40cabd.css">
|
||
<link rel="preload" href="/styles.07d522c6.js" as="script">
|
||
<link rel="preload" href="/runtime~main.373c7abc.js" as="script">
|
||
<link rel="preload" href="/main.5a3c9855.js" as="script">
|
||
<link rel="preload" href="/1.ba9ce8bd.js" as="script">
|
||
<link rel="preload" href="/2.58cb5d3d.js" as="script">
|
||
<link rel="preload" href="/1f391b9e.a824c215.js" as="script">
|
||
<link rel="preload" href="/943.8b024446.js" as="script">
|
||
<link rel="preload" href="/ae345423.971fbe80.js" as="script">
|
||
<link rel="preload" href="/17896441.0c201679.js" as="script">
|
||
<link rel="preload" href="/cf28e639.8c47799b.js" as="script">
|
||
</head>
|
||
<body>
|
||
<script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}()</script><div id="__docusaurus">
|
||
<nav class="navbar navbar--fixed-top navbar--dark"><div class="navbar__inner"><div class="navbar__items"><div aria-label="Navigation bar toggle" class="navbar__toggle" role="button" tabindex="0"><svg xmlns="http://www.w3.org/2000/svg" width="30" height="30" viewBox="0 0 30 30" role="img" focusable="false"><title>Menu</title><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></div><a class="navbar__brand" href="/"><img class="navbar__logo" src="/img/header_logo.svg" alt="React Native"><strong class="navbar__title">React Native</strong></a><div class="navbar__item dropdown dropdown--hoverable dropdown--left"><a class="navbar__item navbar__link" href="/docs/0.60/getting-started">0.60</a><ul class="dropdown__menu"><li><a class="dropdown__link" href="/docs/next/flexbox">Next</a></li><li><a class="dropdown__link" href="/docs/flexbox">0.63</a></li><li><a class="dropdown__link" href="/docs/0.62/flexbox">0.62</a></li><li><a class="dropdown__link" href="/docs/0.61/flexbox">0.61</a></li><li><a aria-current="page" class="dropdown__link dropdown__link--active" href="/docs/0.60/flexbox">0.60</a></li><li><a class="dropdown__link" href="/versions">All versions</a></li></ul></div></div><div class="navbar__items navbar__items--right"><a class="navbar__item navbar__link navbar__link--active" href="/docs/0.60/getting-started">Docs</a><a class="navbar__item navbar__link" href="/docs/0.60/components-and-apis">Components</a><a class="navbar__item navbar__link" href="/docs/0.60/accessibilityinfo">API</a><a class="navbar__item navbar__link" href="/help">Community</a><a class="navbar__item navbar__link" href="/blog">Blog</a><a href="https://github.com/facebook/react-native" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link navbar-github-link" aria-label="GitHub repository"></a><div class="react-toggle react-toggle--disabled displayOnlyInLargeViewport_3lWe"><div class="react-toggle-track"><div class="react-toggle-track-check"><span class="toggle_gnXW">🌜</span></div><div class="react-toggle-track-x"><span class="toggle_gnXW">🌞</span></div></div><div class="react-toggle-thumb"></div><input type="checkbox" disabled="" aria-label="Dark mode toggle" class="react-toggle-screenreader-only"></div><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><svg width="20" height="20" class="DocSearch-Search-Icon" viewBox="0 0 20 20"><path d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z" stroke="currentColor" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path></svg><span class="DocSearch-Button-Placeholder">Search</span><span class="DocSearch-Button-Key">⌘</span><span class="DocSearch-Button-Key">K</span></button></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div><div class="navbar-sidebar"><div class="navbar-sidebar__brand"><a class="navbar__brand" href="/"><img class="navbar__logo" src="/img/header_logo.svg" alt="React Native"><strong class="navbar__title">React Native</strong></a></div><div class="navbar-sidebar__items"><div class="menu"><ul class="menu__list"><li class="menu__list-item"><a class="menu__link navbar__link--active" href="/docs/0.60/getting-started">Docs</a></li><li class="menu__list-item"><a class="menu__link" href="/docs/0.60/components-and-apis">Components</a></li><li class="menu__list-item"><a class="menu__link" href="/docs/0.60/accessibilityinfo">API</a></li><li class="menu__list-item"><a class="menu__link" href="/help">Community</a></li><li class="menu__list-item"><a class="menu__link" href="/blog">Blog</a></li><li class="menu__list-item"><a role="button" class="menu__link menu__link--sublist">Versions</a><ul class="menu__list"><li class="menu__list-item"><a class="menu__link" href="/docs/next/flexbox">Next</a></li><li class="menu__list-item"><a class="menu__link" href="/docs/flexbox">0.63</a></li><li class="menu__list-item"><a class="menu__link" href="/docs/0.62/flexbox">0.62</a></li><li class="menu__list-item"><a class="menu__link" href="/docs/0.61/flexbox">0.61</a></li><li class="menu__list-item"><a aria-current="page" class="menu__link menu__link--active" href="/docs/0.60/flexbox">0.60</a></li><li class="menu__list-item"><a class="menu__link" href="/versions">All versions</a></li></ul></li><li class="menu__list-item"><a href="https://github.com/facebook/react-native" target="_blank" rel="noopener noreferrer" class="menu__link navbar-github-link" aria-label="GitHub repository"></a></li></ul></div></div></div></nav><div class="main-wrapper"><div class="docPage_2UBv"><div class="docSidebarContainer_1hqR" role="complementary"><div class="sidebar_MSwm"><div class="menu menu--responsive menu_2hiu"><button aria-label="Open Menu" aria-haspopup="true" class="button button--secondary button--sm menu__button" type="button"><svg aria-label="Menu" class="sidebarMenuIcon_37TU" xmlns="http://www.w3.org/2000/svg" height="24" width="24" viewBox="0 0 32 32" role="img" focusable="false"><title>Menu</title><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><ul class="menu__list"><li class="menu__list-item"><a class="menu__link menu__link--sublist menu__link--active" href="#!">The Basics</a><ul class="menu__list"><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/0.60/getting-started">Introduction</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/0.60/tutorial">Learn the Basics</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/0.60/style">Style</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/0.60/height-and-width">Height and Width</a></li><li class="menu__list-item"><a aria-current="page" class="menu__link menu__link--active active" tabindex="0" href="/docs/0.60/flexbox">Layout with Flexbox</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/0.60/handling-text-input">Handling Text Input</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/0.60/handling-touches">Handling Touches</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/0.60/using-a-scrollview">Using a ScrollView</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/0.60/using-a-listview">Using List Views</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/0.60/network">Networking</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/0.60/more-resources">More Resources</a></li></ul></li><li class="menu__list-item menu__list-item--collapsed"><a class="menu__link menu__link--sublist" href="#!">Guides</a><ul class="menu__list"><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/platform-specific-code">Platform Specific Code</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/navigation">Navigating Between Screens</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/images">Images</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/animations">Animations</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/accessibility">Accessibility</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/improvingux">Improving User Experience</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/optimizing-flatlist-configuration">Optimizing Flatlist Configuration</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/timers">Timers</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/debugging">Debugging</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/performance">Performance</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/gesture-responder-system">Gesture Responder System</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/javascript-environment">JavaScript Environment</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/typescript">Using TypeScript with React Native</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/direct-manipulation">Direct Manipulation</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/colors">Color Reference</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/integration-with-existing-apps">Integration with Existing Apps</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/building-for-tv">Building For TV Devices</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/running-on-device">Running On Device</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/upgrading">Upgrading to new React Native versions</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/troubleshooting">Troubleshooting</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/native-modules-setup">Native Modules Setup</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/out-of-tree-platforms">Out-of-Tree Platforms</a></li></ul></li><li class="menu__list-item menu__list-item--collapsed"><a class="menu__link menu__link--sublist" href="#!">Guides (iOS)</a><ul class="menu__list"><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/native-modules-ios">Native Modules</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/native-components-ios">Native UI Components</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/linking-libraries-ios">Linking Libraries</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/running-on-simulator-ios">Running On Simulator</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/communication-ios">Communication between native and React Native</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/app-extensions">App Extensions</a></li></ul></li><li class="menu__list-item menu__list-item--collapsed"><a class="menu__link menu__link--sublist" href="#!">Guides (Android)</a><ul class="menu__list"><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/native-modules-android">Native Modules</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/native-components-android">Native UI Components</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/headless-js-android">Headless JS</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/signed-apk-android">Publishing to Google Play Store</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/removing-default-permissions">Removing Default Permissions</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/0.60/hermes">Using Hermes</a></li></ul></li></ul></div></div></div><main class="docMainContainer_1rYT"><div class="container padding-vert--lg docItemWrapper_1Hme"><div class="row"><div class="col docItemCol_2AGf"><div class="alert alert--warning margin-bottom--md" role="alert"><div>This is documentation for React Native <strong>0.60</strong>, which is no longer actively maintained.</div><div class="margin-top--md">For up-to-date documentation, see the <strong><a href="/docs/flexbox">latest version</a></strong> (0.63).</div></div><div class="docItemContainer_1tAC"><article><div><span class="badge badge--secondary">Version: 0.60</span></div><header><h1 class="docTitle_cWlf">Layout with Flexbox</h1></header><div class="markdown"><p>A component can specify the layout of its children using the flexbox algorithm. Flexbox is designed to provide a consistent layout on different screen sizes.</p><p>You will normally use a combination of <code>flexDirection</code>, <code>alignItems</code>, and <code>justifyContent</code> to achieve the right layout.</p><blockquote><p>Flexbox works the same way in React Native as it does in CSS on the web, with a few exceptions. The defaults are different, with <code>flexDirection</code> defaulting to <code>column</code> instead of <code>row</code>, and the <code>flex</code> parameter only supporting a single number.</p></blockquote><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_3pqN" id="flex"></a>Flex<a aria-hidden="true" tabindex="-1" class="hash-link" href="#flex" title="Direct link to heading">#</a></h3><p><a href="/docs/layout-props#flex"><code>flex</code></a> will define how your items are going to <strong>“fill”</strong> over the available space along your main axis. Space will be divided according to each element's flex property.</p><p>In the following example the red, yellow and the green views are all children in the container view that has <code>flex: 1</code> set. The red view uses <code>flex: 1</code> , the yellow view uses <code>flex: 2</code> and the green view uses <code>flex: 3</code> . <strong>1+2+3 = 6</strong> which means that the red view will get <code>1/6</code> of the space, the yellow <code>2/6</code> of the space and the green <code>3/6</code> of the space.</p><p><img src="https://cdn-images-1.medium.com/max/800/1*PhCFmO5tYX_sZSyCd4vO3w.png" alt="Flex"></p><h4><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_3pqN" id="flex-direction"></a>Flex Direction<a aria-hidden="true" tabindex="-1" class="hash-link" href="#flex-direction" title="Direct link to heading">#</a></h4><p><a href="/docs/layout-props#flexdirection"><code>flexDirection</code></a> controls the direction in which the children of a node are laid out. This is also referred to as the <em>main axis</em>. The cross axis is the axis perpendicular to the main axis, or the axis which the wrapping lines are laid out in.</p><ul><li><p><code>row</code> Align children from left to right. If wrapping is enabled then the next line will start under the first item on the left of the container.</p></li><li><p><code>column</code> (<strong>default value</strong>) Align children from top to bottom. If wrapping is enabled then the next line will start to the left first item on the top of the container.</p></li><li><p><code>row-reverse</code> Align children from right to left. If wrapping is enabled then the next line will start under the first item on the right of the container.</p></li><li><p><code>column-reverse</code> Align children from bottom to top. If wrapping is enabled then the next line will start to the left first item on the bottom of the container.</p></li></ul><p>LEARN MORE <a href="https://yogalayout.com/docs/flex-direction" target="_blank" rel="noopener noreferrer">HERE</a></p><div class="snack-player" data-snack-name="Flex Direction" data-snack-description="Example usage" data-snack-code="import%20React%2C%20%7B%20Component%20%7D%20from%20'react'%3B%0Aimport%20%7B%20View%20%7D%20from%20'react-native'%3B%0A%0Aexport%20default%20class%20FlexDirectionBasics%20extends%20Component%20%7B%0A%20%20render()%20%7B%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%2F%2F%20Try%20setting%20%60flexDirection%60%20to%20%60column%60.%0A%20%20%20%20%20%20%3CView%20style%3D%7B%7Bflex%3A%201%2C%20flexDirection%3A%20'row'%7D%7D%3E%0A%20%20%20%20%20%20%20%20%3CView%20style%3D%7B%7Bwidth%3A%2050%2C%20height%3A%2050%2C%20backgroundColor%3A%20'powderblue'%7D%7D%20%2F%3E%0A%20%20%20%20%20%20%20%20%3CView%20style%3D%7B%7Bwidth%3A%2050%2C%20height%3A%2050%2C%20backgroundColor%3A%20'skyblue'%7D%7D%20%2F%3E%0A%20%20%20%20%20%20%20%20%3CView%20style%3D%7B%7Bwidth%3A%2050%2C%20height%3A%2050%2C%20backgroundColor%3A%20'steelblue'%7D%7D%20%2F%3E%0A%20%20%20%20%20%20%3C%2FView%3E%0A%20%20%20%20)%3B%0A%20%20%7D%0A%7D%3B" data-snack-platform="web" data-snack-supported-platforms="ios,android,web" data-snack-theme="light" data-snack-preview="true" data-snack-loading="lazy"></div><p><img src="https://cdn-images-1.medium.com/max/800/1*rA7IbuUsJWsx6evKAsabVw.png" alt="Flex Direction"></p><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_3pqN" id="layout-direction"></a>Layout Direction<a aria-hidden="true" tabindex="-1" class="hash-link" href="#layout-direction" title="Direct link to heading">#</a></h3><p>Layout direction specifies the direction in which children and text in a hierarchy should be laid out. Layout direction also affects what edge <code>start</code> and <code>end</code> refer to. By default React Native lays out with LTR layout direction. In this mode <code>start</code> refers to left and <code>end</code> refers to right.</p><ul><li><p><code>LTR</code> (<strong>default value</strong>) Text and children are laid out from left to right. Margin and padding applied the start of an element are applied on the left side.</p></li><li><p><code>RTL</code> Text and children are laid out from right to left. Margin and padding applied the start of an element are applied on the right side.</p></li></ul><h4><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_3pqN" id="justify-content"></a>Justify Content<a aria-hidden="true" tabindex="-1" class="hash-link" href="#justify-content" title="Direct link to heading">#</a></h4><p><a href="/docs/layout-props#justifycontent"><code>justifyContent</code></a> describes how to align children within the main axis of their container. For example, you can use this property to center a child horizontally within a container with <code>flexDirection</code> set to <code>row</code> or vertically within a container with <code>flexDirection</code> set to <code>column</code>.</p><ul><li><p><code>flex-start</code>(<strong>default value</strong>) Align children of a container to the start of the container's main axis.</p></li><li><p><code>flex-end</code> Align children of a container to the end of the container's main axis.</p></li><li><p><code>center</code> Align children of a container in the center of the container's main axis.</p></li><li><p><code>space-between</code> Evenly space of children across the container's main axis, distributing remaining space between the children.</p></li><li><p><code>space-around</code> Evenly space of children across the container's main axis, distributing remaining space around the children. Compared to <code>space-between</code> using <code>space-around</code> will result in space being distributed to the beginning of the first child and end of the last child.</p></li><li><p><code>space-evenly</code> Evenly distributed within the alignment container along the main axis. The spacing between each pair of adjacent items, the main-start edge and the first item, and the main-end edge and the last item, are all exactly the same.</p></li></ul><p>LEARN MORE <a href="https://yogalayout.com/docs/justify-content" target="_blank" rel="noopener noreferrer">HERE</a></p><div class="snack-player" data-snack-name="Justify Content" data-snack-description="Example usage" data-snack-code="import%20React%2C%20%7B%20Component%20%7D%20from%20'react'%3B%0Aimport%20%7B%20View%20%7D%20from%20'react-native'%3B%0A%0Aexport%20default%20class%20JustifyContentBasics%20extends%20Component%20%7B%0A%20%20render()%20%7B%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%2F%2F%20Try%20setting%20%60justifyContent%60%20to%20%60center%60.%0A%20%20%20%20%20%20%2F%2F%20Try%20setting%20%60flexDirection%60%20to%20%60row%60.%0A%20%20%20%20%20%20%3CView%20style%3D%7B%7B%0A%20%20%20%20%20%20%20%20flex%3A%201%2C%0A%20%20%20%20%20%20%20%20flexDirection%3A%20'column'%2C%0A%20%20%20%20%20%20%20%20justifyContent%3A%20'space-between'%2C%0A%20%20%20%20%20%20%7D%7D%3E%0A%20%20%20%20%20%20%20%20%3CView%20style%3D%7B%7Bwidth%3A%2050%2C%20height%3A%2050%2C%20backgroundColor%3A%20'powderblue'%7D%7D%20%2F%3E%0A%20%20%20%20%20%20%20%20%3CView%20style%3D%7B%7Bwidth%3A%2050%2C%20height%3A%2050%2C%20backgroundColor%3A%20'skyblue'%7D%7D%20%2F%3E%0A%20%20%20%20%20%20%20%20%3CView%20style%3D%7B%7Bwidth%3A%2050%2C%20height%3A%2050%2C%20backgroundColor%3A%20'steelblue'%7D%7D%20%2F%3E%0A%20%20%20%20%20%20%3C%2FView%3E%0A%20%20%20%20)%3B%0A%20%20%7D%0A%7D%3B" data-snack-platform="web" data-snack-supported-platforms="ios,android,web" data-snack-theme="light" data-snack-preview="true" data-snack-loading="lazy"></div><p><img src="https://cdn-images-1.medium.com/max/800/1*i5TVlme-TisAVvD5ax2yPA.png" alt="Justify Content"></p><h4><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_3pqN" id="align-items"></a>Align Items<a aria-hidden="true" tabindex="-1" class="hash-link" href="#align-items" title="Direct link to heading">#</a></h4><p><a href="/docs/layout-props#alignitems"><code>alignItems</code></a> describes how to align children along the cross axis of their container. Align items is very similar to <code>justifyContent</code> but instead of applying to the main axis, <code>alignItems</code> applies to the cross axis.</p><ul><li><p><code>stretch</code> (<strong>default value</strong>) Stretch children of a container to match the <code>height</code> of the container's cross axis.</p></li><li><p><code>flex-start</code> Align children of a container to the start of the container's cross axis.</p></li><li><p><code>flex-end</code> Align children of a container to the end of the container's cross axis.</p></li><li><p><code>center</code> Align children of a container in the center of the container's cross axis.</p></li><li><p><code>baseline</code> Align children of a container along a common baseline. Individual children can be set to be the reference baseline for their parents.</p></li></ul><blockquote><p>For <code>stretch</code> to have an effect, children must not have a fixed dimension along the secondary axis. In the following example, setting <code>alignItems: stretch</code> does nothing until the <code>width: 50</code> is removed from the children.</p></blockquote><p>LEARN MORE <a href="https://yogalayout.com/docs/align-items" target="_blank" rel="noopener noreferrer">HERE</a></p><div class="snack-player" data-snack-name="Align Items" data-snack-description="Example usage" data-snack-code="import%20React%2C%20%7B%20Component%20%7D%20from%20'react'%3B%0Aimport%20%7B%20View%20%7D%20from%20'react-native'%3B%0A%0Aexport%20default%20class%20AlignItemsBasics%20extends%20Component%20%7B%0A%20%20render()%20%7B%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%2F%2F%20Try%20setting%20%60alignItems%60%20to%20'flex-start'%0A%20%20%20%20%20%20%2F%2F%20Try%20setting%20%60justifyContent%60%20to%20%60flex-end%60.%0A%20%20%20%20%20%20%2F%2F%20Try%20setting%20%60flexDirection%60%20to%20%60row%60.%0A%20%20%20%20%20%20%3CView%20style%3D%7B%7B%0A%20%20%20%20%20%20%20%20flex%3A%201%2C%0A%20%20%20%20%20%20%20%20flexDirection%3A%20'column'%2C%0A%20%20%20%20%20%20%20%20justifyContent%3A%20'center'%2C%0A%20%20%20%20%20%20%20%20alignItems%3A%20'stretch'%2C%0A%20%20%20%20%20%20%7D%7D%3E%0A%20%20%20%20%20%20%20%20%3CView%20style%3D%7B%7Bwidth%3A%2050%2C%20height%3A%2050%2C%20backgroundColor%3A%20'powderblue'%7D%7D%20%2F%3E%0A%20%20%20%20%20%20%20%20%3CView%20style%3D%7B%7Bheight%3A%2050%2C%20backgroundColor%3A%20'skyblue'%7D%7D%20%2F%3E%0A%20%20%20%20%20%20%20%20%3CView%20style%3D%7B%7Bheight%3A%20100%2C%20backgroundColor%3A%20'steelblue'%7D%7D%20%2F%3E%0A%20%20%20%20%20%20%3C%2FView%3E%0A%20%20%20%20)%3B%0A%20%20%7D%0A%7D%3B" data-snack-platform="web" data-snack-supported-platforms="ios,android,web" data-snack-theme="light" data-snack-preview="true" data-snack-loading="lazy"></div><p><img src="https://cdn-images-1.medium.com/max/800/1*evkM7zfxt-9p-HJ1M0Bh2g.png" alt="Align Items"></p><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_3pqN" id="align-self"></a>Align Self<a aria-hidden="true" tabindex="-1" class="hash-link" href="#align-self" title="Direct link to heading">#</a></h3><p><a href="/docs/layout-props#alignself"><code>alignSelf</code></a> has the same options and effect as <code>alignItems</code> but instead of affecting the children within a container, you can apply this property to a single child to change its alignment within its parent. <code>alignSelf</code> overrides any option set by the parent with <code>alignItems</code>.</p><p><img src="https://cdn-images-1.medium.com/max/800/1*J1JCoKwLCokX9JXVBvP71g.png" alt="Align Self"></p><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_3pqN" id="align-content"></a>Align Content<a aria-hidden="true" tabindex="-1" class="hash-link" href="#align-content" title="Direct link to heading">#</a></h3><p><a href="/docs/layout-props#aligncontent">alignContent</a> defines the distribution of lines along the cross-axis. This only has effect when items are wrapped to multiple lines using <code>flexWrap</code>.</p><ul><li><p><code>flex-start</code> (<strong>default value</strong>) Align wrapped lines to the start of the container's cross axis.</p></li><li><p><code>flex-end</code> Align wrapped lines to the end of the container's cross axis.</p></li><li><p><code>stretch</code> wrapped lines to match the height of the container's cross axis.</p></li><li><p><code>center</code> Align wrapped lines in the center of the container's cross axis.</p></li><li><p><code>space-between</code> Evenly space wrapped lines across the container's main axis, distributing remaining space between the lines.</p></li><li><p><code>space-around</code> Evenly space wrapped lines across the container's main axis, distributing remaining space around the lines. Compared to space between using space around will result in space being distributed to the begining of the first lines and end of the last line.</p></li></ul><p>LEARN MORE <a href="https://yogalayout.com/docs/align-content" target="_blank" rel="noopener noreferrer">HERE</a></p><p><img src="https://cdn-images-1.medium.com/max/800/1*cC2XFyCF_igp20Ombt4wBw.png" alt="Align Content"></p><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_3pqN" id="flex-wrap"></a>Flex Wrap<a aria-hidden="true" tabindex="-1" class="hash-link" href="#flex-wrap" title="Direct link to heading">#</a></h3><p>The <a href="/docs/layout-props#flexwrap"><code>flexWrap</code></a> property is set on containers and controls what happens when children overflow the size of the container along the main axis. By default children are forced into a single line (which can shrink elements). If wrapping is allowed items are wrapped into multiple lines along the main axis if needed.</p><p>When wrapping lines <code>alignContent</code> can be used to specify how the lines are placed in the container. learn more <a href="https://yogalayout.com/docs/flex-wrap" target="_blank" rel="noopener noreferrer">here</a></p><p><img src="https://cdn-images-1.medium.com/max/800/1*_7v4uQhSsuCn1cfeOMVfrA.png" alt="Flex Wrap"></p><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_3pqN" id="flex-basis-grow-and-shrink"></a>Flex Basis, Grow, and Shrink<a aria-hidden="true" tabindex="-1" class="hash-link" href="#flex-basis-grow-and-shrink" title="Direct link to heading">#</a></h3><ul><li><p><a href="/docs/layout-props#flexgrow"><code>flexGrow</code></a> describes how any space within a container should be distributed among its children along the main axis. After laying out its children, a container will distribute any remaining space according to the flex grow values specified by its children.</p><p>flexGrow accepts any floating point value >= 0, with 0 being the default value. A container will distribute any remaining space among its children weighted by the child’s flex grow value.</p></li><li><p><a href="/docs/layout-props#flexshrink"><code>flexShrink</code></a> describes how to shrink children along the main axis in the case that the total size of the children overflow the size of the container on the main axis. Flex shrink is very similar to flex grow and can be thought of in the same way if any overflowing size is considered to be negative remaining space. These two properties also work well together by allowing children to grow and shrink as needed.</p><p>Flex shrink accepts any floating point value >= 0, with 1 being the default value. A container will shrink its children weighted by the child’s flex shrink value.</p></li><li><p><a href="/docs/layout-props#flexbasis"><code>flexBasis</code></a> is an axis-independent way of providing the default size of an item along the main axis. Setting the flex basis of a child is similar to setting the <code>width</code> of that child if its parent is a container with <code>flexDirection: row</code> or setting the <code>height</code> of a child if its parent is a container with <code>flexDirection: column</code>. The flex basis of an item is the default size of that item, the size of the item before any flex grow and flex shrink calculations are performed.</p></li></ul><p>LEARN MORE <a href="https://yogalayout.com/docs/flex" target="_blank" rel="noopener noreferrer">HERE</a></p><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_3pqN" id="width-and-height"></a>Width and Height<a aria-hidden="true" tabindex="-1" class="hash-link" href="#width-and-height" title="Direct link to heading">#</a></h3><p>The <code>width</code> property in Yoga specifies the width of the element's content area. Similarly height property specifies the <code>height</code> of the element's content area.</p><p>Both <code>width</code> and <code>height</code> can take following values:</p><ul><li><p><code>auto</code> Is the <strong>default Value</strong>, React Native calculates the width/height for the element based on its content, whether that is other children, text, or an image.</p></li><li><p><code>pixels</code> Defines the width/height in absolute pixels. Depending on other styles set on the component, this may or may not be the final dimension of the node.</p></li><li><p><code>percentage</code> Defines the width or height in percentage of its parent's width or height respectively.</p></li></ul><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_3pqN" id="absolute--relative-layout"></a>Absolute & Relative Layout<a aria-hidden="true" tabindex="-1" class="hash-link" href="#absolute--relative-layout" title="Direct link to heading">#</a></h3><p>The <code>position</code> type of an element defines how it is positioned within its parent.</p><p><code>relative</code> (<strong>default value</strong>) By default an element is positioned relatively. This means an element is positioned according to the normal flow of the layout, and then offset relative to that position based on the values of <code>top</code>, <code>right</code>, <code>bottom</code>, and <code>left</code>. The offset does not affect the position of any sibling or parent elements.</p><p><code>absolute</code> When positioned absolutely an element doesn't take part in the normal layout flow. It is instead laid out independent of its siblings. The position is determined based on the <code>top</code>, <code>right</code>, <code>bottom</code>, and <code>left</code> values.</p><p><img src="https://cdn-images-1.medium.com/max/800/1*NlPeRQCQK3Vb5nyjL0Mqxw.png" alt="Absolute & Relative Layoutp"></p><h4><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_3pqN" id="going-deeper"></a>Going Deeper<a aria-hidden="true" tabindex="-1" class="hash-link" href="#going-deeper" title="Direct link to heading">#</a></h4><p>Check out the interactive <a href="https://yogalayout.com/playground" target="_blank" rel="noopener noreferrer">yoga playground</a> that you can use to get a better understanding of flexbox.</p><p>We've covered the basics, but there are many other styles you may need for layouts. The full list of props that control layout is documented <a href="/docs/0.60/layout-props">here</a>.</p><p>We're getting close to being able to build a real application. One thing we are still missing is a way to take user input, so let's move on to <a href="/docs/0.60/handling-text-input">learn how to handle text input with the TextInput component</a>.</p><p>See some examples from <a href="https://medium.com/wix-engineering/the-full-react-native-layout-cheat-sheet-a4147802405c" target="_blank" rel="noopener noreferrer">Wix Engineers</a>:</p></div></article><div class="docMetadata margin-vert--xl"><div class="row"><div class="col"><a href="https://github.com/facebook/react-native-website/blob/master/website/versioned_docs/version-0.60/flexbox.md" target="_blank" rel="noreferrer noopener"><svg fill="currentColor" height="1.2em" width="1.2em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 40 40" style="margin-right:0.3em;vertical-align:sub"><g><path d="m34.5 11.7l-3 3.1-6.3-6.3 3.1-3q0.5-0.5 1.2-0.5t1.1 0.5l3.9 3.9q0.5 0.4 0.5 1.1t-0.5 1.2z m-29.5 17.1l18.4-18.5 6.3 6.3-18.4 18.4h-6.3v-6.2z"></path></g></svg>Edit this page</a></div><div class="col text--right"><em><small class="docMetadata-updated">Last updated on <time datetime="2020-10-29T04:19:29.000Z" class="docLastUpdatedAt_1gIo">10/29/2020</time></small></em></div></div></div><div class="margin-vert--lg"><nav class="pagination-nav" aria-label="Blog list page navigation"><div class="pagination-nav__item"><a class="pagination-nav__link" href="/docs/0.60/height-and-width"><div class="pagination-nav__sublabel">Previous</div><div class="pagination-nav__label">« Height and Width</div></a></div><div class="pagination-nav__item pagination-nav__item--next"><a class="pagination-nav__link" href="/docs/0.60/handling-text-input"><div class="pagination-nav__sublabel">Next</div><div class="pagination-nav__label">Handling Text Input »</div></a></div></nav></div></div></div><div class="col col--3"><div class="tableOfContents_3iuQ"><ul class="table-of-contents table-of-contents__left-border"><li><a href="#flex" class="table-of-contents__link">Flex</a></li><li><a href="#layout-direction" class="table-of-contents__link">Layout Direction</a></li><li><a href="#align-self" class="table-of-contents__link">Align Self</a></li><li><a href="#align-content" class="table-of-contents__link">Align Content</a></li><li><a href="#flex-wrap" class="table-of-contents__link">Flex Wrap</a></li><li><a href="#flex-basis-grow-and-shrink" class="table-of-contents__link">Flex Basis, Grow, and Shrink</a></li><li><a href="#width-and-height" class="table-of-contents__link">Width and Height</a></li><li><a href="#absolute--relative-layout" class="table-of-contents__link">Absolute & Relative Layout</a></li></ul></div></div></div></div></main></div></div><footer class="footer footer--dark"><div class="container"><div class="row footer__links"><div class="col footer__col"><h4 class="footer__title">Docs</h4><ul class="footer__items"><li class="footer__item"><a class="footer__link-item" href="/docs/getting-started">Getting Started</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/tutorial">Tutorial</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/components-and-apis">Components and APIs</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/more-resources">More Resources</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">Community</h4><ul class="footer__items"><li class="footer__item"><a class="footer__link-item" href="/help">The React Native Community</a></li><li class="footer__item"><a class="footer__link-item" href="/showcase">Who's using React Native?</a></li><li class="footer__item"><a href="https://stackoverflow.com/questions/tagged/react-native" target="_blank" rel="noopener noreferrer" class="footer__link-item">Ask Questions on Stack Overflow</a></li><li class="footer__item"><a href="https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md" target="_blank" rel="noopener noreferrer" class="footer__link-item">Contributor Guide</a></li><li class="footer__item"><a href="https://dev.to/t/reactnative" target="_blank" rel="noopener noreferrer" class="footer__link-item">DEV Community</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">Find us</h4><ul class="footer__items"><li class="footer__item"><a class="footer__link-item" href="/blog">Blog</a></li><li class="footer__item"><a href="https://twitter.com/reactnative" target="_blank" rel="noopener noreferrer" class="footer__link-item">Twitter</a></li><li class="footer__item"><a href="https://github.com/facebook/react-native" target="_blank" rel="noopener noreferrer" class="footer__link-item">GitHub</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">More</h4><ul class="footer__items"><li class="footer__item"><a href="https://reactjs.org/" target="_blank" rel="noopener noreferrer" class="footer__link-item">React</a></li><li class="footer__item"><a href="https://opensource.facebook.com/legal/privacy" target="_blank" rel="noopener noreferrer" class="footer__link-item">Privacy Policy</a></li><li class="footer__item"><a href="https://opensource.facebook.com/legal/terms" target="_blank" rel="noopener noreferrer" class="footer__link-item">Terms of Service</a></li></ul></div></div><div class="text--center"><div class="margin-bottom--sm"><a href="https://opensource.facebook.com" target="_blank" rel="noopener noreferrer" class="footerLogoLink_19Ac"><img class="footer__logo" alt="Facebook Open Source Logo" src="/img/oss_logo.png"></a></div><div>Copyright © 2020 Facebook, Inc.</div></div></div></footer></div>
|
||
<script src="/styles.07d522c6.js"></script>
|
||
<script src="/runtime~main.373c7abc.js"></script>
|
||
<script src="/main.5a3c9855.js"></script>
|
||
<script src="/1.ba9ce8bd.js"></script>
|
||
<script src="/2.58cb5d3d.js"></script>
|
||
<script src="/1f391b9e.a824c215.js"></script>
|
||
<script src="/943.8b024446.js"></script>
|
||
<script src="/ae345423.971fbe80.js"></script>
|
||
<script src="/17896441.0c201679.js"></script>
|
||
<script src="/cf28e639.8c47799b.js"></script>
|
||
</body>
|
||
</html> |