From 86ee3a63c8e32001642c2a56be88c041b60ef064 Mon Sep 17 00:00:00 2001 From: Jean Silva Date: Thu, 6 Oct 2016 08:09:28 -0400 Subject: [PATCH] Added Activity Indicator to button element *Accepts the following new props. loading, loadingLeft, activityIndicatorStyle --- src/buttons/Button.js | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/buttons/Button.js b/src/buttons/Button.js index 0e3d94f80d..6f3f3691a7 100644 --- a/src/buttons/Button.js +++ b/src/buttons/Button.js @@ -1,5 +1,5 @@ import React, { PropTypes } from 'react' -import { TouchableWithoutFeedback, TouchableNativeFeedback, TouchableOpacity, TouchableHighlight, StyleSheet, View, Platform } from 'react-native' +import { TouchableWithoutFeedback, TouchableNativeFeedback, TouchableOpacity, TouchableHighlight, StyleSheet, View, Platform, ActivityIndicator } from 'react-native' import colors from '../config/colors' import Text from '../text/Text' import MaterialIcon from 'react-native-vector-icons/MaterialIcons' @@ -14,6 +14,9 @@ const log = () => { const Button = ({ Component, disabled, + loading, + loadingLeft, + activityIndicatorStyle, buttonStyle, borderRadius, title, @@ -68,6 +71,17 @@ const Button = ({ name={icon.name} /> ) } + let loadingElement; + if(loading){ + loadingElement = ( + + ) + } if (!Component && Platform.OS === 'ios') { Component = TouchableHighlight } @@ -112,6 +126,9 @@ const Button = ({ { icon && !iconRight && iconElement } + { + loading && !loadingLeft && loadingElement + } {title} + { + loading && loadingLeft && loadingElement + } { icon && iconRight && iconElement } @@ -149,7 +169,8 @@ Button.propTypes = { underlayColor: PropTypes.string, raised: PropTypes.bool, textStyle: PropTypes.any, - disabled: PropTypes.bool + disabled: PropTypes.bool, + loading: PropTypes.bool } styles = StyleSheet.create({ @@ -178,6 +199,10 @@ styles = StyleSheet.create({ smallFont: { fontSize: 14 }, + activityIndicatorStyle: { + marginHorizontal: 10, + height: 0 + }, raised: { ...Platform.select({ ios: {