Skip to content

Added common components #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jan 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ module.exports = {
"import/no-extraneous-dependencies": "off",
"import/default": "off",
"import/namespace": "off",
"import/no-absolute-path": "error"
"import/no-absolute-path": "error",
"react/no-typos": "off"
},
"settings": {
"import/resolver": {
Expand Down
44 changes: 44 additions & 0 deletions generators/app/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,44 @@ module.exports.CUSTOM_TEXT_PATH = `${module.exports.COMPONENTS_PATH}/CustomText`
module.exports.CUSTOM_TEXT = `${module.exports.CUSTOM_TEXT_PATH}/index.js`;
module.exports.CUSTOM_TEXT_STYLES = `${module.exports.CUSTOM_TEXT_PATH}/styles.js`;

// COMPONENTS - CUSTOM TEXT INPUT
module.exports.CUSTOM_TEXT_INPUT_PATH = `${module.exports.COMPONENTS_PATH}/CustomTextInput`;
module.exports.CUSTOM_TEXT_INPUT = `${module.exports.CUSTOM_TEXT_INPUT_PATH}/index.js`;
module.exports.CUSTOM_TEXT_INPUT_STYLES = `${module.exports.CUSTOM_TEXT_INPUT_PATH}/styles.js`;
module.exports.CUSTOM_TEXT_INPUT_ASSETS_PATH = `${module.exports.CUSTOM_TEXT_INPUT_PATH}/assets`;
module.exports.CUSTOM_TEXT_INPUT_ASSETS_VISIBILITY = `${
module.exports.CUSTOM_TEXT_INPUT_ASSETS_PATH
}/ic_visibility.png`;
module.exports.CUSTOM_TEXT_INPUT_ASSETS_VISIBILITY_2X = `${
module.exports.CUSTOM_TEXT_INPUT_ASSETS_PATH
}/[email protected]`;
module.exports.CUSTOM_TEXT_INPUT_ASSETS_VISIBILITY_3X = `${
module.exports.CUSTOM_TEXT_INPUT_ASSETS_PATH
}/[email protected]`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dunno. It's likely this ic_visibility is being repeated over and over

module.exports.CUSTOM_TEXT_INPUT_ASSETS_VISIBILITY_OFF = `${
module.exports.CUSTOM_TEXT_INPUT_ASSETS_PATH
}/ic_visibility_off.png`;
module.exports.CUSTOM_TEXT_INPUT_ASSETS_VISIBILITY_OFF_2X = `${
module.exports.CUSTOM_TEXT_INPUT_ASSETS_PATH
}/[email protected]`;
module.exports.CUSTOM_TEXT_INPUT_ASSETS_VISIBILITY_OFF_3X = `${
module.exports.CUSTOM_TEXT_INPUT_ASSETS_PATH
}/[email protected]`;
module.exports.CUSTOM_TEXT_INPUT_SHOW_PASSWORD_PATH = `${
module.exports.CUSTOM_TEXT_INPUT_PATH
}/components/ShowPassword`;
module.exports.CUSTOM_TEXT_INPUT_SHOW_PASSWORD = `${
module.exports.CUSTOM_TEXT_INPUT_SHOW_PASSWORD_PATH
}/index.js`;
module.exports.CUSTOM_TEXT_INPUT_SHOW_PASSWORD_STYLES = `${
module.exports.CUSTOM_TEXT_INPUT_SHOW_PASSWORD_PATH
}/styles.js`;

// COMPONENTS - CUSTOM TEXT
module.exports.CUSTOM_BUTTON_PATH = `${module.exports.COMPONENTS_PATH}/CustomButton`;
module.exports.CUSTOM_BUTTON = `${module.exports.CUSTOM_BUTTON_PATH}/index.js`;
module.exports.CUSTOM_BUTTON_STYLES = `${module.exports.CUSTOM_BUTTON_PATH}/styles.js`;

// COMPONENTS - DRAWER
module.exports.DRAWER_PATH = `${module.exports.COMPONENTS_PATH}/Drawer`;
module.exports.DRAWER_INDEX = `${module.exports.DRAWER_PATH}/index.js`;
Expand All @@ -54,6 +92,11 @@ module.exports.DRAWER_OVERLAY_PATH = `${module.exports.DRAWER_PATH}/components/D
module.exports.DRAWER_OVERLAY_INDEX = `${module.exports.DRAWER_OVERLAY_PATH}/index.js`;
module.exports.DRAWER_OVERLAY_STYLES = `${module.exports.DRAWER_OVERLAY_PATH}/styles.js`;

// COMPONENTS - LOADABLE
module.exports.LOADABLE_PATH = `${module.exports.COMPONENTS_PATH}/Loadable`;
module.exports.LOADABLE = `${module.exports.LOADABLE_PATH}/index.js`;
module.exports.LOADABLE_STYLES = `${module.exports.LOADABLE_PATH}/styles.js`;

// REDUX
module.exports.REDUX_STORE = `${module.exports.REDUX_PATH}/store.js`;

Expand Down Expand Up @@ -93,6 +136,7 @@ module.exports.ROUTES_CONSTANTS = `${module.exports.CONSTANTS_PATH}/routes.js`;
module.exports.ARRAY_UTILS = `${module.exports.UTILS_PATH}/arrayUtils.js`;
module.exports.I18N_UTILS = `${module.exports.UTILS_PATH}/i18nUtils.js`;
module.exports.NAV_UTILS = `${module.exports.UTILS_PATH}/navUtils.js`;
module.exports.STYLE_UTILS = `${module.exports.UTILS_PATH}/styleUtils.js`;

// TEST
module.exports.ARRAY_UTILS_TESTS = `${module.exports.TEST_PATH}/utils/arrayUtils.spec.js`;
Expand Down
30 changes: 30 additions & 0 deletions generators/app/tasks/appSetup/baseFilesTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ const {
APP_NAVIGATOR,
CUSTOM_TEXT,
CUSTOM_TEXT_STYLES,
CUSTOM_BUTTON,
CUSTOM_BUTTON_STYLES,
CUSTOM_TEXT_INPUT,
CUSTOM_TEXT_INPUT_STYLES,
CUSTOM_TEXT_INPUT_ASSETS_VISIBILITY,
CUSTOM_TEXT_INPUT_ASSETS_VISIBILITY_2X,
CUSTOM_TEXT_INPUT_ASSETS_VISIBILITY_3X,
CUSTOM_TEXT_INPUT_ASSETS_VISIBILITY_OFF,
CUSTOM_TEXT_INPUT_ASSETS_VISIBILITY_OFF_2X,
CUSTOM_TEXT_INPUT_ASSETS_VISIBILITY_OFF_3X,
CUSTOM_TEXT_INPUT_SHOW_PASSWORD,
CUSTOM_TEXT_INPUT_SHOW_PASSWORD_STYLES,
LOADABLE,
LOADABLE_STYLES,
PLATFORM_CONSTANTS,
COLORS_CONSTANTS,
ROUTES_CONSTANTS,
Expand All @@ -21,6 +35,7 @@ const {
I18N_CONFIG,
I18N_UTILS,
NAV_UTILS,
STYLE_UTILS,
INDEX,
APP,
SCREENS
Expand All @@ -35,13 +50,28 @@ const FILES = [
APP_NAVIGATOR,
CUSTOM_TEXT,
CUSTOM_TEXT_STYLES,
CUSTOM_BUTTON,
CUSTOM_BUTTON_STYLES,
CUSTOM_TEXT_INPUT,
CUSTOM_TEXT_INPUT_STYLES,
CUSTOM_TEXT_INPUT_ASSETS_VISIBILITY,
CUSTOM_TEXT_INPUT_ASSETS_VISIBILITY_2X,
CUSTOM_TEXT_INPUT_ASSETS_VISIBILITY_3X,
CUSTOM_TEXT_INPUT_ASSETS_VISIBILITY_OFF,
CUSTOM_TEXT_INPUT_ASSETS_VISIBILITY_OFF_2X,
CUSTOM_TEXT_INPUT_ASSETS_VISIBILITY_OFF_3X,
CUSTOM_TEXT_INPUT_SHOW_PASSWORD,
CUSTOM_TEXT_INPUT_SHOW_PASSWORD_STYLES,
LOADABLE,
LOADABLE_STYLES,
PLATFORM_CONSTANTS,
COLORS_CONSTANTS,
ARRAY_UTILS,
ARRAY_UTILS_TESTS,
I18N_CONFIG,
I18N_UTILS,
NAV_UTILS,
STYLE_UTILS,
TEST_ESLINT_CONFIG,
HOME_STYLES
];
Expand Down
3 changes: 2 additions & 1 deletion generators/app/templates/.eslintrc.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module.exports = {
"import/named": "error",
"import/default": "error",
"import/namespace": "error",
"import/no-absolute-path": "error"
"import/no-absolute-path": "error",
"react/no-typos": "off"
}
};
63 changes: 63 additions & 0 deletions generators/app/templates/src/app/components/CustomButton/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React, { PureComponent } from 'react';
import { TouchableOpacity, Image, ViewPropTypes } from 'react-native';
import PropTypes from 'prop-types';

import CustomText from '../CustomText';
import { getCustomStyles } from '../../../utils/styleUtils';

import styles from './styles';

class CustomButton extends PureComponent {
static VARIANTS = ['borderless', 'radial', 'black', 'green', 'white', 'gray'];

customStyles = () => getCustomStyles(CustomButton.VARIANTS, this.props, styles);

customTextStyles = () => getCustomStyles(CustomButton.VARIANTS, this.props, styles, 'Content');

render() {
const {
onPress,
style,
activeOpacity,
icon,
title,
iconStyle,
disabled,
textStyle,
...textProps
} = this.props;
// TODO: Set android ripple while pressing a button
return (
<TouchableOpacity
onPress={onPress}
style={[styles.container, this.customStyles(), style]}
activeOpacity={activeOpacity}
disabled={disabled}
>
{icon && <Image source={icon} resizeMode="contain" style={[styles.icon, iconStyle]} />}
{title && (
<CustomText {...textProps} style={[styles.text, this.customTextStyles(), textStyle]}>
{title}
</CustomText>
)}
</TouchableOpacity>
);
}
}

CustomButton.defaultProps = {
activeOpacity: 1
};

CustomButton.propTypes = {
activeOpacity: PropTypes.number,
disabled: PropTypes.bool,
icon: PropTypes.number,
iconStyle: ViewPropTypes.style,
onPress: PropTypes.func.isRequired,
style: ViewPropTypes.style,
textStyle: PropTypes.number,
title: PropTypes.string
};

export default CustomButton;
54 changes: 54 additions & 0 deletions generators/app/templates/src/app/components/CustomButton/styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { StyleSheet } from 'react-native';

import { transparent, black, green, gray, white } from '../../../constants/colors';

const iconSize = 20;

const borderlessStyle = {
borderWidth: 0,
backgroundColor: transparent
};

export default StyleSheet.create({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export default at the bottom

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think that we have all export default of styles file like @ignaciosantise wrote.
In components maybe, but in style files i like this. Really there is not difference

Copy link
Author

@ignaciosantise ignaciosantise Jan 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mvbattan if we are changing the export position of Stylesheets, we should change all of them in another PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, let's do it in another PR

container: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
padding: 8
},
icon: {
height: iconSize,
width: iconSize
},
borderless: borderlessStyle,
radial: {
borderRadius: 100
},
black: {
backgroundColor: black
},
blackContent: {
color: white
},
white: {
backgroundColor: white
},
whiteContent: {
color: black
},
gray: {
backgroundColor: gray
},
grayContent: {
color: black
},
borderlessContent: {
color: gray
},
green: {
backgroundColor: green
},
text: {
color: black
}
});
11 changes: 6 additions & 5 deletions generators/app/templates/src/app/components/CustomText/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { Text } from 'react-native';

import { getCustomStyles } from '../../../utils/styleUtils';

import styles from './styles';

export default class CustomText extends PureComponent {
class CustomText extends PureComponent {
/*
** You can add styles to Base like Family Font to be the Text styles base!
** if you want to add a custom style, you need to add it here and in VARIANTS
Expand All @@ -24,10 +26,7 @@ export default class CustomText extends PureComponent {
'gray'
];

customStyles = () =>
CustomText.VARIANTS
.map(variant => (this.props[variant] ? styles[variant] : null))
.filter(style => style !== null);
customStyles = () => getCustomStyles(CustomText.VARIANTS, this.props, styles);

render() {
return (
Expand All @@ -50,3 +49,5 @@ CustomText.propTypes = {
CustomText.VARIANTS.forEach(variant => {
CustomText.propTypes[variant] = PropTypes.bool;
});

export default CustomText;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import PropTypes from 'prop-types';
import { TouchableOpacity, Image } from 'react-native';

import icVisible from '../../assets/ic_visibility.png';
import icVisibleOff from '../../assets/ic_visibility_off.png';

import styles from './styles';

const ShowPassword = ({ onShowPassword, passwordVisible }) => (
<TouchableOpacity onPress={onShowPassword} style={styles.container}>
<Image source={passwordVisible ? icVisible : icVisibleOff} resizeMode="contain" style={styles.icon} />
</TouchableOpacity>
);

ShowPassword.propTypes = {
onShowPassword: PropTypes.func.isRequired,
passwordVisible: PropTypes.bool.isRequired
};

export default ShowPassword;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { StyleSheet } from 'react-native';

export default StyleSheet.create({
container: {
display: 'flex',
flexDirection: 'row',
alignItems: 'center'
},
icon: {
width: 20,
marginLeft: 8
}
});
Loading