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

Created new React Native Components entry #1269

Merged
merged 16 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
---
Title: 'React Native Components'
ericsonrd marked this conversation as resolved.
Show resolved Hide resolved
Description: 'Bundles of reusable, nestable code used to describe the appearance and behavior of a UI.'
ericsonrd marked this conversation as resolved.
Show resolved Hide resolved
Subjects:
- 'Mobile Development'
Tags:
- 'Components'
- 'React Native'
- 'UI'
CatalogContent:
- 'learn-react-native'
- 'paths/front-end-engineer-career-path'
---

**React Native Components** are bundles of reusable, nestable code used to describe the appearance and behavior of a User Interface (UI).
ericsonrd marked this conversation as resolved.
Show resolved Hide resolved

## UI Views

The basic building block of a **UI** is the **View,** a small, rectangular and often times nestable element that can be used to display text, images and respond to user input. React Native works by invoking these Views in their native environment with JavaScript, using React Components.
yangc95 marked this conversation as resolved.
Show resolved Hide resolved

![React Native to Native Ui Representation](../../../../../media/react_native_UI_Views.png)
yangc95 marked this conversation as resolved.
Show resolved Hide resolved

## Native Components

These previously mentioned platform-backed components are called **Native Components,** and React Native creates the corresponding, platform specific Views (whether iOS or Android) for these components at runtime. Because of this, React Native apps look, feel and perform like Native apps.
yangc95 marked this conversation as resolved.
Show resolved Hide resolved

## Core Components

React Native offers a set of essential, ready-to-use Native Components called **Core Components.** There are many components ranging from Text to Activity Indicators. Most apps will use these Core Components:
yangc95 marked this conversation as resolved.
Show resolved Hide resolved

| React Native Component | Description |
Copy link
Contributor

@Dusch4593 Dusch4593 Dec 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| React Native Component | Description |
| Native Component | Description |

| --- | --- |
| \<View> | Is a container analog to a \<div> in html. It supports layout with flexbox, styles, touch handling, accessibility controls and can contain other components inside, including other views. |
| \<Text> | Displays text, support styles and touch events. It can also nest other Text components. |
| \<Image> | Displays different types of images, including from network, static, local disks and from ‘data:’ uri scheme. |
| \<TextInput> | Allows the input of text by the user and provides several configuration capabilities such as auto-correction, auto-capitalization, placeholder text, etc. |
|\<ScrollView> | An scrolling container that can nest multiple components and views. It can scroll vertically or horizontally. |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| \<View> | Is a container analog to a \<div> in html. It supports layout with flexbox, styles, touch handling, accessibility controls and can contain other components inside, including other views. |
| \<Text> | Displays text, support styles and touch events. It can also nest other Text components. |
| \<Image> | Displays different types of images, including from network, static, local disks and from ‘data:’ uri scheme. |
| \<TextInput> | Allows the input of text by the user and provides several configuration capabilities such as auto-correction, auto-capitalization, placeholder text, etc. |
|\<ScrollView> | An scrolling container that can nest multiple components and views. It can scroll vertically or horizontally. |
| `<View>` | A common container component that supports layout with flexbox, styles, touch handling, accessibility controls, and can contain other components inside such as other views. It is analogous to a non-scrolling [`<div>`](https://www.codecademy.com/resources/docs/html/elements/div) HTML element. |
| `<Text>` | Displays text and supports styles and touch events. It is analogous to a [paragraph element](https://www.codecademy.com/resources/docs/html/paragraphs). |
| `<Image>` | Displays different types of images, including from network, static, local disks, and from ‘data:’ [URI](https://www.codecademy.com/resources/docs/general/uri) scheme. It is analogous to an [image element](https://www.codecademy.com/resources/docs/html/images). |
| `<TextInput>` | Allows the input of text by the user and provides several configuration capabilities such as auto-correction, auto-capitalization, placeholder text, etc. It is analogous to an [`<input>`] element with its `type` attribute set to `"text"`. |
| `<ScrollView>` | A container that can nest multiple components and views that can scroll vertically or horizontally. It is analogous to a scrolling `div` element. |


## Community Components

React Native Componens can also be custom-built, and there’s a big ecosystem of these Community-built Components that can be accessed on the [**Native Directory**](https://reactnative.directory/)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
React Native Componens can also be custom-built, and there’s a big ecosystem of these Community-built Components that can be accessed on the [**Native Directory**](https://reactnative.directory/)
React Native Components can also be custom-built, and there’s a big ecosystem of these Community-built Components that can be accessed on the [Native Directory](https://reactnative.directory/)


## React Native Components are based on React

![React and React Native Components](../../../../../media/react_react_native_components.png)
yangc95 marked this conversation as resolved.
Show resolved Hide resolved

React Native Components share the same API structure as **React Components.** Whatever a component returns is rendered as a React element, which allows to describe what’s seen on the screen. They can also be defined as ***Function Component*** or ***Class Components:***
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
React Native Components share the same API structure as **React Components.** Whatever a component returns is rendered as a React element, which allows to describe what’s seen on the screen. They can also be defined as ***Function Component*** or ***Class Components:***
React Native Components share the same API structure as React Components. Whatever a component returns is rendered as a React element, which allows to describe what’s seen on the screen. They can also be defined as Function Component or Class Components:


- #### Function Component:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- #### Function Component:
### Function Component:

```jsx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```jsx
```jsx

import React from 'react';
import { Text } from 'react-native';

const Box = () => {
return (
<Text>I have a small box</Text>
);
}

export default Box;
```
Try this code example [HERE.](https://snack.expo.dev/@ericsonrd/rn-function-component)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Try this code example [HERE.](https://snack.expo.dev/@ericsonrd/rn-function-component)
Try this code example [here.](https://snack.expo.dev/@ericsonrd/rn-function-component)


- #### Class Component:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- #### Class Component:
### Class Component:

```jsx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```jsx
```jsx

import React, { Component } from "react";
import { Text } from 'react-native';

class Box extends Component {
render() {
return (
<Text>I have a small box</Text>
);
}
}

export default Box;
```
Try this code example [HERE.](https://snack.expo.dev/@ericsonrd/rn-class-component)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Try this code example [HERE.](https://snack.expo.dev/@ericsonrd/rn-class-component)
Try this code example [here.](https://snack.expo.dev/@ericsonrd/rn-class-component)



## JSX, Props and State.

React Native Components also use **JSX,** accept **Props** and manage **State.**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
React Native Components also use **JSX,** accept **Props** and manage **State.**
React Native Components also use JSX, accept Props and manage State.


- ### JSX
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- ### JSX
### JSX

As in React, the JSX syntax in React Native allows writing elements inside JavaScript, and also the use of variables inside them:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
As in React, the JSX syntax in React Native allows writing elements inside JavaScript, and also the use of variables inside them:
As in React, the JSX syntax in React Native allows writing elements inside JavaScript, and also the use of variables inside them:


```jsx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```jsx
``jsx

import React from 'react';
import { Text } from 'react-native';

const Box = () => {
const size = “small”;
return (
<Text>I have a {size} box</Text>
);
}

export default Box;
```
Try this code example [HERE.](https://snack.expo.dev/@ericsonrd/rn-component-jsx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Try this code example [HERE.](https://snack.expo.dev/@ericsonrd/rn-component-jsx)
Try this code example [here.](https://snack.expo.dev/@ericsonrd/rn-component-jsx)


- ### Props
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- ### Props
### Props

Most React Native Core Components accept Props, for example, you can pass different sizes via Props to this Box component:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Most React Native Core Components accept Props, for example, you can pass different sizes via Props to this Box component:
Most React Native Core Components accept Props, for example, you can pass different sizes via Props to this Box component:

```jsx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```jsx
```jsx

import React from 'react';
import { View, Text } from 'react-native';

const Box = (props) => {
return (
<Text>I have a {props.size} box</Text>
);
}

const BoxCollection = () => {
return (
<View>
<Box size=“small” />
<Box size=“medium” />
<Box size=“large” />
</View>
);
}

export default BoxCollection;
```
Try this code example [HERE.](https://snack.expo.dev/@ericsonrd/rn-component-props)
yangc95 marked this conversation as resolved.
Show resolved Hide resolved

- ### State
yangc95 marked this conversation as resolved.
Show resolved Hide resolved
Just like React, React Native Components use State to handle data that changes over time, such as with user interaction:
yangc95 marked this conversation as resolved.
Show resolved Hide resolved
```js
yangc95 marked this conversation as resolved.
Show resolved Hide resolved
import React, { useState } from "react";
import { View, Text, Button } from "react-native";

const Box = () => {
const [size, setSize] = useState("small");
return (
<View>
<Text>I have a {size} box </Text>
<Button
color="red"
onPress={() => setSize("small")}
title="Small" />
<Button
color="blue"
onPress={() => setSize("medium")}
title="Medium" />
<Button
color="orange"
onPress={() => setSize("large")}
title="Large" />
</View>
);
}

export default Box;
```
Try this code example [HERE.](https://snack.expo.dev/@ericsonrd/rn-component-state)
yangc95 marked this conversation as resolved.
Show resolved Hide resolved
Binary file added media/react_native_UI_Views.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/react_react_native_components.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.