Skip to content

Commit

Permalink
Merge branch 'release/0.16.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
SoHotSoup committed Jun 26, 2017
2 parents 11272fc + d58e037 commit e24505f
Show file tree
Hide file tree
Showing 11 changed files with 238 additions and 103 deletions.
11 changes: 8 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@
],
"parser": "babel-eslint",
"rules": {
"import/no-extraneous-dependencies": 0,
"import/extensions": 0,
"import/prefer-default-export": 0,
"import/no-named-as-default": 0,
"no-empty-label": 0,
"no-console": 0,
"no-shadow": 0,
"import/no-unresolved": 0,
"global-require": 0,
"no-underscore-dangle": 0,
"space-before-keywords": 0,
"space-after-keywords": 0,
"space-return-throw-case": 0,
"react/jsx-filename-extension": 0,
"react-native/no-unused-styles": 2,
"react-native/split-platform-components": 2,
"react/prefer-stateless-function": 0,
"react-native/split-platform-components": 2
}
}
}
4 changes: 1 addition & 3 deletions navigation/NavigationBar.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React, { Component } from 'react';
import _ from 'lodash';

import { NavigationBarView, NavigationBarStyleName } from './NavigationBarView';
import { DriverShape } from '@shoutem/animation';
import { connectStyle } from '@shoutem/theme';
import { NavigationBarView, NavigationBarStyleName } from './NavigationBarView';

/**
* A NavigationBar component that can be used to define
Expand Down Expand Up @@ -38,7 +37,6 @@ class NavigationBar extends Component {

constructor(props, context) {
super(props, context);

this.setNavBarProps(props);
}

Expand Down
17 changes: 13 additions & 4 deletions navigation/NavigationBarView.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ class NavigationBarView extends PureComponent {
// If the backgroundColor is animated, we want to listen for
// color changes, so that we can update the bar style as the
// animation runs.
this.backgroundListenerId = addAnimatedValueListener(backgroundColor, () =>
this.setStatusBarStyleForBackgroundColor(backgroundColor)
);
this.backgroundListenerId = addAnimatedValueListener(backgroundColor, () => {
this.setStatusBarStyleForBackgroundColor(backgroundColor);
});
}

// Set the bar style based on the current background color value
Expand Down Expand Up @@ -206,7 +206,7 @@ class NavigationBarView extends PureComponent {
// if necessary in `setStatusBarStyle`.
removeAnimatedValueListener(
this.props.style.container.backgroundColor,
this.backgroundListenerId
this.backgroundListenerId,
);
this.backgroundListenerId = null;
}
Expand Down Expand Up @@ -368,6 +368,14 @@ class NavigationBarView extends PureComponent {
return null;
}

renderBackground() {
const { renderBackground } = this.props;
if (renderBackground) {
return renderBackground(this.props);
}
return null;
}

render() {
const { scene } = this.props;
const { style, hidden, child } = this.resolveSceneProps(scene);
Expand All @@ -380,6 +388,7 @@ class NavigationBarView extends PureComponent {

return (
<Animated.View style={[style.container, this.interpolateNavBarStyle()]}>
{this.renderBackground()}
{this.renderLinearGradient()}
<NavigationHeader
{...this.createNavigationHeaderProps(style)}
Expand Down
27 changes: 27 additions & 0 deletions navigation/children-composers/back-button.composer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
import {
View,
Button,
Icon,
} from '../../index';

const createBackButton = navBarProps => sceneProps => (
<View virtual styleName="container">
<Button onPress={sceneProps.onNavigateBack}>
<Icon name="back" animationName={navBarProps.animationName} />
</Button>
</View>
);

const SceneComposer = {
canCompose(navBarProps) {
return !(navBarProps.scene.index === 0 || !navBarProps.onNavigateBack);
},
compose(navBarProps) {
return {
renderLeftComponent: createBackButton(navBarProps),
};
},
};

export default SceneComposer;
13 changes: 13 additions & 0 deletions navigation/children-composers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import NavBarComposer from './navbar-image.composer';
import TitleComposer from './title.composer';
import ShareComposer from './share.composer';
import BackButtonComposer from './back-button.composer';

const ChildrenComposers = [
NavBarComposer,
TitleComposer,
ShareComposer,
BackButtonComposer,
];

export default ChildrenComposers;
51 changes: 51 additions & 0 deletions navigation/children-composers/navbar-image.composer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React from 'react';
import _ from 'lodash';
import { NavigationBar } from '../NavigationBar';
import { Image } from '../../index';

const imageFitContainer = navBarProps => (NavigationBar.fitContainer || navBarProps.fitContainer);

const interpolateNavBarStyle = navBarProps => (
_.get(navBarProps, 'style.navigationBarImage') || {}
);

const interpolateNavBarProps = (navBarProps) => {
const { animationName } = navBarProps;
const newProps = {
resizeMode: imageFitContainer(navBarProps) ? 'cover' : 'contain',
resizeMethod: imageFitContainer(navBarProps) ? 'scale' : 'auto',
};

if (animationName) {
_.assign(newProps, {
animationName,
});
}
return newProps;
};

const createNavBarBackgroundImage = navBarProps => () => {
const navigationBarImage =
(NavigationBar.globalNavigationBarImage || navBarProps.navigationBarImage);

return (
<Image
source={{ uri: navigationBarImage }}
style={interpolateNavBarStyle(navBarProps)}
{...interpolateNavBarProps(navBarProps)}
/>
);
};

const NavBarComposer = {
canCompose(navBarProps) {
return !!(NavigationBar.globalNavigationBarImage || navBarProps.navigationBarImage);
},
compose(navBarProps) {
return {
renderBackground: createNavBarBackgroundImage(navBarProps),
};
},
};

export default NavBarComposer;
33 changes: 33 additions & 0 deletions navigation/children-composers/share.composer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';
import _ from 'lodash';
import {
View,
ShareButton,
} from '../../index';

const createShareButton = navBarProps => () => {
const { title, text, link } = navBarProps.share;
return (
<View virtual styleName="container">
<ShareButton
animationName={navBarProps.animationName}
title={title || navBarProps.title}
message={text}
url={link}
/>
</View>
);
};

const ShareComposer = {
canCompose(navBarProps) {
return _.get(navBarProps, 'share.link');
},
compose(navBarProps) {
return {
renderRightComponent: createShareButton(navBarProps),
};
},
};

export default ShareComposer;
49 changes: 49 additions & 0 deletions navigation/children-composers/title.composer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React from 'react';
import _ from 'lodash';
import {
View,
Title,
} from '../../index';
import { NavigationBar } from '../NavigationBar';

function hasBackgroundImage(navBarProps) {
return (NavigationBar.globalNavigationBarImage || navBarProps.navigationBarImage);
}

/**
* Check if title should be displayed or now
* @param {bool} showTitle
*/
function canShowTitle(navBarProps) {
if (!hasBackgroundImage(navBarProps)) {
return true;
} else if (NavigationBar.showTitle === false) {
return false;
}
return NavigationBar.showTitle;
}

const createTitle = navBarProps => () => {
const value = navBarProps.title;
return (
<View virtual styleName="container">
<Title animationName={navBarProps.animationName} numberOfLines={1}>
{value || ''}
</Title>
</View>
);
};

const TitleComposer = {
canCompose(navBarProps) {
const value = navBarProps.title;
return (!!value && canShowTitle(navBarProps));
},
compose(navBarProps) {
return {
renderTitleComponent: createTitle(navBarProps),
};
},
};

export default TitleComposer;
85 changes: 6 additions & 79 deletions navigation/composeChildren.js
Original file line number Diff line number Diff line change
@@ -1,90 +1,17 @@
import React, { Component } from 'react';
import Share from 'react-native-share';
import _ from 'lodash';

import {
View,
Button,
ShareButton,
Title,
Icon,
} from '../index';

const composers = {
title: (value, navBarProps) => ({
renderTitleComponent() {
return (
<View virtual styleName="container">
<Title animationName={navBarProps.animationName} numberOfLines={1}>
{value || ''}
</Title>
</View>
);
},
}),
share: (value, navBarProps) => {
if (!value.link) {
return undefined;
}

const { title, text, link } = value;

return {
renderRightComponent() {
return (
<View virtual styleName="container">
<ShareButton
animationName={navBarProps.animationName}
title={title || navBarProps.title}
message={text}
url={link}
/>
</View>
);
},
};
},
scene: (value, navBarProps) => ({
renderLeftComponent: (sceneProps) => {
if (sceneProps.scene.index === 0 || !sceneProps.onNavigateBack) {
return null;
}

return (
<View virtual styleName="container">
<Button onPress={sceneProps.onNavigateBack}>
<Icon name="back" animationName={navBarProps.animationName} />
</Button>
</View>
);
},
}),
};

/**
* Merge customizer that ignores undefined values.
* If source (usually state set by the component) has undefined
* property values, ignore those properties.
*
* @param objValue The resulting object value.
* @param srcValue The source object value.
* @returns {*} The value to use in the result.
*/
function skipUndefined(objValue, srcValue) {
return _.isUndefined(srcValue) ? objValue : srcValue;
}
import ChildrenComposers from './children-composers';

// eslint-disable-next-line react/prefer-stateless-function
const composeChildren = NavigationBarComponent => class extends Component {
render() {
const newProps = {};
_.forEach(this.props, (value, key) => {
if (_.isFunction(composers[key])) {
_.assign(newProps, composers[key](value, this.props));
}
});
ChildrenComposers
.filter(composer => composer.canCompose(this.props))
.map(composer => composer.compose(this.props))
.reduce(_.assign, newProps);

return <NavigationBarComponent {..._.assignWith(newProps, this.props, skipUndefined)} />;
return <NavigationBarComponent {..._.assign(newProps, this.props)} />;
}
};

Expand Down
Loading

0 comments on commit e24505f

Please sign in to comment.