From 1b83fb1164c7731025ae73cb6849a2d7a24f3145 Mon Sep 17 00:00:00 2001 From: Wim Selles Date: Sun, 9 Sep 2018 08:01:21 +0200 Subject: [PATCH 1/2] feature: add new button to support accessibility - add testproperties method - add accessibility to the screens --- js/components/Button.js | 134 ++++++++++++++++++++++++++++++++++++ js/components/LoginForm.js | 23 ++++--- js/config/TestProperties.js | 22 ++++++ js/screens/Forms.js | 6 +- js/screens/Home.js | 6 +- js/screens/Login.js | 6 +- js/screens/Swipe.js | 6 +- 7 files changed, 188 insertions(+), 15 deletions(-) create mode 100644 js/components/Button.js create mode 100644 js/config/TestProperties.js diff --git a/js/components/Button.js b/js/components/Button.js new file mode 100644 index 0000000..96c4797 --- /dev/null +++ b/js/components/Button.js @@ -0,0 +1,134 @@ +import React, { Component } from 'react'; +import { + ActivityIndicator, + StyleSheet, + Text, + TouchableOpacity, + View, + ViewPropTypes +} from 'react-native'; +import PropTypes from 'prop-types'; +import { testProperties } from '../config/TestProperties'; + +class Button extends Component { + static propTypes = { + backgroundColor: PropTypes.string, + containerStyle: ViewPropTypes.style, + disabled: PropTypes.bool, + loading: PropTypes.bool, + onPress: PropTypes.func.isRequired, + testID: PropTypes.string, + text: PropTypes.string, + textStyle: Text.propTypes.style, + }; + + static defaultProps = { + backgroundColor: 'transparent', + containerStyle: null, + disabled: false, + loading: false, + testID: null, + text: null, + textStyle: null, + }; + + onButtonPress = () => { + const { onPress, loading } = this.props; + + if (loading) return; + + return onPress(); + }; + + get textStyle() { + const { icon, loading, textStyle, disabled } = this.props; + const style = [styles.text]; + + if (icon || loading) { + style.push(styles.textOffset); + } + + style.push(textStyle); + + if (disabled) { + style.push(styles.disabledText); + } + + return style; + } + + renderText = () => { + const { text } = this.props; + + if (this.props.loading) { + return null; + } + + if (text) { + return {text}; + } + + return null; + }; + + renderIcon = () => { + if (this.props.loading) { + return ; + } + + return this.props.icon; + }; + + render() { + const { + text, + disabled, + testID, + backgroundColor, + containerStyle, + } = this.props; + + return ( + + + {this.renderIcon()} + {this.renderText()} + + + ); + } +} + +const styles = StyleSheet.create({ + container: { + minHeight: 40, + }, + content: { + flex: 1, + flexDirection: 'row', + paddingHorizontal: 15, + justifyContent: 'center', + alignItems: 'center', + }, + disabledContent: { + backgroundColor: '#E0E6E8', + }, + text: { + textAlign: 'center', + color: '#000', + alignSelf: 'center', + }, + textOffset: { + marginLeft: 5, + }, + disabledText: { + color: '#252525', + }, +}); + +export default Button; diff --git a/js/components/LoginForm.js b/js/components/LoginForm.js index ba512ce..e6005cb 100644 --- a/js/components/LoginForm.js +++ b/js/components/LoginForm.js @@ -13,9 +13,11 @@ import { KeyboardAvoidingView, Alert, } from 'react-native'; -import { Input, Button } from 'react-native-elements' +import { Input } from 'react-native-elements' import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import { WINDOW_WIDTH } from '../config/Constants'; +import { testProperties } from '../config/TestProperties'; +import Button from './Button'; import TitleDivider from './TitleDivider'; // Enable LayoutAnimation on Android @@ -134,18 +136,16 @@ class LoginForm extends Component {