1.0.2 • Published 2 years ago

react-native-expo-swipe-button v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

react-native-expo-swipe-button

NPM Status

ezgif com-gif-maker(1)

A swipe button ready-to-use and highly customizable

Installations

npm install react-native-expo-swipe-button --save
yarn install react-native-expo-swipe-button

Usage

import { SwipeButton } from 'react-native-expo-swipe-button';

function Home(): JSX.Element {
  return (
    <View
      style={{
        flex: 1,
        justifyContent: 'center',
        backgroundColor: 'white',
        flexDirection: 'column',
      }}
    >
      <SwipeButton
        Icon={
          <MaterialIcons name="keyboard-arrow-right" size={50} color="white" />
        }
        onComplete={() => Alert.alert('Completed')}
        title="Swipe to complete"
        borderRadius={180}
        containerStyle={{ backgroundColor: 'gray' }}
        underlayTitle="Release to complete"
        underlayTitleStyle={{ color: 'white' }}
      />
      <SwipeButton
        Icon={
          <MaterialIcons name="keyboard-arrow-right" size={50} color="white" />
        }
        onComplete={() => {}}
        title="Gradient swipe"
        borderRadius={180}
        containerGradientProps={{
          colors: ['red', 'cyan'],
          start: [0, 0.5],
          end: [1, 0.5],
        }}
        underlayTitle="Release to complete"
        underlayStyle={{
          borderRadius: 180,
        }}
        underlayContainerGradientProps={{
          colors: ['green', 'yellow'],
          start: [0, 0.5],
          end: [1, 0.5],
        }}
      />
      <SwipeButton
        Icon={
          <MaterialIcons name="keyboard-arrow-right" size={50} color="white" />
        }
        onComplete={() => {}}
        title="Custom format swipe"
        borderRadius={25}
        containerStyle={{
          backgroundColor: 'transparent',
          borderWidth: 0,
          borderColor: 'red',
        }}
        underlayStyle={{
          borderRadius: 0,
          borderWidth: 5,
          borderColor: 'red',
          backgroundColor: 'transparent',
        }}
        underlayTitle="Release to complete"
        underlayTitleStyle={{ color: 'white' }}
        completeThresholdPercentage={50}
        goBackToStart
        titleElement={
          <LinearGradient
            colors={['red', 'yellow']}
            style={[styles.titleContainer, { height: 60, borderRadius: 25 }]}
            start={[0, 0.5]}
            end={[1, 0.5]}
          >
            <Text
              numberOfLines={2}
              allowFontScaling={false}
              style={[styles.title]}
            >
              Full custom swipe
            </Text>
          </LinearGradient>
        }
        underlayTitleElement={
          <LinearGradient
            colors={['pink', 'yellow']}
            style={[styles.titleContainer, { height: 60, borderRadius: 25 }]}
            start={[0, 0.5]}
            end={[1, 0.5]}
          >
            <Text
              numberOfLines={2}
              allowFontScaling={false}
              style={[styles.title]}
            >
              Release to complete
            </Text>
          </LinearGradient>
        }
      />
    </View>
  );
}

Properties

PropDescriptionTypeDefaultIs Required
disabledIf disabled is set to true it will not be possible to interact with the button.booleanfalseno
completeThresholdPercentageDetermine when onComplete should be invoked.number70%no
goBackToStartIf true, the circle will go back to the start position after swipe is completed.booleanfalseno
widthThe width of the component.number90%no
heightThe height of the component.number70no
circleSizedefine the size of the circle buttonnumber70no
underlayStyleThe styling of the underlay containerStyleProp<ViewStyle>{position: 'absolute',backgroundColor: '#152228',borderTopStartRadius: DEFAULT_BORDER_RADIUS,borderBottomStartRadius: DEFAULT_BORDER_RADIUS,borderBottomEndRadius: DEFAULT_BORDER_RADIUS, borderTopEndRadius: DEFAULT_BORDER_RADIUS }no
containerStyleStyling of the outer containerStyleProp<ViewStyle>{backgroundColor: 'white',alignSelf: 'center',justifyContent: 'center', marginVertical: 10 }no
iconContainerStyleThe styling of the buttonStyleProp<ViewStyle>{ position: 'absolute', backgroundColor: 'black', alignItems: 'center', justifyContent: 'center' }no
borderRadiusThe border radius of the container and the Iconnumberheight / 2no
containerGradientPropsgradient props for the container. Using this will actually use a linear gradient as view{ colors?: string[]; } & Omit<LinearGradientProps, 'colors' | 'style'>noneno
underlayContainerGradientPropsgradient props for the underlayContainer. Using this will actually use a linear gradient as view{ colors?: string[]; } & Omit<LinearGradientProps, 'colors' | 'style'>noneno
IconElement that should be displayed inside the buttonJSX.Elementnoneyes
circleBackgroundColorBackground color for the circlestringblackno
borderRadiusset border radius for the circlenumbernoneno
titleThe text that will be displayed in the containerstringnoneyes
titleExtraTextPropsAdditional props for the title textTextPropsnoneno
titleStyleAdditional styling for the title textStyleProp<TextStyle>{ color: 'black', fontSize: 16, maxWidth: '50%', textAlign: 'center' }no
titleContainerExtraViewPropsAdditional props for the title containerViewPropsnoneno
titleContainerStyleAdditional styling for the title containerStyleProp<ViewStyle>{ justifyContent: 'center', alignItems: 'center' }no
titleElementAn JSX element you can define to replace the title default component. Using this will omit the others title propsJSX.Elementnoneno
underlayTitleThe text that will be displayed in the underlay containerstring''no
underlayTitleExtraTextPropsAdditional props for the underlay title textTextPropsnoneno
underlayTitleStyleAdditional styling for the underlay title textStyleProp<TextStyle>{ color: 'black', fontSize: 16, maxWidth: '50%', textAlign: 'center' }no
underlayTitleContainerExtraViewPropsAdditional props for the underlay title containerViewPropsnoneno
underlayTitleContainerStyleAdditional styling for the underlay title containerStyleProp<ViewStyle>{ justifyContent: 'center' alignItems: 'center' }no
underlayTitleElementAn JSX element you can define to replace the underlay title default component. Using this will omit the others title propsJSX.Elementnoneno
onCompleteCallback that will be invoked when complete threshold has been reached() => voidnoneyes
onSwipeProgresscallback for swiping in progress(progress: number) => voidnoneno
onSwipeStartCallback that will be invoked when the user starts swiping() => voidnoneno
onSwipeEndCallback that will be invoked when the user ends swiping() => voidnoneno

A complete minimal example can be found Here.

Known issues

Contributing

See the contributing guide to learn how to contribute to the repository.

License

MIT