1.0.12 • Published 7 years ago

react-native-animatable-button v1.0.12

Weekly downloads
1
License
ISC
Repository
github
Last release
7 years ago

react-native-animatable-button

npm version

Installation

npm install react-native-animatable-button --save

Overview

  • States
  • Opacity animation
  • Tap animations
  • Fully customizable

Props

Button Props

PropsTypeDescriptionRequiredDefault
accessibilityLabelstringcustom access labelnot requiredreactNativeAnimetableButton
buttonContainerStyleObjectmust be provided Object not STYLEnot requiredsee below
selectedStatestringselected id of provided statesnot requireddefault
stateskey: string: IButtonStatestate objectnot requireddefault state
disabledbooleanenable/disable buttonnot requiredfalse
touchFeedbaackbooleanenable/disable tap opacity animatenot requiredtrue
touchFeedbaackDelaybooleanset delayPressIn prop of TOpacitynot required0

Button Animation Props

PropsTypeDescriptionRequiredDefault
animationDelaynumberdelay of animationsnot required0
animationDurationnumberanimation duration timenot required400
animationEasingEasingFunctioneasing optionsnot requiredEasing.bezier(0.4, 0.2, 0.4, 1.3)
onPressAnimationEnablebooleantap animation confignot requiredtrue
onPressAnimationScaleValuenumbernumber of scale tonot required1.05
onPressAnimationTypebutton - insidescale all button or insidenot requiredbutton
startAnimationDelaynumberdelay of start animationnot required0
startAnimationDurationnumberanimation duration time for startnot required400
startAnimationEnablebooleanenable/disable start animationnot requiredtrue
backgroundAnimationanimated - slideset background optionnot requiredanimated

Button State Props

PropsTypeDescriptionRequiredDefault
buttonInsideContainerStyleObjectmust be provided Object not STYLEnot requiredsee below
iconImageURISource - anyicon uri or sourcenot required-
iconStyleImageStyleicon stylenot requiredsee below
iconPositionleft - rightposition of iconnot requiredleft
textstringbutton textnot required-
textStyleTextStyletext stylenot requiredsee below
spinnerbooleanenable/disable spinnernot requiredfalse
spinnerPropsActivityIndicatorPropertiesspinner Propsnot required-
syncIconAndTextAnimationbooleanenable/disable animation diffnot requiredfalse
asyncIconAndTextAnimationDiffnumber 0 - 100percent of diffnot required50

buttonContainerStyle

{
  backgroundColor: 'rgba(0,0,0,0)',
  borderRadius: 5,
  borderWidth: 1,
  height: ButtonSize.height,
  overflow: 'hidden'
}

buttonInsideContainerStyle

{
  alignItems: 'center',
  backgroundColor: 'rgba(0,0,0,0)',
  flexDirection: 'row',
  height: ButtonSize.height,
  justifyContent: 'center',
  overflow: 'hidden',
  paddingHorizontal: 10
}

textStyle

{
  paddingHorizontal: 5
}

iconStyle

{
  flex: 1,
  resizeMode: 'contain'
}

Note

Master props and state props are combined when provided.

Usage example

constructor() {
  super();

  this.state = {
  activeState: 'idle2'
  }
}

render () {
  <Button	
    touchFeedback={false}
    onPress={this.onPress.bind(this)}
    selectedState={this.state.activeState}
    buttonContainerStyle={{
      height: 40
    }}
    buttonInsideContainerStyle={{
      backgroundColor: 'rgba(100,100,100,0.5)'
    }}
    onPress={() => { 
      console.log('master pressed');
      if (this.state.activeState === 'idle2') this.setState({ activeState: 'idle' });	
    }}
    states={{
      laodList: {
        text:"Load List",
        buttonInsideContainerStyle:{
          backgroundColor: 'rgba(255,0,0,0.5)'
        },
        onPress: () => { 
          console.log('loadList pressed'); 
          this.setState({ activeState: 'loading' })
          
          return false; 
        }
      },
      // when tap laodList logs => loadList pressed; master pressed

      loading: {
        text:"loading",
        buttonInsideContainerStyle:{
          backgroundColor: 'rgba(0,255,0,0.5)'
        },
        spinner: true,
        onPress: () => { console.log('loading pressed'); return true; }
      },
      // when tap loading logs => loading pressed;

      idle: {
        text:"idle",
        onPress: () => { 
          console.log('idle pressed');
          this.setState({ activeState: 'loadList' })
        }
      },
      // when tap idle logs => idle pressed; master pressed

      idle2: {
        text:"idle2",
      }
      // when tap idle2 logs => master pressed
    }}
  />
}

Description

if you are return false or undefined in sub onPress functions when call master onPress function.