forked from facebook/react-native-website
-
Notifications
You must be signed in to change notification settings - Fork 328
/
index.js
599 lines (568 loc) · 16 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
/**
* Copyright (c) Meta Platforms, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import React, {useEffect} from 'react';
import GitHubButton from 'react-github-btn';
import Head from '@docusaurus/Head';
import useBaseUrl from '@docusaurus/useBaseUrl';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import Layout from '@theme/Layout';
import CodeBlock from '@theme/CodeBlock';
import CrossPlatformSVG from '../../static/img/homepage/cross-platform.svg';
import {setupDissectionAnimation} from './animations/_dissectionAnimation';
import {setupHeaderAnimations} from './animations/_headerAnimation';
const textContent = {
intro: `
React Native combines the best parts of native development with React,
a best-in-class JavaScript library for building user interfaces.
<br/><br/>
<strong>Use a little—or a lot</strong>. You can use React Native today in your existing
Android and iOS projects or you can create a whole new app from scratch.
`,
nativeCode: `
React primitives render to native platform UI, meaning your app uses the
same native platform APIs other apps do.
<br/><br/>
<strong>Many platforms</strong>, one React. Create platform-specific versions of components
so a single codebase can share code across platforms. With React Native,
one team can maintain two platforms and share a common technology—React.
`,
codeExample: `
import React from 'react';
import {Text, View} from 'react-native';
import {Header} from './Header';
import {heading} from './Typography';
const WelcomeScreen = () => (
<View>
<Header title="Welcome to React Native"/>
<Text style={heading}>Step One</Text>
<Text>
Edit App.js to change this screen and turn it
into your app.
</Text>
<Text style={heading}>See Your Changes</Text>
<Text>
Press Cmd + R inside the simulator to reload
your app’s code.
</Text>
<Text style={heading}>Debug</Text>
<Text>
Press Cmd + M or Shake your device to open the
React Native Debug Menu.
</Text>
<Text style={heading}>Learn</Text>
<Text>
Read the docs to discover what to do next:
</Text>
</View>
);
`,
forEveryone: `
React Native lets you create truly native apps and doesn't compromise your users' experiences.
It provides a core set of platform agnostic native components like <code>View</code>, <code>Text</code>, and <code>Image</code>
that map directly to the platform’s native UI building blocks.
`,
crossPlatform: `
React components wrap existing native code and interact with native APIs via
React’s declarative UI paradigm and JavaScript. This enables native app development
for whole new teams of developers, and can let existing native teams work much faster.
`,
fastRefresh: `
<strong>See your changes as soon as you save.</strong> With the power of JavaScript,
React Native lets you iterate at lightning speed. No more waiting for native builds to finish.
Save, see, repeat.
`,
talks: `
Members of the React Native team frequently speak at various conferences.
<br/><br/>
You can follow the latest news from the React Native team on Twitter
`,
};
function Heading({text}) {
return <h2 className="Heading">{text}</h2>;
}
function ActionButton({href, type = 'primary', target, children}) {
return (
<a className={`ActionButton ${type}`} href={href} target={target}>
{children}
</a>
);
}
function TextColumn({title, text, moreContent}) {
return (
<>
<Heading text={title} />
<div dangerouslySetInnerHTML={{__html: text}} />
{moreContent}
</>
);
}
function HomeCallToAction() {
return (
<>
<ActionButton
type="primary"
href={useBaseUrl('docs/environment-setup')}
target="_self">
Get started
</ActionButton>
<ActionButton
type="secondary"
href={useBaseUrl('docs/getting-started')}
target="_self">
Learn the basics
</ActionButton>
</>
);
}
function TwitterButton({accountName}) {
return (
<a
href={`https://twitter.com/intent/follow?screen_name=${accountName}®ion=follow_link`}
className="twitter-follow-button">
<div className="icon" />
Follow @{accountName}
</a>
);
}
function GitHubStarButton() {
return (
<div className="github-button">
<GitHubButton
href="https://github.com/facebook/react-native"
data-icon="octicon-star"
data-size="large"
aria-label="Star facebook/react-native on GitHub">
Star
</GitHubButton>
</div>
);
}
export function Section({
element = 'section',
children,
className,
background = 'light',
}) {
const El = element;
return (
<El
className={
className
? `Section ${className} ${background}`
: `Section ${background}`
}>
{children}
</El>
);
}
function TwoColumns({columnOne, columnTwo, reverse}) {
return (
<div className={`TwoColumns ${reverse ? 'reverse' : ''}`}>
<div className={`column first ${reverse ? 'right' : 'left'}`}>
{columnOne}
</div>
<div className={`column last ${reverse ? 'left' : 'right'}`}>
{columnTwo}
</div>
</div>
);
}
function ScreenRect({className, fill, stroke}) {
return (
<rect
className={`screen ${className || ''}`}
rx="3%"
width="180"
height="300"
x="-90"
y="-150"
fill={fill}
stroke={stroke}
/>
);
}
function LogoAnimation() {
return (
<svg
className="LogoAnimation init"
width={350}
height={350}
xmlns="http://www.w3.org/2000/svg"
viewBox="-200 -200 400 400">
<title>React Logo</title>
<clipPath id="screen">
<ScreenRect fill="none" stroke="gray" />
</clipPath>
<rect
x="-25"
y="120"
width="50"
height="25"
rx="2"
fill="white"
stroke="none"
className="stand"
/>
<polygon
points="-125,90 125,90 160,145 -160,145"
fill="white"
stroke="white"
strokeWidth="5"
strokeLinejoin="round"
className="base"
/>
<ScreenRect className="background" stroke="none" />
<g clipPath="url(#screen)" className="logo">
<g className="logoInner">
<circle cx="0" cy="0" r="30" fill="#61dafb" />
<g stroke="#61dafb" strokeWidth="15" fill="none" id="logo">
<ellipse rx="165" ry="64" />
<ellipse rx="165" ry="64" transform="rotate(60)" />
<ellipse rx="165" ry="64" transform="rotate(120)" />
</g>
</g>
<line
x1="-30"
x2="30"
y1="130"
y2="130"
stroke="white"
strokeWidth="8"
strokeLinecap="round"
className="speaker"
/>
</g>
<ScreenRect fill="none" stroke="white" />
</svg>
);
}
function HeaderHero() {
return (
<Section background="dark" className="HeaderHero">
<div className="socialLinks">
<TwitterButton accountName="reactnative" />
<GitHubStarButton />
</div>
<TwoColumns
reverse
columnOne={<LogoAnimation />}
columnTwo={
<>
<h1 className="title">React Native</h1>
<p className="tagline">Learn once, write anywhere.</p>
<div className="buttons">
<HomeCallToAction />
</div>
</>
}
/>
</Section>
);
}
function NativeApps() {
return (
<Section className="NativeApps" background="light">
<TwoColumns
reverse
columnOne={
<TextColumn
title="Create native apps for Android and iOS using React"
text={textContent.intro}
/>
}
columnTwo={<img alt="" src={useBaseUrl('img/homepage/phones.png')} />}
/>
</Section>
);
}
function NativeCode() {
return (
<Section className="NativeCode" background="tint">
<TwoColumns
columnOne={
<TextColumn
title="Written in JavaScript—rendered with native code"
text={textContent.nativeCode}
/>
}
columnTwo={
<CodeBlock language="jsx">{textContent.codeExample}</CodeBlock>
}
/>
</Section>
);
}
function NativeDevelopment() {
return (
<Section className="NativeDevelopment" background="light">
<TwoColumns
reverse
columnOne={
<TextColumn
title="Native Development For Everyone"
text={textContent.forEveryone}
/>
}
columnTwo={
<div className="dissection">
{[0, 1, 2, 3].map(i => (
<img
alt=""
key={i}
src={useBaseUrl(`img/homepage/dissection/${i}.png`)}
/>
))}
</div>
}
/>
</Section>
);
}
function CrossPlatform() {
return (
<Section className="CrossPlatform" background="tint">
<TwoColumns
columnOne={
<TextColumn
title="Seamless Cross-Platform"
text={textContent.crossPlatform}
/>
}
columnTwo={<CrossPlatformSVG />}
/>
</Section>
);
}
function FastRefresh() {
return (
<Section className="FastRefresh" background="light">
<TwoColumns
reverse
columnOne={
<TextColumn title="Fast Refresh" text={textContent.fastRefresh} />
}
columnTwo={
<video
muted
autoPlay
loop
playsInline
src={useBaseUrl(`img/homepage/ReactRefresh.mp4`)}
/>
}
/>
</Section>
);
}
function VideoContent() {
return (
<div>
<Section className="VideoContent" background="tint">
<br />
<TwoColumns
columnOne={
<TextColumn
title="Talks and Videos"
text={textContent.talks}
moreContent={<TwitterButton accountName="reactnative" />}
/>
}
columnTwo={
<div className="vidWrapper">
<iframe
src="https://www.youtube.com/embed/NCAY0HIfrwc"
title="Mobile Innovation with React Native, ComponentKit, and Litho"
frameBorder="0"
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
allowFullScreen
/>
</div>
}
/>
<br />
<TwoColumns
columnOne={
<>
<p>
The{' '}
<a href="https://opensource.facebook.com/">
Meta Open Source team
</a>{' '}
has put together a short overview of React Native, where they
explained the project in beginner's terms.
</p>
</>
}
columnTwo={
<div className="vidWrapper">
<iframe
src="https://www.youtube.com/embed/wUDeLT6WXnQ"
title="Explain Like I'm 5: React Native"
frameBorder="0"
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
allowFullScreen
/>
</div>
}
/>
</Section>
</div>
);
}
/* Community */
function AppList() {
const {siteConfig} = useDocusaurusContext();
const apps = Object.values(siteConfig.customFields.users)
.flat()
.filter(app => app.pinned);
return (
<ul className="AppList">
{apps.map((app, i) => {
const imgSource = !app.icon.startsWith('http')
? useBaseUrl('img/showcase/' + app.icon)
: app.icon;
return (
<li key={i} className="item">
{app.infoLink ? (
<a href={app.infoLink}>
<img src={imgSource} alt={app.name} />
</a>
) : (
<img src={imgSource} alt={app.name} />
)}
</li>
);
})}
</ul>
);
}
function Community() {
return (
<Section className="Community" background="light">
<div className="content">
<Heading text="Facebook Supported, Community Driven" />
<TwoColumns
columnOne={
<>
<p className="firstP">
<img src={useBaseUrl(`img/homepage/fb-logo.svg`)} alt="" />
<span>
Facebook released React Native in 2015 and has been
maintaining it ever since.
</span>
</p>
<p>
In 2018, React Native had the{' '}
<a href="https://octoverse.github.com/2018/projects#repositories">
2nd highest
</a>{' '}
number of contributors for any repository in GitHub. Today,
React Native is supported by contributions from individuals and
companies around the world including{' '}
<span>
<a href="https://callstack.com/">Callstack</a>
</span>
,{' '}
<span>
<a href="https://expo.io/">Expo</a>
</span>
, <a href="https://infinite.red/">Infinite Red</a>,{' '}
<a href="https://www.microsoft.com/">Microsoft</a> and{' '}
<a href="https://swmansion.com/">Software Mansion</a>.
</p>
<p>
Our community is always shipping exciting new projects and
exploring platforms beyond Android and iOS with repos like{' '}
<span>
<a href="https://github.com/microsoft/react-native-windows#readme">
React Native Windows
</a>
</span>
,{' '}
<a href="https://github.com/microsoft/react-native-macos#readme">
React Native macOS
</a>{' '}
and{' '}
<a href="https://github.com/necolas/react-native-web#readme">
React Native Web
</a>
.
</p>
</>
}
columnTwo={
<>
<p>
React Native is being used in thousands of apps, but it's likely
you've already used it in one of these apps:
</p>
<AppList />
<p>
and <a href={useBaseUrl(`showcase`)}>many more</a>.
</p>
</>
}
/>
</div>
</Section>
);
}
function GetStarted() {
return (
<Section className="GetStarted" background="dark">
<div className="content">
<Heading text="Give it a try" />
<ol className="steps">
<li>
<p>Run this</p>
<div className="terminal">
<code>npx react-native init MyTestApp</code>
</div>
</li>
<li>
<p>Read these</p>
<HomeCallToAction />
</li>
</ol>
</div>
</Section>
);
}
const useHomePageAnimations = () => {
useEffect(() => setupHeaderAnimations(), []);
useEffect(() => setupDissectionAnimation(), []);
};
const Index = () => {
useHomePageAnimations();
return (
<Layout
description="A framework for building native apps using React"
wrapperClassName="homepage">
<Head>
<title>React Native · Learn once, write anywhere</title>
<meta
property="og:title"
content="React Native · Learn once, write anywhere"
/>
<meta
property="twitter:title"
content="React Native · Learn once, write anywhere"
/>
</Head>
<HeaderHero />
<NativeApps />
<NativeCode />
<NativeDevelopment />
<CrossPlatform />
<FastRefresh />
<VideoContent />
<Community />
<GetStarted />
</Layout>
);
};
export default Index;