Skip to content

Commit

Permalink
Add activityIndicator prop support
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentCATILLON committed Feb 5, 2019
1 parent 8c75828 commit a70a44e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Button extends Component {
allowFontScaling: PropTypes.bool,
isLoading: PropTypes.bool,
isDisabled: PropTypes.bool,
activityIndicator: PropTypes.object,
activityIndicatorColor: PropTypes.string,
delayLongPress: PropTypes.number,
delayPressIn: PropTypes.number,
Expand Down Expand Up @@ -70,6 +71,10 @@ class Button extends Component {

_renderInnerText() {
if (this.props.isLoading) {
if (this.props.activityIndicator) {
return this.props.activityIndicator;
}

return (
<ActivityIndicator
animating={true}
Expand Down
15 changes: 15 additions & 0 deletions Example/button/Example.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ class Example extends React.Component {
}}>
Hello
</Button>
<Button
isLoading={true}
style={styles.buttonStyle9}
onPress={() => {
console.log('world!')
}}
activityIndicator={<Text>Custom activity indicator</Text>}>
Hello
</Button>
<Button
disabledStyle={styles.buttonStyle8}
isDisabled={true}
Expand Down Expand Up @@ -172,6 +181,12 @@ const styles = StyleSheet.create({
fontWeight: '500',
color: '#333',
},
buttonStyle9: {
borderColor: '#d291bc',
backgroundColor: 'white',
borderRadius: 0,
borderWidth: 3,
},
customViewStyle: {
width: 120,
height: 40,
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ your own styles to your child elements as you see fit. Multiple children are all
| ``isLoading`` | ``bool`` | Renders an inactive state dimmed button with a spinner if ``true``. |
| ``isDisabled`` | ``bool`` | Renders an inactive state dimmed button if ``true``. |
| ``activeOpacity`` | ``Number`` | The button onpressing transparency (Usually with a point value between 0 and 1). |
| ``activityIndicator`` | ``React.Node`` | Activity indicator to use when ``isLoading`` is true. |
| ``activityIndicatorColor`` | ``string`` | Sets the button of the ``ActivityIndicatorIOS`` or ``ProgressBarAndroid`` in the loading state. |
| ``background`` | ``TouchableNativeFeedback.propTypes.background`` | **Android only**. The background prop of ``TouchableNativeFeedback``. |
Check the included example for more options.
Expand Down
11 changes: 10 additions & 1 deletion __tests__/Button.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global test */

import { View } from 'react-native'
import { Text, View } from 'react-native'
import React from 'react'
import Button from '../Button'
import renderer from 'react-test-renderer'
Expand Down Expand Up @@ -33,6 +33,15 @@ describe('Button', () => {
const tree = component.toJSON()
expect(tree).toMatchSnapshot()
})
test('Renders custom activity indicator', () => {
const component = renderer.create(
<Button isLoading={true} activityIndicator={<Text>Loading</Text>}>
Custom loader button
</Button>
)
const tree = component.toJSON()
expect(tree).toMatchSnapshot()
})
test('Renders with a inner View', () => {
const component = renderer.create(
<Button>
Expand Down

0 comments on commit a70a44e

Please sign in to comment.