Permalink
Browse files

CLI: Add README to app template, lint

Reviewed By: mkonicek

Differential Revision:
D4522116
Ninja: oss only

fbshipit-source-id: d17e0e8badcfe97eaea092e5d5274e02904a534d
  • Loading branch information...
mkonicek committed Feb 7, 2017
1 parent 2bc2ae7 commit 021e754c8f83d5c9ae405efca018fcca00ffe45f
@@ -0,0 +1,41 @@
+# App template for new React Native apps
+
+This is a simple React Native app template which demonstrates a few basics concepts such as navigation between a few screens, ListViews, and handling text input.
+
+<img src="https://cloud.githubusercontent.com/assets/346214/22697898/ced66f52-ed4a-11e6-9b90-df6daef43199.gif" alt="Android Example" height="800" style="float: left"/>
+
+<img src="https://cloud.githubusercontent.com/assets/346214/22697901/cfeab3e4-ed4a-11e6-8552-d76585317ac2.gif" alt="iOS Example" height="800"/>
+
+## Purpose
+
+The idea is to make it easier for people to get started with React Native. Currently `react-native init` creates a very simple app that contains one screen with static text. Everyone new to React Native then needs to figure out how to do very basic things such as:
+- Rendering a list of items fetched from a server
+- Navigating between screens
+- Handling text input and the software keyboard
+
+This app serves as a template used by `react-native init` so it is easier for anyone to get up and running quickly by having an app with a few screens and a ListView ready to go.
+
+### Best practices
+
+Another purpose of this app is to define best practices such as the folder structure of a standalone React Native app and naming conventions.
+
+## Not using Redux
+
+This template intentionally doesn't use Redux. After discussing with a few people who have experience using Redux we concluded that adding Redux to this app targeted at beginners would make the code more confusing, and wouldn't clearly show the benefits of Redux (because the app is too small). There are already a few concepts to grasp - the React component lifecycle, rendeing lists, using async / await, handling the software keyboard. We thought that's the maximum amount of things to learn at once. It's better for everyone to see patterns in their codebase as the app grows and decide for themselves whether and when they need Redux. See also the post [You Might Not Need Redux](https://medium.com/@dan_abramov/you-might-not-need-redux-be46360cf367#.f3q7kq4b3) by [Dan Abramov](https://twitter.com/dan_abramov).
+
+## Not using Flow (for now)
+
+Many people are new to React Native, some are new to ES6 and most people will be new to Flow. Therefore we didn't want to introduce all these concepts all at once in a single codebase. However, it might make sense to later introduce a separate version of this template that uses Flow annotations.
+
+## Provide feedback
+
+We need your feedback. Do you have a lot of experience building React Native apps? If so, please carefully read the code of the template and if you think something should be done differently, use issues in the repo [mkonicek/AppTemplateFeedback](https://github.com/mkonicek/AppTemplateFeedback) to discuss what should be done differently.
+
+## How to use the template
+
+```
+$ react-native init MyApp --version 0.42.0-rc.2 --template navigation
+$ cd MyApp
+$ react-native run-android
+$ react-native run-ios
+```
@@ -1,3 +1,5 @@
+'use strict';
+
/* @flow */
import React, { PropTypes, Component } from 'react';
@@ -10,7 +12,7 @@ import {
} from 'react-native';
type Props = {
- offset?: number;
+ offset?: number,
}
type State = {
@@ -41,7 +43,7 @@ type State = {
*/
const KeyboardSpacer = () => (
Platform.OS === 'ios' ? <KeyboardSpacerIOS /> : null
-)
+);
class KeyboardSpacerIOS extends Component<Props, Props, State> {
static propTypes = {
@@ -1,3 +1,5 @@
+'use strict';
+
import React, { Component } from 'react';
import {
Platform,
@@ -21,7 +23,7 @@ const Touchable = ({onPress, children}) => {
);
} else {
return (
- <TouchableHighlight onPress={onPress} underlayColor='#ddd'>
+ <TouchableHighlight onPress={onPress} underlayColor="#ddd">
{child}
</TouchableHighlight>
);
@@ -1,3 +1,4 @@
+'use strict';
// This file just a dummy example of a HTTP API to talk to the backend.
// The state of the "database" that would normally live on the server
@@ -60,7 +61,7 @@ function _makeSimulatedNetworkRequest(getValue) {
*/
async function fetchChatList() {
return _makeSimulatedNetworkRequest((resolve, reject) => {
- resolve(backendStateForLoggedInPerson.chats.map(chat => chat.name))
+ resolve(backendStateForLoggedInPerson.chats.map(chat => chat.name));
});
}
@@ -73,7 +74,7 @@ async function fetchChat(name) {
backendStateForLoggedInPerson.chats.find(
chat => chat.name === name
)
- )
+ );
});
}
@@ -82,11 +83,11 @@ async function fetchChat(name) {
*/
async function sendMessage({name, message}) {
return _makeSimulatedNetworkRequest((resolve, reject) => {
- const chat = backendStateForLoggedInPerson.chats.find(
+ const chatForName = backendStateForLoggedInPerson.chats.find(
chat => chat.name === name
);
- if (chat) {
- chat.messages.push({
+ if (chatForName) {
+ chatForName.messages.push({
name: 'Me',
text: message,
});
@@ -1,4 +1,5 @@
-import React, { Component } from 'react';
+'use strict';
+
import { TabNavigator } from 'react-navigation';
import ChatListScreen from './chat/ChatListScreen';
@@ -1,3 +1,5 @@
+'use strict';
+
/**
* This is an example React Native app demonstrates ListViews, text input and
* navigation between a few screens.
@@ -1,3 +1,5 @@
+'use strict';
+
import React, { Component } from 'react';
import {
ActivityIndicator,
@@ -39,7 +41,6 @@ export default class ChatListScreen extends Component {
async componentDidMount() {
const chatList = await Backend.fetchChatList();
- const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
this.setState((prevState) => ({
dataSource: prevState.dataSource.cloneWithRows(chatList),
isLoading: false,
@@ -59,7 +60,7 @@ export default class ChatListScreen extends Component {
});
}}
/>
- )
+ );
}
render() {
@@ -1,3 +1,5 @@
+'use strict';
+
import React, { Component } from 'react';
import {
ActivityIndicator,
@@ -43,7 +45,6 @@ export default class ChatScreen extends Component {
});
return;
}
- const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
this.setState((prevState) => ({
messages: chat.messages,
dataSource: prevState.dataSource.cloneWithRows(chat.messages),
@@ -85,7 +86,7 @@ export default class ChatScreen extends Component {
myMessage: '',
}
});
- this.refs.textInput.clear();
+ this.textInput.clear();
}
onMyMessageChange = (event) => {
@@ -110,17 +111,16 @@ export default class ChatScreen extends Component {
return (
<View style={styles.container}>
<ListView
- ref="listView"
dataSource={this.state.dataSource}
renderRow={this.renderRow}
style={styles.listView}
onLayout={this.scrollToBottom}
/>
<View style={styles.composer}>
<TextInput
- ref='textInput'
+ ref={(textInput) => { this.textInput = textInput; }}
style={styles.textInput}
- placeholder='Type a message...'
+ placeholder="Type a message..."
text={this.state.myMessage}
onSubmitEditing={this.onAddMessage}
onChange={this.onMyMessageChange}
@@ -1,9 +1,10 @@
+'use strict';
+
import React, { Component } from 'react';
import {
Image,
Platform,
StyleSheet,
- Text,
} from 'react-native';
import ListItem from '../../components/ListItem';
@@ -35,11 +36,6 @@ export default class WelcomeScreen extends Component {
}
const styles = StyleSheet.create({
- container: {
- backgroundColor: 'white',
- flex: 1,
- padding: 16,
- },
icon: {
width: 30,
height: 26,
@@ -1,3 +1,5 @@
+'use strict';
+
import React, { Component } from 'react';
import {
StyleSheet,
@@ -1,3 +1,5 @@
+'use strict';
+
import React, { Component } from 'react';
import {
StyleSheet,

0 comments on commit 021e754

Please sign in to comment.