-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
227 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,122 @@ | ||
# pressto | ||
https://github.com/user-attachments/assets/c857eb8d-3ce7-4afe-b2dd-e974560684d8 | ||
|
||
Some custom react native touchables | ||
The fastest way to improve your React Native app is by using tap gestures. | ||
That's why I've created **pressto**, a super-simple package to help you get started. | ||
|
||
The package is built on top of the Tap Gesture from [react-native-gesture-handler](https://docs.swmansion.com/react-native-gesture-handler/) to handle the resulting gestures and animations on the main thread. It aims to replace your “TouchableOpacity”. | ||
|
||
## Installation | ||
|
||
```sh | ||
npm install pressto | ||
yarn add pressto react-native-reanimated react-native-gesture-handler | ||
``` | ||
|
||
Or with Expo | ||
|
||
```sh | ||
npx expo install pressto react-native-reanimated react-native-gesture-handler | ||
``` | ||
|
||
## Features | ||
|
||
- Pre-built animated pressable components: `PressableScale` and `PressableOpacity` | ||
- Easy creation of custom animated pressables with `createAnimatedPressable` | ||
- Configurable animation types and durations | ||
|
||
## Usage | ||
|
||
```js | ||
import { multiply } from 'pressto'; | ||
### Use basic Pressables: PressableScale and PressableOpacity | ||
|
||
// ... | ||
```jsx | ||
import React from 'react'; | ||
import { StyleSheet, View } from 'react-native'; | ||
import { PressableOpacity, PressableScale } from 'pressto'; | ||
|
||
function BasicPressablesExample() { | ||
return ( | ||
<View style={styles.container}> | ||
<PressableScale style={styles.box} onPress={() => console.log('scale')} /> | ||
<PressableOpacity style={styles.box} onPress={() => console.log('opacity')} /> | ||
</View> | ||
); | ||
} | ||
|
||
const result = await multiply(3, 7); | ||
``` | ||
|
||
### Create a custom Pressable with createAnimatedPressable | ||
|
||
```jsx | ||
import { createAnimatedPressable } from 'pressto'; | ||
|
||
const PressableRotate = createAnimatedPressable((progress) => ({ | ||
transform: [ | ||
{ rotate: `${progress.value * Math.PI / 4}rad` }, | ||
], | ||
})); | ||
|
||
function CustomPressableExample() { | ||
return ( | ||
<View style={styles.container}> | ||
<PressableRotate style={styles.box} onPress={() => console.log('rotate')} /> | ||
</View> | ||
); | ||
} | ||
``` | ||
|
||
### Use the PressablesConfig | ||
|
||
```jsx | ||
import React from 'react'; | ||
import { gestureHandlerRootHOC } from 'react-native-gesture-handler'; | ||
import { PressablesConfig } from 'pressto'; | ||
|
||
function App() { | ||
return ( | ||
<View style={styles.container}> | ||
<PressableRotate style={styles.box} onPress={() => console.log('rotate')} /> | ||
<PressableScale style={styles.box} onPress={() => console.log('scale')} /> | ||
<PressableOpacity style={styles.box} onPress={() => console.log('opacity')} /> | ||
</View> | ||
); | ||
} | ||
|
||
export default () => ( | ||
<PressablesConfig animationType="spring" config={{ mass: 2 }} globalHandlers={{ | ||
onPress: () => { | ||
console.log('you can call haptics here'); | ||
} | ||
}}> | ||
<App /> | ||
</PressablesConfig> | ||
) | ||
``` | ||
|
||
## API | ||
|
||
### PressableScale | ||
|
||
A pressable component that scales when pressed. | ||
|
||
### PressableOpacity | ||
|
||
A pressable component that changes opacity when pressed. | ||
|
||
### createAnimatedPressable | ||
|
||
A function to create custom animated pressables. It takes a worklet function that defines how the component should animate based on the press progress. | ||
|
||
### PressablesConfig | ||
|
||
A component to configure global settings for all pressable components within its children. | ||
|
||
## Contributing | ||
|
||
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow. | ||
Contributions are welcome! Please see our [contributing guide](CONTRIBUTING.md) for more details. | ||
|
||
## License | ||
|
||
MIT | ||
|
||
--- | ||
|
||
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob) | ||
Made with ❤️ using [create-react-native-library](https://github.com/callstack/react-native-builder-bob) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.