react-native-pressable-scale
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

A Pressable that scales down when pressed.

npm i react-native-pressable-scale



<PressableScale>

Requires react-native-reanimated (v2)

A component for responding to touches using a React Native <TouchableWithoutFeedback>

<PressableScale onPress={onBuyPressed} style={styles.buyButton}>
  <Text>Buy this Product</Text>
</PressableScale>

The following props are supported:

Name Type Explanation Required Default Value
activeScale number The scale to animate to use when the <PressableScale> is in a pressed state. Ranges from 0 to 1 0.95
weight 'light' | 'medium' | 'heavy' The weight to use for the spring animation. This should act as a predefined preset for the mass property of the spring config. 'heavy'
All TouchableWithoutFeedback props TouchableWithoutFeedbackProps All properties from the React Native TouchableWithoutFeedback component such as onPress, delayPressIn or style. { delayPressIn: 0 }

<NativePressableScale>

A supercharged <PressableScale>.

Requires react-native-gesture-handler and react-native-reanimated (v2)

A component for responding to touches using the native TapGestureHandler without ever going over the JS Bridge. Use this component if you want your Pressables to be able to receive touches, respond to touches, show visual animated feedback (scale down/scale up) and dispatch a callback to JS without using the React Native Thread at all. This component will always be pressable, even when the React Native (JS) Thread freezes because of a heavy JS computation.

⚠️ Warning: This does not work in Modals on Android devices. See software-mansion/react-native-gesture-handler issue #139

<NativePressableScale onPress={onBuyPressed} style={styles.buyButton}>
  <Text>Buy this Product</Text>
</NativePressableScale>

The following props are supported:

Name Type Explanation Required Default Value
activeScale number The scale to animate to use when the <PressableScale> is in a pressed state. Ranges from 0 to 1 0.95
weight 'light' | 'medium' | 'heavy' The weight to use for the spring animation. This should act as a predefined preset for the mass property of the spring config. 'heavy'
onPress () => void The event to fire after the <PressableScale> has been pressed by the user. undefined
isInList boolean A flag indicating whether this <PressableScale> is rendered in a ScrollView, FlatList or any other component that uses a swipe gesture. This will delay the animation for 50ms so swipe gestures don't immediately trigger scale changes false
disabled boolean A flag indicating whether this <PressableScale> should be disabled and therefore stop receiving touch events. false
ref React.RefObject<TapGestureHandler> A reference to the <TapGestureHandler> component. false
All View props ViewProps All properties from the React Native View component such as style or children. {}
All WithSpringConfig props WithSpringConfig All properties from the react-native-reanimated withSpring options parameter such as Easing or duration. { duration: 50, easing: Easing.linear }

Also try

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.1.0
    212
    • latest

Version History

Package Sidebar

Install

npm i react-native-pressable-scale

Weekly Downloads

246

Version

2.1.0

License

MIT

Unpacked Size

20.4 kB

Total Files

15

Last publish

Collaborators

  • mrousavy