Skip to content

Commit

Permalink
Added Activity Indicator to button element
Browse files Browse the repository at this point in the history
*Accepts the following new props. loading, loadingLeft,
activityIndicatorStyle
  • Loading branch information
Jeanmsilva89 committed Oct 6, 2016
1 parent a727262 commit 86ee3a6
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/buttons/Button.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -14,6 +14,9 @@ const log = () => {
const Button = ({
Component,
disabled,
loading,
loadingLeft,
activityIndicatorStyle,
buttonStyle,
borderRadius,
title,
Expand Down Expand Up @@ -68,6 +71,17 @@ const Button = ({
name={icon.name} />
)
}
let loadingElement;
if(loading){
loadingElement = (
<ActivityIndicator
animating={true}
style={[styles.activityIndicatorStyle, activityIndicatorStyle]}
color={color || "white"}
size={small && "small" || "large"}
/>
)
}
if (!Component && Platform.OS === 'ios') {
Component = TouchableHighlight
}
Expand Down Expand Up @@ -112,6 +126,9 @@ const Button = ({
{
icon && !iconRight && iconElement
}
{
loading && !loadingLeft && loadingElement
}
<Text
style={[
styles.text,
Expand All @@ -124,6 +141,9 @@ const Button = ({
]}>
{title}
</Text>
{
loading && loadingLeft && loadingElement
}
{
icon && iconRight && iconElement
}
Expand All @@ -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({
Expand Down Expand Up @@ -178,6 +199,10 @@ styles = StyleSheet.create({
smallFont: {
fontSize: 14
},
activityIndicatorStyle: {
marginHorizontal: 10,
height: 0
},
raised: {
...Platform.select({
ios: {
Expand Down

0 comments on commit 86ee3a6

Please sign in to comment.