Skip to content

Commit d2d23a0

Browse files
committed
Merge remote-tracking branch 'upstream/main' into production
2 parents 3ad7487 + f5bb54d commit d2d23a0

62 files changed

Lines changed: 297 additions & 346 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/debugging-native-code.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ adb logcat "*:S" ReactNative:V ReactNativeJS:V YourModuleName:D
5050

5151
In your native module, use `NSLog` for custom logs:
5252

53-
```objective-c
53+
```objectivec
5454
NSLog(@"YourModuleName: %@", message);
5555
```
5656

docs/images.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ You can use the `@2x` and `@3x` suffixes to provide images for different screen
3030
<Image source={require('./img/check.png')} />
3131
```
3232

33-
...the bundler will bundle and serve the image corresponding to device's screen density. For example, `check@2x.png`, will be used on an iPhone 7, while`check@3x.png` will be used on an iPhone 7 Plus or a Nexus 5. If there is no image matching the screen density, the closest best option will be selected.
33+
...the bundler will bundle and serve the image corresponding to device's screen density. For example, `check@2x.png`, will be used on an iPhone 7, while `check@3x.png` will be used on an iPhone 7 Plus or a Nexus 5. If there is no image matching the screen density, the closest best option will be selected.
3434

3535
On Windows, you might need to restart the bundler if you add new images to your project.
3636

docs/intro-react.md

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ If you want to dig deeper, we encourage you to check out [React’s official doc
2222
The rest of this introduction to React uses cats in its examples: friendly, approachable creatures that need names and a cafe to work in. Here is your very first Cat component:
2323

2424
```SnackPlayer name=Your%20Cat
25-
import React from 'react';
2625
import {Text} from 'react-native';
2726
2827
const Cat = () => {
@@ -32,10 +31,9 @@ const Cat = () => {
3231
export default Cat;
3332
```
3433

35-
Here is how you do it: To define your `Cat` component, first use JavaScript’s [`import`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) to import React and React Native’s [`Text`](/docs/next/text) Core Component:
34+
Here is how you do it: To define your `Cat` component, first use JavaScript’s [`import`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) to import React Native’s [`Text`](/docs/next/text) Core Component:
3635

3736
```tsx
38-
import React from 'react';
3937
import {Text} from 'react-native';
4038
```
4139

@@ -76,7 +74,6 @@ Now take a closer look at that `return` statement. `<Text>Hello, I am your cat!<
7674
React and React Native use **JSX,** a syntax that lets you write elements inside JavaScript like so: `<Text>Hello, I am your cat!</Text>`. The React docs have [a comprehensive guide to JSX](https://react.dev/learn/writing-markup-with-jsx) you can refer to learn even more. Because JSX is JavaScript, you can use variables inside it. Here you are declaring a name for the cat, `name`, and embedding it with curly braces inside `<Text>`.
7775

7876
```SnackPlayer name=Curly%20Braces
79-
import React from 'react';
8077
import {Text} from 'react-native';
8178
8279
const Cat = () => {
@@ -93,7 +90,6 @@ Any JavaScript expression will work between curly braces, including function cal
9390
<TabItem value="javascript">
9491

9592
```SnackPlayer name=Curly%20Braces&ext=js
96-
import React from 'react';
9793
import {Text} from 'react-native';
9894
9995
const getFullName = (firstName, secondName, thirdName) => {
@@ -111,7 +107,6 @@ export default Cat;
111107
<TabItem value="typescript">
112108

113109
```SnackPlayer name=Curly%20Braces&ext=tsx
114-
import React from 'react';
115110
import {Text} from 'react-native';
116111
117112
const getFullName = (
@@ -134,18 +129,13 @@ export default Cat;
134129

135130
You can think of curly braces as creating a portal into JS functionality in your JSX!
136131

137-
:::tip
138-
Because JSX is included in the React library, it won’t work if you don’t have `import React from 'react'` at the top of your file!
139-
:::
140-
141132
## Custom Components
142133

143134
You’ve already met [React Native’s Core Components](intro-react-native-components). React lets you nest these components inside each other to create new components. These nestable, reusable components are at the heart of the React paradigm.
144135

145136
For example, you can nest [`Text`](text) and [`TextInput`](textinput) inside a [`View`](view) below, and React Native will render them together:
146137

147138
```SnackPlayer name=Custom%20Components
148-
import React from 'react';
149139
import {Text, TextInput, View} from 'react-native';
150140
151141
const Cat = () => {
@@ -190,7 +180,6 @@ On Android, you usually put your views inside `LinearLayout`, `FrameLayout`, `Re
190180
You can render this component multiple times and in multiple places without repeating your code by using `<Cat>`:
191181

192182
```SnackPlayer name=Multiple%20Components
193-
import React from 'react';
194183
import {Text, View} from 'react-native';
195184
196185
const Cat = () => {
@@ -227,7 +216,6 @@ You can put as many cats in your cafe as you like. Each `<Cat>` renders a unique
227216
<TabItem value="javascript">
228217

229218
```SnackPlayer name=Multiple%20Props&ext=js
230-
import React from 'react';
231219
import {Text, View} from 'react-native';
232220
233221
const Cat = props => {
@@ -255,7 +243,6 @@ export default Cafe;
255243
<TabItem value="typescript">
256244

257245
```SnackPlayer name=Multiple%20Props&ext=tsx
258-
import React from 'react';
259246
import {Text, View} from 'react-native';
260247
261248
type CatProps = {
@@ -289,7 +276,6 @@ export default Cafe;
289276
Most of React Native’s Core Components can be customized with props, too. For example, when using [`Image`](image), you pass it a prop named [`source`](image#source) to define what image it shows:
290277

291278
```SnackPlayer name=Props
292-
import React from 'react';
293279
import {Text, View, Image} from 'react-native';
294280
295281
const CatApp = () => {
@@ -333,7 +319,7 @@ You can add state to a component by calling [React’s `useState` Hook](https://
333319
<TabItem value="javascript">
334320

335321
```SnackPlayer name=State&ext=js
336-
import React, {useState} from 'react';
322+
import {useState} from 'react';
337323
import {Button, Text, View} from 'react-native';
338324
339325
const Cat = props => {
@@ -371,7 +357,7 @@ export default Cafe;
371357
<TabItem value="typescript">
372358

373359
```SnackPlayer name=State&ext=tsx
374-
import React, {useState} from 'react';
360+
import {useState} from 'react';
375361
import {Button, Text, View} from 'react-native';
376362
377363
type CatProps = {
@@ -415,7 +401,7 @@ export default Cafe;
415401
First, you will want to import `useState` from React like so:
416402

417403
```tsx
418-
import React, {useState} from 'react';
404+
import {useState} from 'react';
419405
```
420406

421407
Then you declare the component’s state by calling `useState` inside its function. In this example, `useState` creates an `isHungry` state variable:

docs/network.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ React Native provides the [Fetch API](https://developer.mozilla.org/en-US/docs/W
1515

1616
In order to fetch content from an arbitrary URL, you can pass the URL to fetch:
1717

18-
```tsx
18+
```ts
1919
fetch('https://mywebsite.com/mydata.json');
2020
```
2121

2222
Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:
2323

24-
```tsx
24+
```ts
2525
fetch('https://mywebsite.com/endpoint/', {
2626
method: 'POST',
2727
headers: {
@@ -43,7 +43,7 @@ The above examples show how you can make a request. In many cases, you will want
4343

4444
Networking is an inherently asynchronous operation. Fetch method will return a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that makes it straightforward to write code that works in an asynchronous manner:
4545

46-
```tsx
46+
```ts
4747
const getMoviesFromApi = () => {
4848
return fetch('https://reactnative.dev/movies.json')
4949
.then(response => response.json())
@@ -58,7 +58,7 @@ const getMoviesFromApi = () => {
5858

5959
You can also use the `async` / `await` syntax in a React Native app:
6060

61-
```tsx
61+
```ts
6262
const getMoviesFromApiAsync = async () => {
6363
try {
6464
const response = await fetch(
@@ -199,7 +199,7 @@ On Android, as of API Level 28, clear text traffic is also blocked by default. T
199199

200200
The [XMLHttpRequest API](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) is built into React Native. This means that you can use third party libraries such as [frisbee](https://github.com/niftylettuce/frisbee) or [axios](https://github.com/axios/axios) that depend on it, or you can use the XMLHttpRequest API directly if you prefer.
201201

202-
```tsx
202+
```ts
203203
const request = new XMLHttpRequest();
204204
request.onreadystatechange = e => {
205205
if (request.readyState !== 4) {
@@ -225,7 +225,7 @@ The security model for XMLHttpRequest is different than on web as there is no co
225225

226226
React Native also supports [WebSockets](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket), a protocol which provides full-duplex communication channels over a single TCP connection.
227227

228-
```tsx
228+
```ts
229229
const ws = new WebSocket('ws://host.com/path');
230230

231231
ws.onopen = () => {

docs/timers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ One reason why well-built native apps feel so smooth is by avoiding expensive op
3333

3434
Applications can schedule tasks to run after interactions with the following:
3535

36-
```tsx
36+
```ts
3737
InteractionManager.runAfterInteractions(() => {
3838
// ...long-running synchronous task...
3939
});
@@ -49,7 +49,7 @@ The touch handling system considers one or more active touches to be an 'interac
4949

5050
`InteractionManager` also allows applications to register animations by creating an interaction 'handle' on animation start, and clearing it upon completion:
5151

52-
```tsx
52+
```ts
5353
const handle = InteractionManager.createInteractionHandle();
5454
// run animation... (`runAfterInteractions` tasks are queued)
5555
// later, on animation completion:

plugins/remark-codeblock-language-as-title/src/index.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,44 @@
77

88
import {Root} from 'mdast';
99

10+
const LANGUAGES_MAP: Record<string, string> = {
11+
js: 'JavaScript',
12+
javascript: 'JavaScript',
13+
ts: 'TypeScript',
14+
typescript: 'TypeScript',
15+
jsx: 'React JSX',
16+
tsx: 'React TSX',
17+
json: 'JSON',
18+
objc: 'Objective-C',
19+
objectivec: 'Objective-C',
20+
xml: 'XML',
21+
css: 'CSS',
22+
cpp: 'C++',
23+
};
24+
25+
const HIDDEN_TITLES = ['zsh', 'sh', 'shell', 'bash', 'powershell'];
26+
27+
function capitalizeFirstLetter(str: string | null) {
28+
if (!str) {
29+
return str;
30+
}
31+
return str[0].toUpperCase() + str.slice(1);
32+
}
33+
1034
export default function codeblockLanguageAsTitleRemarkPlugin() {
1135
return async (root: Root) => {
1236
const {visit} = await import('unist-util-visit');
1337
visit(root, 'code', node => {
14-
if (node.lang && !['shell', 'bash'].includes(node.lang)) {
38+
if (node.lang && !HIDDEN_TITLES.includes(node.lang)) {
39+
const formattedTitle =
40+
LANGUAGES_MAP[node.lang] ?? capitalizeFirstLetter(node.lang);
1541
if (node.meta) {
1642
if (node.meta.includes('title=')) {
1743
return;
1844
}
19-
node.meta = `title="${node.lang}" ${node.meta}`;
45+
node.meta = `title="${formattedTitle}" ${node.meta}`;
2046
} else {
21-
node.meta = `title="${node.lang}"`;
47+
node.meta = `title="${formattedTitle}"`;
2248
}
2349
}
2450
});

website/architecture/bundled-hermes.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ To implement this on Android, we've added a new build inside the `/ReactAndroid/
119119
You can now trigger a build of Hermes engine by invoking:
120120

121121
```bash
122-
// Build a debug version of Hermes
122+
# Build a debug version of Hermes
123123
./gradlew :ReactAndroid:hermes-engine:assembleDebug
124-
// Build a release version of Hermes
124+
# Build a release version of Hermes
125125
./gradlew :ReactAndroid:hermes-engine:assembleRelease
126126
```
127127

@@ -133,7 +133,7 @@ On the Gradle consumer side, we also shipped a small improvement on the consumer
133133

134134
However, this made this line necessary in the template:
135135

136-
```
136+
```groovy
137137
exclude group:'com.facebook.fbjni'
138138
```
139139

website/versioned_docs/version-0.77/debugging-native-code.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ adb logcat "*:S" ReactNative:V ReactNativeJS:V YourModuleName:D
5050

5151
In your native module, use `NSLog` for custom logs:
5252

53-
```objective-c
53+
```objectivec
5454
NSLog(@"YourModuleName: %@", message);
5555
```
5656

website/versioned_docs/version-0.77/images.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ You can use the `@2x` and `@3x` suffixes to provide images for different screen
3030
<Image source={require('./img/check.png')} />
3131
```
3232

33-
...the bundler will bundle and serve the image corresponding to device's screen density. For example, `check@2x.png`, will be used on an iPhone 7, while`check@3x.png` will be used on an iPhone 7 Plus or a Nexus 5. If there is no image matching the screen density, the closest best option will be selected.
33+
...the bundler will bundle and serve the image corresponding to device's screen density. For example, `check@2x.png`, will be used on an iPhone 7, while `check@3x.png` will be used on an iPhone 7 Plus or a Nexus 5. If there is no image matching the screen density, the closest best option will be selected.
3434

3535
On Windows, you might need to restart the bundler if you add new images to your project.
3636

0 commit comments

Comments
 (0)