Skip to content

Commit

Permalink
Merge pull request #589 from aksonov/revert-585-eslint-fixes
Browse files Browse the repository at this point in the history
Revert "Fix some eslint errors"
  • Loading branch information
aksonov committed Apr 25, 2016
2 parents 63cbdaa + f690311 commit 6d7aef9
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 166 deletions.
28 changes: 9 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
import Actions from './src/Actions';
import DefaultRenderer from './src/DefaultRenderer';
import Modal from './src/Modal';
import NavBar from './src/NavBar';
import Reducer from './src/Reducer';
import Router from './src/Router';
import Scene from './src/Scene';
import Switch from './src/Switch';
import TabBar from './src/TabBar';
import Actions from './src/Actions';
import getInitialState from './src/State';
import Reducer from './src/Reducer';
import TabBar from './src/TabBar';
import Modal from './src/Modal';
import DefaultRenderer from './src/DefaultRenderer';
import Switch from './src/Switch';
import NavBar from './src/NavBar';

module.exports = {
Actions,
DefaultRenderer,
Modal,
NavBar,
Reducer,
Router,
Scene,
Switch,
TabBar,
getInitialState,
};
module.exports = { DefaultRenderer, NavBar, Switch, Modal, Router, TabBar,
Scene, Actions, Reducer, getInitialState };
64 changes: 28 additions & 36 deletions src/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ function isNumeric(n) {
}

function filterParam(data) {
if (data.toString() !== '[object Object]') {
return { data };
}
if (data.toString() != '[object Object]')
return { data: data };
if (!data) {
return {};
}
const proto = (data || {}).constructor.name;
var proto = (data || {}).constructor.name;
// avoid passing React Native parameters
if (proto !== 'Object') {
if (proto != 'Object') {
data = {};
}
return data;
Expand All @@ -52,76 +51,69 @@ class Actions {
assert(root.props, 'props should be defined for stack');
const key = root.key || 'root';
assert(key, 'unique key should be defined ', root);
assert([POP_ACTION, POP_ACTION2, REFRESH_ACTION, REPLACE_ACTION, JUMP_ACTION, PUSH_ACTION,
FOCUS_ACTION, RESET_ACTION, 'create', 'init', 'callback', 'iterate', 'current',
].indexOf(key) === -1, `${key} is not allowed as key name`);
const { ...staticProps } = root.props;
assert([POP_ACTION, POP_ACTION2, REFRESH_ACTION, REPLACE_ACTION, JUMP_ACTION, PUSH_ACTION, FOCUS_ACTION, RESET_ACTION, 'create',
'init', 'callback', 'iterate', 'current'].indexOf(key) == -1, key + ' is not allowed as key name');
const { children, ...staticProps } = root.props;
let type = root.props.type || (parentProps.tabs ? JUMP_ACTION : PUSH_ACTION);
if (type === 'switch') {
type = JUMP_ACTION;
}
const res = { name: key, ...staticProps, key, sceneKey: key, type, parent: parentProps.key };
let res = { name:key, ...staticProps, key, sceneKey:key, type, parent:parentProps.key };
if (root.props.children) {
const list = root.props.children instanceof Array ?
root.props.children : [root.props.children];
const list = root.props.children instanceof Array ? root.props.children : [root.props.children];
res.children = list.map(c => this.iterate(c, res, refs).key);
} else {
assert(staticProps.component, `component property is not set for key=${key}`);
assert(staticProps.component, 'component property is not set for key=' + key);
// wrap scene if parent is "tabs"
if (parentProps.tabs) {
const innerKey = `${res.key}_`;
const inner = { ...res, name: key, key: innerKey, type: PUSH_ACTION, parent: res.key };
const innerKey = res.key + '_';
const inner = { ...res, name:key, key: innerKey, type: PUSH_ACTION, parent:res.key };
refs[innerKey] = inner;
res.children = [innerKey];
delete res.component;
}
res.index = 0;
}
if (this[key]) {
console.log(`Key ${root.key} is already defined!`);
console.log('Key ' + root.key + ' is already defined!');
}
this[key] = (props = {}) => {
assert(this.callback, 'Actions.callback is not defined!');
this.callback({ key: root.key, type, ...filterParam(props) });
};
this[key] =
(props = {}) => { assert(this.callback, 'Actions.callback is not defined!');
this.callback({ key: root.key, type, ...filterParam(props) }); };
refs[res.key] = res;

return res;
}

pop(props = {}) {
if (this.callback) {
this.callback({ ...filterParam(props), type: POP_ACTION });
}
props = filterParam(props);
const data = isNumeric(props) ? { num: props } : props;
this.callback && this.callback({ ...props, type: POP_ACTION });
}

jump(props = {}) {
if (this.callback) {
this.callback({ ...filterParam(props), type: JUMP_ACTION });
}
props = filterParam(props);
this.callback && this.callback({ ...props, type: JUMP_ACTION });
}

init(props = {}) {
if (this.callback) {
this.callback({ ...filterParam(props), type: INIT_ACTION });
}
props = filterParam(props);
this.callback && this.callback({ ...props, type: INIT_ACTION });
}

refresh(props = {}) {
if (this.callback) {
this.callback({ ...filterParam(props), type: REFRESH_ACTION });
}
props = filterParam(props);
this.callback && this.callback({ ...props, type: REFRESH_ACTION });
}

focus(props = {}) {
if (this.callback) {
this.callback({ ...filterParam(props), type: FOCUS_ACTION });
}
props = filterParam(props);
this.callback && this.callback({ ...props, type: FOCUS_ACTION });
}

create(scene:Scene) {
assert(scene, 'root scene should be defined');
const refs = {};
let refs = {};
this.iterate(scene, {}, refs);
return refs;
}
Expand Down
167 changes: 75 additions & 92 deletions src/DefaultRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,28 @@
* LICENSE file in the root directory of this source tree.
*
*/
import React, {
Animated,
NavigationExperimental,
PropTypes,
StyleSheet,
View,
} from 'react-native';
import React, { Component, Animated, PropTypes, StyleSheet, View, NavigationExperimental } from 'react-native';
const {
AnimatedView: NavigationAnimatedView,
Card: NavigationCard,
RootContainer: NavigationRootContainer,
Header: NavigationHeader,
} = NavigationExperimental;
import Actions from './Actions';
import NavBar from './NavBar';
AnimatedView: NavigationAnimatedView,
Card: NavigationCard,
RootContainer: NavigationRootContainer,
Header: NavigationHeader,
} = NavigationExperimental;
import TabBar from './TabBar';
import NavBar from './NavBar';
import Actions from './Actions';

const propTypes = {
navigationState: PropTypes.object,
};

const styles = StyleSheet.create({
animatedView: {
flex: 1,
backgroundColor: 'transparent',
},
});

class DefaultRenderer extends React.Component {
static childContextTypes = {
navigationState: PropTypes.any,
};

export default class DefaultRenderer extends Component {
constructor(props) {
super(props);
this.renderCard = this.renderCard.bind(this);
this.renderScene = this.renderScene.bind(this);
this.renderHeader = this.renderHeader.bind(this);
this._renderCard = this._renderCard.bind(this);
this._renderScene = this._renderScene.bind(this);
this._renderHeader = this._renderHeader.bind(this);
}

getChildContext() {
return {
navigationState: this.props.navigationState,
};
}
static childContextTypes = {
navigationState: PropTypes.any,
};

componentDidMount() {
this.dispatchFocusAction(this.props);
Expand All @@ -70,41 +47,10 @@ class DefaultRenderer extends React.Component {
Actions.focus({ scene });
}

renderHeader(/* NavigationSceneRendererProps*/ props) {
const state = props.navigationState;
let selected = state.children[state.index];
while (selected.hasOwnProperty('children')) {
selected = selected.children[selected.index];
}
const Component = state.navBar || selected.navBar || NavBar;
return <Component {...props} getTitle={titleState => titleState.title} />;
}

renderCard(/* NavigationSceneRendererProps*/ props) {
const { key, direction, panHandlers, getSceneStyle } = props.scene.navigationState;

const optionals = {};
if (getSceneStyle) optionals.style = getSceneStyle(props);

return (
<NavigationCard
{...props}
key={`card_${key}`}
direction={direction || 'horizontal'}
panHandlers={panHandlers}
renderScene={this.renderScene}
{...optionals}
/>
);
}

renderScene(/* NavigationSceneRendererProps*/ props) {
return (
<DefaultRenderer
key={props.scene.navigationState.key}
navigationState={props.scene.navigationState}
/>
);
getChildContext() {
return {
navigationState: this.props.navigationState,
};
}

render() {
Expand All @@ -118,20 +64,20 @@ class DefaultRenderer extends React.Component {
}
if (Component) {
return (
<View style={[{ flex: 1 }, navigationState.sceneStyle]}>
<Component {...navigationState} navigationState={navigationState} />
</View>
);
<View style={[{ flex: 1 }, navigationState.sceneStyle]}>
<Component {...navigationState} navigationState={navigationState} />
</View>
);
}

const selected = navigationState.children[navigationState.index];
// return <DefaultRenderer key={selected.key} navigationState={selected}/>

const applyAnimation = selected.applyAnimation || navigationState.applyAnimation;
const style = selected.style || navigationState.style;
let applyAnimation = selected.applyAnimation || navigationState.applyAnimation;
let style = selected.style || navigationState.style;
let direction = selected.direction || navigationState.direction || 'horizontal';

const optionals = {};
let optionals = {};
if (applyAnimation) {
optionals.applyAnimation = applyAnimation;
} else {
Expand All @@ -145,18 +91,55 @@ class DefaultRenderer extends React.Component {
}

return (
<NavigationAnimatedView
navigationState={navigationState}
style={[styles.animatedView, style]}
renderOverlay={this.renderHeader}
direction={direction}
renderScene={this.renderCard}
{...optionals}
/>
);
<NavigationAnimatedView
navigationState={navigationState}
style={[styles.animatedView, style]}
renderOverlay={this._renderHeader}
direction={direction}
renderScene={this._renderCard}
{...optionals}
/>
);
}
}

DefaultRenderer.propTypes = propTypes;
_renderHeader(/* NavigationSceneRendererProps*/ props) {
const state = props.navigationState;
const child = state.children[state.index];
let selected = state.children[state.index];
while (selected.hasOwnProperty('children')) {
selected = selected.children[selected.index];
}
const Component = state.navBar || selected.navBar || NavBar;
return <Component {...props} getTitle={state => state.title} />;
}

export default DefaultRenderer;
_renderCard(/* NavigationSceneRendererProps*/ props) {
const { key, direction, panHandlers, getSceneStyle } = props.scene.navigationState;

const optionals = {};
if (getSceneStyle) optionals.style = getSceneStyle(props);

return (
<NavigationCard
{...props}
key={'card_' + key}
direction={direction || 'horizontal'}
panHandlers={panHandlers}
renderScene={this._renderScene}
{...optionals}
/>
);
}

_renderScene(/* NavigationSceneRendererProps*/ props) {
return <DefaultRenderer key={props.scene.navigationState.key} navigationState={props.scene.navigationState} />;
}

}

const styles = StyleSheet.create({
animatedView: {
flex: 1,
backgroundColor:'transparent'
},
});
Loading

0 comments on commit 6d7aef9

Please sign in to comment.