Skip to content

Commit

Permalink
fix typings
Browse files Browse the repository at this point in the history
  • Loading branch information
aksonov committed Aug 12, 2019
1 parent 7ce705b commit b3d2bcb
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 73 deletions.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ interface OverlayStatic extends React.ComponentClass<SceneProps & OverlayProps>
export var Lightbox: LightboxStatic;
export type Lightbox = LightboxStatic;
interface LightboxProps extends React.Props<Modal> {}
interface LightboxStatic extends React.ComponentClass<LightboxProps> {}
interface LightboxStatic extends React.ComponentClass<SceneProps & LightboxProps> {}

// Stack
export var Stack: StackStatic;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-router-flux",
"version": "4.1.0-beta.6",
"version": "4.1.0-beta.7",
"description": "React Native Router using Flux architecture",
"repository": {
"type": "git",
Expand Down
146 changes: 75 additions & 71 deletions src/navigationStore.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from 'react';
import { StatusBar, Image, Animated, Easing } from 'react-native';
import {
StatusBar, Image, Animated, Easing,
} from 'react-native';
import {
createAppContainer,
createBottomTabNavigator,
Expand Down Expand Up @@ -122,7 +124,9 @@ function getProperties(component = {}) {
delete res.children;
return res;
}
function createTabBarOptions({ tabBarStyle, activeTintColor, inactiveTintColor, activeBackgroundColor, inactiveBackgroundColor, showLabel, labelStyle, tabStyle, ...props }) {
function createTabBarOptions({
tabBarStyle, activeTintColor, inactiveTintColor, activeBackgroundColor, inactiveBackgroundColor, showLabel, labelStyle, tabStyle, ...props
}) {
return {
...props,
style: tabBarStyle,
Expand Down Expand Up @@ -267,47 +271,46 @@ function createNavigationOptions(params) {
}

if (
rightButtonImage ||
rightTitle ||
params.renderRightButton ||
onRight ||
navigationParams.onRight ||
navigationParams.rightTitle ||
navigationParams.rightButtonImage ||
rightButtonTextStyle ||
((drawerImage || drawerIcon) && !hideDrawerButton && drawerPosition === 'right')
rightButtonImage
|| rightTitle
|| params.renderRightButton
|| onRight
|| navigationParams.onRight
|| navigationParams.rightTitle
|| navigationParams.rightButtonImage
|| rightButtonTextStyle
|| ((drawerImage || drawerIcon) && !hideDrawerButton && drawerPosition === 'right')
) {
res.headerRight = getValue(navigationParams.right || navigationParams.rightButton || params.renderRightButton, { ...navigationParams, ...screenProps }) || (
<RightNavBarButton navigation={navigation} {...params} {...navigationParams} {...componentData} />
);
}

if (
leftButtonImage ||
backButtonImage ||
backTitle ||
leftTitle ||
params.renderLeftButton ||
leftButtonTextStyle ||
renderBackButton ||
backButtonTextStyle ||
onLeft ||
navigationParams.leftTitle ||
navigationParams.onLeft ||
navigationParams.leftButtonImage ||
navigationParams.backButtonImage ||
navigationParams.backTitle ||
((drawerImage || drawerIcon) && !hideDrawerButton && drawerPosition !== 'right')
leftButtonImage
|| backButtonImage
|| backTitle
|| leftTitle
|| params.renderLeftButton
|| leftButtonTextStyle
|| renderBackButton
|| backButtonTextStyle
|| onLeft
|| navigationParams.leftTitle
|| navigationParams.onLeft
|| navigationParams.leftButtonImage
|| navigationParams.backButtonImage
|| navigationParams.backTitle
|| ((drawerImage || drawerIcon) && !hideDrawerButton && drawerPosition !== 'right')
) {
const leftButton = navigationParams.left || navigationParams.leftButton || params.renderLeftButton;
res.headerLeft =
getValue(leftButton, { ...params, ...navigationParams, ...screenProps }) ||
(((onLeft && (leftTitle || navigationParams.leftTitle || leftButtonImage || navigationParams.leftButtonImage)) || drawerImage || drawerIcon) && (
res.headerLeft = getValue(leftButton, { ...params, ...navigationParams, ...screenProps })
|| (((onLeft && (leftTitle || navigationParams.leftTitle || leftButtonImage || navigationParams.leftButtonImage)) || drawerImage || drawerIcon) && (
<LeftNavBarButton navigation={navigation} {...params} {...navigationParams} {...componentData} />
)) ||
res.headerLeft ||
(init ? null : (!leftButton && renderBackButton && renderBackButton(state)) || (!leftButton && <BackNavBarButton navigation={navigation} {...state} />)) ||
null;
))
|| res.headerLeft
|| (init ? null : (!leftButton && renderBackButton && renderBackButton(state)) || (!leftButton && <BackNavBarButton navigation={navigation} {...state} />))
|| null;
}

if (back) {
Expand Down Expand Up @@ -348,7 +351,7 @@ function createNavigationOptions(params) {

if (!legacy && backToInitial) {
const userDefinedTabBarOnPress = res.tabBarOnPress;
res.tabBarOnPress = data => {
res.tabBarOnPress = (data) => {
if (userDefinedTabBarOnPress) {
console.warn('backToInitial and tabBarOnPress were both defined and might cause unexpected navigation behaviors. I hope you know what you are doing ;-)');
userDefinedTabBarOnPress(data);
Expand Down Expand Up @@ -379,11 +382,11 @@ function extendProps(props, store: NavigationStore) {
const res = { ...props };
for (const transition of Object.keys(props)) {
if (
reservedKeys.indexOf(transition) === -1 &&
transition.startsWith('on') &&
transition.charAt(2) >= 'A' &&
transition.charAt(2) <= 'Z' &&
typeof props[transition] === 'string'
reservedKeys.indexOf(transition) === -1
&& transition.startsWith('on')
&& transition.charAt(2) >= 'A'
&& transition.charAt(2) <= 'Z'
&& typeof props[transition] === 'string'
) {
if (store[props[transition]]) {
res[transition] = params => store[props[transition]](params);
Expand Down Expand Up @@ -519,13 +522,13 @@ class NavigationStore {
}
}

setCustomReducer = Navigator => {
setCustomReducer = (Navigator) => {
this.getStateForAction = Navigator.router.getStateForAction;
const reducer = createReducer();
Navigator.router.getStateForAction = (cmd, state) => (this.reducer ? this.reducer(state, cmd) : reducer(state, cmd));
};

onEnterHandler = async currentScene => {
onEnterHandler = async (currentScene) => {
if (this.states[currentScene]) {
const handler = this[currentScene + OnEnter];
const success = this.states[currentScene].success || defaultSuccess;
Expand All @@ -545,7 +548,7 @@ class NavigationStore {
}
};

onExitHandler = prevScene => {
onExitHandler = (prevScene) => {
if (prevScene) {
const exitHandler = this[prevScene + OnExit];
if (exitHandler) {
Expand All @@ -572,13 +575,11 @@ class NavigationStore {
if (this.currentScene !== this.prevScene) {
// run onExit for old scene
this.onExitHandler(this.prevScene);
setTimeout(() =>
this.dispatch({
type: ActionConst.FOCUS,
routeName: this.currentScene,
params: this.currentParams,
}),
);
setTimeout(() => this.dispatch({
type: ActionConst.FOCUS,
routeName: this.currentScene,
params: this.currentParams,
}));
this.onEnterHandler(currentScene);
} else {
const routeName = getRouteNameByKey(this.state, action.key);
Expand All @@ -593,15 +594,15 @@ class NavigationStore {
}
};

setTopLevelNavigator = navigatorRef => {
setTopLevelNavigator = (navigatorRef) => {
this._navigator = navigatorRef;
};

addRef = (name, ref) => {
this.refs[name] = ref;
};

deleteRef = name => {
deleteRef = (name) => {
delete this.refs[name];
};

Expand All @@ -625,8 +626,12 @@ class NavigationStore {
}
const res = {};
const order = [];
const { navigator, renderer, contentComponent, drawerWidth, drawerLockMode, tabBarPosition, lazy, duration, ...parentProps } = scene.props;
let { legacy, tabs, modal, lightbox, overlay, drawer, transitionConfig, tabBarComponent } = parentProps;
const {
navigator, renderer, contentComponent, drawerWidth, drawerLockMode, tabBarPosition, lazy, duration, ...parentProps
} = scene.props;
let {
legacy, tabs, modal, lightbox, overlay, drawer, transitionConfig, tabBarComponent,
} = parentProps;
if (scene.type === Modal) {
modal = true;
} else if (scene.type === Drawer) {
Expand Down Expand Up @@ -689,7 +694,9 @@ class NavigationStore {
const key = child.key || `key${(counter += 1)}`;
const init = key === children[0].key;
assert(reservedKeys.indexOf(key) === -1, `Scene name cannot be reserved word: ${child.key}`);
const { component, type = tabs || drawer ? 'jump' : 'push', path, onEnter, onExit, on, failure, success, wrap, initial = false, ...props } = child.props;
const {
component, type = tabs || drawer ? 'jump' : 'push', path, onEnter, onExit, on, failure, success, wrap, initial = false, ...props
} = child.props;
if (!this.states[key]) {
this.states[key] = {};
}
Expand All @@ -700,22 +707,20 @@ class NavigationStore {
}
delete props.children;
if (success) {
this.states[key].success =
success instanceof Function
? success
: args => {
// console.log(`Transition to state=${success}`);
setTimeout(() => this[success](args));
};
this.states[key].success = success instanceof Function
? success
: (args) => {
// console.log(`Transition to state=${success}`);
setTimeout(() => this[success](args));
};
}
if (failure) {
this.states[key].failure =
failure instanceof Function
? failure
: args => {
// console.log(`Transition to state=${failure}`);
setTimeout(() => this[failure](args));
};
this.states[key].failure = failure instanceof Function
? failure
: (args) => {
// console.log(`Transition to state=${failure}`);
setTimeout(() => this[failure](args));
};
}
if (path) {
this.states[key].path = path;
Expand Down Expand Up @@ -823,8 +828,7 @@ class NavigationStore {
if (legacy) {
createTabNavigator = DEPRECATED_createTabNavigator;
if (!tabBarComponent) {
tabBarComponent =
tabBarPosition === 'top' ? props => <DEPRECATED_TabBarTop {...props} {...commonProps} /> : props => <DEPRECATED_TabBarBottom {...props} {...commonProps} />;
tabBarComponent = tabBarPosition === 'top' ? props => <DEPRECATED_TabBarTop {...props} {...commonProps} /> : props => <DEPRECATED_TabBarBottom {...props} {...commonProps} />;
}
} else if (tabBarPosition !== 'top') {
createTabNavigator = createBottomTabNavigator;
Expand Down Expand Up @@ -884,7 +888,7 @@ class NavigationStore {
});
};

dispatch = action => {
dispatch = (action) => {
if (this.externalDispatch) {
this.externalAction = action;
this.externalDispatch(action);
Expand Down

0 comments on commit b3d2bcb

Please sign in to comment.