Skip to content

Commit

Permalink
[Button] Auto import LinearGradient if Expo (#943)
Browse files Browse the repository at this point in the history
* Warning only for non-expo user

* Auto import LinearGradient on Expo

* Show warning if non-expo user

* Update example

* Update snapshot
  • Loading branch information
martinezguillaume authored and iRoachie committed Feb 28, 2018
1 parent 21bdbb1 commit 3a1c746
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
11 changes: 4 additions & 7 deletions src/buttons/Button.js
Expand Up @@ -21,20 +21,17 @@ const log = () => {

class Button extends Component {
componentDidMount() {
if (
this.props.linearGradientProps != null &&
this.props.ViewComponent == null
) {
const { linearGradientProps, ViewComponent } = this.props;
if (linearGradientProps && !global.Expo && !ViewComponent) {
/* eslint-disable no-console */
console.error(
`You need to pass a ViewComponent to use linearGradientProps !\nExample: ViewComponent={require('expo').LinearGradient}`
`You need to pass a ViewComponent to use linearGradientProps !\nExample: ViewComponent={require('react-native-linear-gradient')}`
);
}
}

render() {
const {
ViewComponent,
TouchableComponent,
containerStyle,
onPress,
Expand All @@ -50,6 +47,7 @@ class Button extends Component {
iconContainerStyle,
iconRight,
linearGradientProps,
ViewComponent = linearGradientProps && global.Expo ? global.Expo.LinearGradient : View,
...attributes
} = this.props;

Expand Down Expand Up @@ -132,7 +130,6 @@ Button.defaultProps = {
iconRight: false,
TouchableComponent:
Platform.OS === 'ios' ? TouchableOpacity : TouchableNativeFeedback,
ViewComponent: View,
onPress: log,
clear: false,
loadingProps: {
Expand Down
2 changes: 0 additions & 2 deletions src/pricing/__tests__/__snapshots__/PricingCard.js.snap
Expand Up @@ -131,7 +131,6 @@ exports[`PricingCard component should render with props 1`] = `
</TextElement>
<Button
TouchableComponent={[Function]}
ViewComponent={[Function]}
buttonStyle={
Array [
Object {
Expand Down Expand Up @@ -283,7 +282,6 @@ exports[`PricingCard component should render without issues 1`] = `
</TextElement>
<Button
TouchableComponent={[Function]}
ViewComponent={[Function]}
buttonStyle={
Array [
Object {
Expand Down

0 comments on commit 3a1c746

Please sign in to comment.