Skip to content

Commit

Permalink
Update examples in docs and address version lag of CRNA
Browse files Browse the repository at this point in the history
Summary:
cc hramos

Pretty sure I've hit all of the places where AppRegistry is called in CRNA-pastable examples. Let me know whether you think we need to approach the version lag differently, I figure a caveat is as natural a place to call it out as any.

If you end up finding anything else that needs tweaking before cherry picking, I'm happy to push that up here too.
Closes #13744

Differential Revision: D5071038

Pulled By: hramos

fbshipit-source-id: 4a4a6f2a73079aca627f17d75a4e4b395ecbd4a8
  • Loading branch information
anp authored and facebook-github-bot committed May 17, 2017
1 parent af94987 commit ca2d57c
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 32 deletions.
8 changes: 4 additions & 4 deletions Libraries/Components/TextInput/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const DataDetectorTypes = [
* import React, { Component } from 'react';
* import { AppRegistry, TextInput } from 'react-native';
*
* class UselessTextInput extends Component {
* export default class UselessTextInput extends Component {
* constructor(props) {
* super(props);
* this.state = { text: 'Useless Placeholder' };
Expand All @@ -91,7 +91,7 @@ const DataDetectorTypes = [
* }
* }
*
* // App registration and rendering
* // skip this line if using Create React Native App
* AppRegistry.registerComponent('AwesomeProject', () => UselessTextInput);
* ```
*
Expand All @@ -117,7 +117,7 @@ const DataDetectorTypes = [
* }
* }
*
* class UselessTextInputMultiline extends Component {
* export default class UselessTextInputMultiline extends Component {
* constructor(props) {
* super(props);
* this.state = {
Expand Down Expand Up @@ -145,7 +145,7 @@ const DataDetectorTypes = [
* }
* }
*
* // App registration and rendering
* // skip these lines if using Create React Native App
* AppRegistry.registerComponent(
* 'AwesomeProject',
* () => UselessTextInputMultiline
Expand Down
10 changes: 5 additions & 5 deletions Libraries/Image/Image.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const ImageViewManager = NativeModules.ImageViewManager;
* import React, { Component } from 'react';
* import { AppRegistry, View, Image } from 'react-native';
*
* class DisplayAnImage extends Component {
* export default class DisplayAnImage extends Component {
* render() {
* return (
* <View>
Expand All @@ -57,7 +57,7 @@ const ImageViewManager = NativeModules.ImageViewManager;
* }
* }
*
* // App registration and rendering
* // skip this line if using Create React Native App
* AppRegistry.registerComponent('DisplayAnImage', () => DisplayAnImage);
* ```
*
Expand All @@ -74,7 +74,7 @@ const ImageViewManager = NativeModules.ImageViewManager;
* }
* });
*
* class DisplayAnImageWithStyle extends Component {
* export default class DisplayAnImageWithStyle extends Component {
* render() {
* return (
* <View>
Expand All @@ -87,7 +87,7 @@ const ImageViewManager = NativeModules.ImageViewManager;
* }
* }
*
* // App registration and rendering
* // skip these lines if using Create React Native App
* AppRegistry.registerComponent(
* 'DisplayAnImageWithStyle',
* () => DisplayAnImageWithStyle
Expand All @@ -96,7 +96,7 @@ const ImageViewManager = NativeModules.ImageViewManager;
*
* ### GIF and WebP support on Android
*
* By default, GIF and WebP are not supported on Android.
* When building your own native code, GIF and WebP are not supported by default on Android.
*
* You will need to add some optional modules in `android/app/build.gradle`, depending on the needs of your app.
*
Expand Down
4 changes: 2 additions & 2 deletions Libraries/Text/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const viewConfig = {
* import React, { Component } from 'react';
* import { AppRegistry, Text, StyleSheet } from 'react-native';
*
* class TextInANest extends Component {
* export default class TextInANest extends Component {
* constructor(props) {
* super(props);
* this.state = {
Expand Down Expand Up @@ -90,7 +90,7 @@ const viewConfig = {
* },
* });
*
* // App registration and rendering
* // skip this line if using Create React Native App
* AppRegistry.registerComponent('TextInANest', () => TextInANest);
* ```
*/
Expand Down
2 changes: 2 additions & 0 deletions docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Once you've created your project and opened it in the Expo client app, you can p

### Caveats

The Expo client app usually releases about 1 week after any given React Native release, and Create React Native App always provides the latest version of React Native which is supported by the Expo client. You can check [this document](https://github.com/react-community/create-react-native-app/blob/master/VERSIONS.md) to find out what versions are supported.

Because you don't build any native code with Create React Native App, it's not possible to include custom native modules beyond the React Native APIs and components that are available in the Expo client app.

If you know that you'll eventually need to include your own native code, Create React Native App is still a good way to get started. In that case you'll just need to "[eject](https://github.com/react-community/create-react-native-app/blob/master/react-native-scripts/template/README.md#ejecting-from-create-react-native-app)" eventually to create your own native builds. If you do eject, the native build instructions below will be required to continue working on your project.
Expand Down
3 changes: 2 additions & 1 deletion docs/HandlingTextInput.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ as "🍕🍕🍕".
import React, { Component } from 'react';
import { AppRegistry, Text, TextInput, View } from 'react-native';
class PizzaTranslator extends Component {
export default class PizzaTranslator extends Component {
constructor(props) {
super(props);
this.state = {text: ''};
Expand All @@ -40,6 +40,7 @@ class PizzaTranslator extends Component {
}
}
// skip this line if using Create React Native App
AppRegistry.registerComponent('PizzaTranslator', () => PizzaTranslator);
```

Expand Down
6 changes: 4 additions & 2 deletions docs/HeightAndWidth.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The simplest way to set the dimensions of a component is by adding a fixed `widt
import React, { Component } from 'react';
import { AppRegistry, View } from 'react-native';
class FixedDimensionsBasics extends Component {
export default class FixedDimensionsBasics extends Component {
render() {
return (
<View>
Expand All @@ -30,6 +30,7 @@ class FixedDimensionsBasics extends Component {
}
}
// skip this line if using Create React Native App
AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
```

Expand All @@ -45,7 +46,7 @@ Use `flex` in a component's style to have the component expand and shrink dynami
import React, { Component } from 'react';
import { AppRegistry, View } from 'react-native';
class FlexDimensionsBasics extends Component {
export default class FlexDimensionsBasics extends Component {
render() {
return (
// Try removing the `flex: 1` on the parent View.
Expand All @@ -60,6 +61,7 @@ class FlexDimensionsBasics extends Component {
}
}
// skip this line if using Create React Native App
AppRegistry.registerComponent('AwesomeProject', () => FlexDimensionsBasics);
```

Expand Down
9 changes: 6 additions & 3 deletions docs/LayoutWithFlexbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Adding `flexDirection` to a component's `style` determines the **primary axis**
import React, { Component } from 'react';
import { AppRegistry, View } from 'react-native';
class FlexDirectionBasics extends Component {
export default class FlexDirectionBasics extends Component {
render() {
return (
// Try setting `flexDirection` to `column`.
Expand All @@ -35,6 +35,7 @@ class FlexDirectionBasics extends Component {
}
};
// skip this line if using Create React Native App
AppRegistry.registerComponent('AwesomeProject', () => FlexDirectionBasics);
```

Expand All @@ -46,7 +47,7 @@ Adding `justifyContent` to a component's style determines the **distribution** o
import React, { Component } from 'react';
import { AppRegistry, View } from 'react-native';
class JustifyContentBasics extends Component {
export default class JustifyContentBasics extends Component {
render() {
return (
// Try setting `justifyContent` to `center`.
Expand All @@ -64,6 +65,7 @@ class JustifyContentBasics extends Component {
}
};
// skip this line if using Create React Native App
AppRegistry.registerComponent('AwesomeProject', () => JustifyContentBasics);
```

Expand All @@ -77,7 +79,7 @@ Adding `alignItems` to a component's style determines the **alignment** of child
import React, { Component } from 'react';
import { AppRegistry, View } from 'react-native';
class AlignItemsBasics extends Component {
export default class AlignItemsBasics extends Component {
render() {
return (
// Try setting `alignItems` to 'flex-start'
Expand All @@ -97,6 +99,7 @@ class AlignItemsBasics extends Component {
}
};
// skip this line if using Create React Native App
AppRegistry.registerComponent('AwesomeProject', () => AlignItemsBasics);
```

Expand Down
6 changes: 4 additions & 2 deletions docs/Props.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ create an image, you can use a prop named `source` to control what image it show
import React, { Component } from 'react';
import { AppRegistry, Image } from 'react-native';
class Bananas extends Component {
export default class Bananas extends Component {
render() {
let pic = {
uri: 'https://upload.wikimedia.org/wikipedia/commons/d/de/Bananavarieties.jpg'
Expand All @@ -28,6 +28,7 @@ class Bananas extends Component {
}
}
// skip this line if using Create React Native App
AppRegistry.registerComponent('Bananas', () => Bananas);
```

Expand All @@ -49,7 +50,7 @@ class Greeting extends Component {
}
}
class LotsOfGreetings extends Component {
export default class LotsOfGreetings extends Component {
render() {
return (
<View style={{alignItems: 'center'}}>
Expand All @@ -61,6 +62,7 @@ class LotsOfGreetings extends Component {
}
}
// skip this line if using Create React Native App
AppRegistry.registerComponent('LotsOfGreetings', () => LotsOfGreetings);
```

Expand Down
7 changes: 4 additions & 3 deletions docs/State.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Blink extends Component {
}
}
class BlinkApp extends Component {
export default class BlinkApp extends Component {
render() {
return (
<View>
Expand All @@ -52,12 +52,13 @@ class BlinkApp extends Component {
}
}
// skip this line if using Create React Native App
AppRegistry.registerComponent('BlinkApp', () => BlinkApp);
```

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like [Redux](http://redux.js.org/index.html) to control your data flow. In that case you would use Redux to modify your state rather than calling `setState` directly.
In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like [Redux](http://redux.js.org/index.html) to control your data flow. In that case you would use Redux to modify your state rather than calling `setState` directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the [React.Component API](https://facebook.github.io/react/docs/component-api.html).
State works the same way as it does in React, so for more details on handling state, you can look at the [React.Component API](https://facebook.github.io/react/docs/component-api.html).
At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to [learn about Style](docs/style.html).
3 changes: 2 additions & 1 deletion docs/Style.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ As a component grows in complexity, it is often cleaner to use `StyleSheet.creat
import React, { Component } from 'react';
import { AppRegistry, StyleSheet, Text, View } from 'react-native';
class LotsOfStyles extends Component {
export default class LotsOfStyles extends Component {
render() {
return (
<View>
Expand All @@ -42,6 +42,7 @@ const styles = StyleSheet.create({
},
});
// skip this line if using Create React Native App
AppRegistry.registerComponent('LotsOfStyles', () => LotsOfStyles);
```

Expand Down
6 changes: 4 additions & 2 deletions docs/Text.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Both iOS and Android allow you to display formatted text by annotating ranges of
import React, { Component } from 'react';
import { AppRegistry, Text } from 'react-native';
class BoldAndBeautiful extends Component {
export default class BoldAndBeautiful extends Component {
render() {
return (
<Text style={{fontWeight: 'bold'}}>
Expand All @@ -21,6 +21,7 @@ class BoldAndBeautiful extends Component {
}
}
// skip this line if using Create React Native App
AppRegistry.registerComponent('BoldAndBeautiful', () => BoldAndBeautiful);
```

Expand All @@ -40,7 +41,7 @@ On iOS, you can nest views within your Text component. Here's an example:
import React, { Component } from 'react';
import { AppRegistry, Text, View } from 'react-native';
class BlueIsCool extends Component {
export default class BlueIsCool extends Component {
render() {
return (
<Text>
Expand All @@ -52,6 +53,7 @@ class BlueIsCool extends Component {
}
}
// skip this line if using Create React Native App
AppRegistry.registerComponent('BlueIsCool', () => BlueIsCool);
```

Expand Down
7 changes: 4 additions & 3 deletions docs/Tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ In accordance with the ancient traditions of our people, we must first build an
import React, { Component } from 'react';
import { AppRegistry, Text } from 'react-native';
class AwesomeProject extends Component {
export default class HelloWorldApp extends Component {
render() {
return (
<Text>Hello world!</Text>
);
}
}
AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);
// skip this line if using Create React Native App
AppRegistry.registerComponent('HelloWorldApp', () => HelloWorldApp);
```

If you are feeling curious, you can play around with sample code directly in the web simulators. You can also paste it into your `index.ios.js` or `index.android.js` file to create a real app on your local machine.
Expand All @@ -47,7 +48,7 @@ is a built-in component that just displays some text.

So this code is defining `HelloWorldApp`, a new `Component`, and it's registering it with the `AppRegistry`. When you're building a React Native app, you'll be making new components a lot. Anything you see on the screen is some sort of component. A component can be pretty simple - the only thing that's required is a `render` function which returns some JSX to render.

The `AppRegistry` just tells React Native which component is the root one for the whole application. You won't be thinking about `AppRegistry` a lot - there will probably just be one call to `AppRegistry.registerComponent` in your whole app. It's included in these examples so you can paste the whole thing into your `index.ios.js` or `index.android.js` file and get it running.
The `AppRegistry` just tells React Native which component is the root one for the whole application. You won't be thinking about `AppRegistry` a lot - there will probably just be one call to `AppRegistry.registerComponent` in your whole app. It's included in these examples so you can paste the whole thing into your `index.ios.js` or `index.android.js` file and get it running. If you have a project from Create React Native App, this is handled for you and it's not necessary to call AppRegistry in your code.

## This App Doesn't Do Very Much

Expand Down
4 changes: 2 additions & 2 deletions docs/UsingAListView.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ This example creates a simple `ListView` of hardcoded data. It first initializes
import React, { Component } from 'react';
import { AppRegistry, ListView, Text, View } from 'react-native';
class ListViewBasics extends Component {
export default class ListViewBasics extends Component {
// Initialize the hardcoded data
constructor(props) {
super(props);
Expand All @@ -45,7 +45,7 @@ class ListViewBasics extends Component {
}
}
// App registration and rendering
// skip this line if using Create React Native App
AppRegistry.registerComponent('ListViewBasics', () => ListViewBasics);
```

Expand Down
4 changes: 2 additions & 2 deletions docs/UsingAScrollView.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This example creates a vertical `ScrollView` with both images and text mixed tog
import React, { Component } from 'react';
import { AppRegistry, ScrollView, Image, Text } from 'react-native'
class IScrolledDownAndWhatHappenedNextShockedMe extends Component {
export default class IScrolledDownAndWhatHappenedNextShockedMe extends Component {
render() {
return (
<ScrollView>
Expand Down Expand Up @@ -56,7 +56,7 @@ class IScrolledDownAndWhatHappenedNextShockedMe extends Component {
}
}
// skip these lines if using Create React Native App
AppRegistry.registerComponent(
'IScrolledDownAndWhatHappenedNextShockedMe',
() => IScrolledDownAndWhatHappenedNextShockedMe);
Expand Down

0 comments on commit ca2d57c

Please sign in to comment.