Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added SimpleNavigator & sample pages
- Loading branch information
Showing
11 changed files
with
307 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# EditorConfig: http://EditorConfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
{ | ||
"plugins": [ | ||
"react", "jsdoc" | ||
], | ||
"parser": "babel-eslint", | ||
"parserOptions": { | ||
"ecmaVersion": 6, | ||
"ecmaFeatures": { | ||
"jsx": true, | ||
"experimentalObjectRestSpread": true | ||
} | ||
}, | ||
"env": { | ||
"browser": true, | ||
"node": true, | ||
"es6": true | ||
}, | ||
"rules": { | ||
// Common js rules | ||
"brace-style": [2, "1tbs", { "allowSingleLine": true }], | ||
"camelcase": 2, | ||
"curly": 2, | ||
"eqeqeq": 2, | ||
"no-extend-native": 2, | ||
"no-proto": 2, | ||
"no-caller": 2, | ||
"no-unused-vars": [2, { "vars": "all", "args": "none" }], | ||
"indent": [2, 2, {"SwitchCase": 1}], | ||
"new-cap": 2, | ||
"quotes": [2, "single"], | ||
"max-depth": [2, 3], | ||
"max-statements": [2, 45], | ||
"max-len": [2, 150], | ||
"no-eq-null": 2, | ||
"operator-linebreak": 2, | ||
"no-multiple-empty-lines": [2, { max: 2 }], | ||
"no-mixed-spaces-and-tabs": 2, | ||
"space-unary-ops": 2, | ||
"no-multi-spaces": 2, | ||
"space-before-blocks": 2, | ||
"space-before-function-paren": [2, "always"], | ||
"keyword-spacing": 2, | ||
"space-infix-ops": 2, | ||
"object-curly-spacing": [2, "always"], | ||
"comma-spacing": [2, { "before": false, "after": true }], | ||
"no-trailing-spaces": 2, | ||
"comma-dangle": 2, | ||
"wrap-iife": 2, | ||
"no-extra-semi": 2, | ||
"semi-spacing": 2, | ||
"semi": [2, "never"], | ||
"spaced-comment": 2, | ||
"func-names": 2, | ||
|
||
// NodeJs rules | ||
"block-scoped-var": 2, | ||
"global-require": 2, | ||
"no-mixed-requires": 2, | ||
"no-new-require": 2, | ||
|
||
// ES6 rules | ||
"arrow-spacing": 2, | ||
"no-const-assign": 2, | ||
"no-var": 2, | ||
"prefer-const": 2, | ||
|
||
// React | ||
"jsx-quotes": [2, "prefer-double"], | ||
"react/jsx-uses-react": 1, | ||
"react/jsx-uses-vars": 1, | ||
|
||
// JSDoc | ||
"jsdoc/check-param-names": 1, | ||
"jsdoc/check-tag-names": 1, | ||
"jsdoc/check-types": 1, | ||
"jsdoc/newline-after-description": 0, | ||
"jsdoc/require-description-complete-sentence": 1, | ||
"jsdoc/require-hyphen-before-param-description": 1, | ||
"jsdoc/require-param": 1, | ||
"jsdoc/require-param-description": 1, | ||
"jsdoc/require-param-type": 1, | ||
"jsdoc/require-returns-description": 1, | ||
"jsdoc/require-returns-type": 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from 'react' | ||
import { | ||
View, | ||
Text | ||
} from 'react-native' | ||
import baseStyles from '../baseStyles' | ||
|
||
export default class AboutView extends React.Component { | ||
|
||
render () { | ||
return ( | ||
<View style={baseStyles.view}> | ||
<Text style={baseStyles.h3}> | ||
About Us | ||
</Text> | ||
|
||
<Text style={baseStyles.link} onPress={() => this.props.nav.back()}> | ||
⟨ Go Back | ||
</Text> | ||
</View> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,33 @@ | ||
/** | ||
* Sample React Native App | ||
* https://github.com/facebook/react-native | ||
* @flow | ||
*/ | ||
|
||
import React, { Component } from 'react' | ||
import { | ||
AppRegistry, | ||
StyleSheet, | ||
Text, | ||
View, | ||
Platform, | ||
TextInput | ||
} from 'react-native' | ||
const { GiftedForm } = require('react-native-gifted-form') | ||
import { StyleSheet, View } from 'react-native' | ||
|
||
import SimpleNavigator from './SimpleNavigator' | ||
import MainView from './MainView' | ||
import ContactUsView from './ContactUsView' | ||
import AboutView from './AboutView' | ||
|
||
export class App extends Component { | ||
render() { | ||
return ( | ||
<View style={styles.container}> | ||
<Text style={styles.welcome}> | ||
Welcome to React Native for {Platform.OS}!!!! | ||
</Text> | ||
<Text style={styles.instructions}> | ||
To get started, edit index.{Platform.OS}.js YA! | ||
</Text> | ||
<Text style={styles.instructions}> | ||
Press Cmd+R to reload,{'\n'} | ||
{ Platform.OS !== "web"?"Cmd+D or shake for dev menu":"" } | ||
</Text> | ||
state = {} | ||
|
||
<GiftedForm style={styles.myForm}> | ||
<GiftedForm.TextInputWidget | ||
name='firstName' | ||
title='First name' | ||
placeholder='First name' | ||
clearButtonMode='while-editing' | ||
/> | ||
<GiftedForm.TextInputWidget | ||
name='lastName' | ||
title='Last name' | ||
placeholder='Last name' | ||
clearButtonMode='while-editing' | ||
/> | ||
</GiftedForm> | ||
render () { | ||
return ( | ||
<View style={styles.view}> | ||
<SimpleNavigator views={{ | ||
index: MainView, | ||
contactUs: ContactUsView, | ||
about: AboutView | ||
}} /> | ||
</View> | ||
) | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
view: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
justifyContent: 'flex-start', | ||
alignItems: 'center', | ||
backgroundColor: '#F5FCFF', | ||
}, | ||
welcome: { | ||
fontSize: 20, | ||
textAlign: 'center', | ||
margin: 10, | ||
}, | ||
instructions: { | ||
textAlign: 'center', | ||
color: '#333333', | ||
marginBottom: 5, | ||
}, | ||
myForm: { | ||
width: 400 | ||
paddingTop: 50 | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react' | ||
import { | ||
View, | ||
Text | ||
} from 'react-native' | ||
import baseStyles from '../baseStyles' | ||
|
||
export default class ContactUsView extends React.Component { | ||
|
||
render () { | ||
return ( | ||
<View style={baseStyles.view}> | ||
<Text style={baseStyles.h3}> | ||
Contact Us | ||
</Text> | ||
|
||
<Text style={baseStyles.link} onPress={() => this.props.nav.linkTo('about')}> | ||
About Us | ||
</Text> | ||
|
||
<Text style={baseStyles.link} onPress={() => this.props.nav.back()}> | ||
⟨ Go Back | ||
</Text> | ||
</View> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import React from 'react' | ||
import { | ||
StyleSheet, | ||
Text, | ||
View, | ||
Platform | ||
} from 'react-native' | ||
import baseStyles from '../baseStyles' | ||
|
||
const { GiftedForm } = require('react-native-gifted-form') | ||
|
||
export default class MainView extends React.Component { | ||
render () { | ||
return ( | ||
<View style={styles.container}> | ||
<Text style={styles.welcome}> | ||
Welcome to React Native for {Platform.OS}! | ||
</Text> | ||
<Text style={styles.instructions}> | ||
To get started, edit App.js | ||
</Text> | ||
<Text style={styles.instructions}> | ||
Press Cmd+R to reload,{'\n'} | ||
{ Platform.OS !== "web" ? "Cmd+D or shake for dev menu": "" } | ||
</Text> | ||
|
||
<Text style={baseStyles.link} onPress={() => this.props.nav.linkTo('contactUs')}> | ||
Go to Contact Us | ||
</Text> | ||
|
||
<GiftedForm style={styles.myForm}> | ||
<GiftedForm.TextInputWidget | ||
name="firstName" | ||
title="First name" | ||
placeholder="First name" | ||
clearButtonMode="while-editing" | ||
/> | ||
<GiftedForm.TextInputWidget | ||
name="lastName" | ||
title="Last name" | ||
placeholder="Last name" | ||
clearButtonMode="while-editing" | ||
/> | ||
</GiftedForm> | ||
|
||
</View> | ||
) | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
backgroundColor: '#F5FCFF', | ||
}, | ||
welcome: { | ||
fontSize: 20, | ||
textAlign: 'center', | ||
margin: 10, | ||
}, | ||
instructions: { | ||
textAlign: 'center', | ||
color: '#333333', | ||
marginBottom: 5, | ||
}, | ||
myForm: { | ||
marginTop: 20, | ||
alignSelf: 'stretch' | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from 'react' | ||
import { View } from 'react-native' | ||
|
||
export default class SimpleNavigator extends React.Component { | ||
state = { | ||
currentView: null, | ||
view: null | ||
} | ||
currentComp = null | ||
history = [] | ||
|
||
back = () => { | ||
this.history.pop() | ||
const lastViewId = this.history[ this.history.length - 1 ] | ||
this.setState({ currentView: lastViewId }) | ||
} | ||
|
||
linkTo = (viewId) => { | ||
this.history.push(viewId) | ||
this.setState({ currentView: viewId }) | ||
} | ||
|
||
render () { | ||
if (this.state.currentView) { | ||
this.currentComp = this.props.views[ this.state.currentView ] | ||
} else { | ||
this.history = ['index'] | ||
this.currentComp = this.props.views[ 'index' ] | ||
} | ||
const viewEl = <this.currentComp nav={this} /> | ||
|
||
return ( | ||
<View> | ||
{viewEl} | ||
</View> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { | ||
StyleSheet | ||
} from 'react-native' | ||
|
||
export default StyleSheet.create({ | ||
view: { | ||
padding: 10, | ||
paddingTop: 30, | ||
backgroundColor: '#F5FCFF' | ||
}, | ||
h3: { | ||
fontSize: 20 | ||
}, | ||
link: { | ||
color: 'darkblue', | ||
marginTop: 20, | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.