1.2.1 • Published 4 years ago

react-native-better-buttons v1.2.1

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

react-native-better-buttons

npm license

Base components for move-to-cancel and long-press-to-cancel views

Features

  • LongPressButton: Cancels actions after longPressTimout elapses
  • MoveAwayButton: Cancels actions when user's finger moves outside button
  • useLongPress: Hook for changing from pressed to longPressed state
  • useMeasurement: Hook for determining the View's dimensions relative to the page (minX, maxX, minY, maxY)
  • Ripple: Click effect for buttons. Derived from react-native-material-ripple

LongPressButton MoveAwayButton Ripple

Installation

npm install --save react-native-better-buttons

Usage

LongPressButton

<LongPressButton
  style={theme.button}
  pressedStyle={theme.buttonPressed}
  onPressOut={() => {}}>
  <Text>LongPressButton</Text>
</LongPressButton>

MoveAwayButton

const { pressed, setPressed } = useLongPress()

const handleClick = () => {
  if (pressed) {
    onClick()
  }
  setPressed(false)
}

return (
  <MoveAwayButton
    style={[styles.card, pressed && styles.cardPressed]}
    pressed={pressed}
    setPressed={setPressed}
    onPressOut={handleClick}>
    <Text style={[styles.text, pressed && styles.textPressed]}>
      MoveAwayButton
    </Text>
  </MoveAwayButton>
)

useMeasurement

const { dimensions, setRef } = useMeasurement(buffer)

const handlePressIn = (e: GestureResponderEvent) => {
  const { pageX, pageY } = e.nativeEvent
  const { minX, maxX, minY, maxY } = dimensions
  // Do work
}

return (
  <View
    ref={setRef}
    onStartShouldSetResponder={() => true}
    onResponderGrant={handlePressIn}
  />
)

Properties

namedescriptiontypedefault
rippleColorRipple colorStringrgb(0, 0, 0)
rippleOpacityRipple opacityNumber0.3
rippleDurationRipple duration in msNumber400
rippleResetRipples before resetting. Prevents animation issues.Number10
rippleSizeRipple size restrictionNumber0
rippleContainerBorderRadiusRipple container border radiusNumber0
rippleCenteredRipple always starts from centerBooleanfalse
disableRippleFadeRipple does not fade outBooleanfalse
disableRippleView is used instead of RippleBooleanfalse
disableRippleOnPressInonPressIn ripple is disabledBooleanfalse
rippleOnPressRipples onPressBooleanfalse
rippleOnPressOutRipples onPressOutBooleanfalse
onPressInTouch moved in or started callbackFunction-
onRippleAnimationAnimation start callbackFunction-
longPressTimoutTime in ms before action is cancelledNumber800
moveCancelBufferExtra buffer before move away cancels actionNumber10

Other View properties will also work

Copyright and License

MIT License

Copyright 2020 Jordan Wilking. All rights reserved.