|
1 | | -<img alt="React Native Bounceable" src="assets/logo.png" width="1050"/> |
| 1 | +r<img alt="React Native Bounceable" src="assets/logo.png" width="1050"/> |
2 | 2 |
|
3 | 3 | [](https://github.com/WrathChaos/react-native-bounceable) |
4 | 4 |
|
@@ -49,16 +49,141 @@ You can put **ANY children component** inside the **RNBounceable** component, it |
49 | 49 | </RNBounceable> |
50 | 50 | ``` |
51 | 51 |
|
| 52 | +## Basic Examples |
| 53 | + |
| 54 | +### 1) Simple button |
| 55 | + |
| 56 | +```jsx |
| 57 | +<RNBounceable |
| 58 | + onPress={() => console.log('Pressed!')} |
| 59 | + bounceEffectIn={0.92} |
| 60 | + bounceEffectOut={1} |
| 61 | + bounceVelocityIn={0.2} |
| 62 | + bounceVelocityOut={0.45} |
| 63 | + bouncinessIn={6} |
| 64 | + bouncinessOut={0} |
| 65 | + style={{ |
| 66 | + backgroundColor: '#111827', paddingVertical: 12, paddingHorizontal: 16, borderRadius: 12, |
| 67 | + }} |
| 68 | +> |
| 69 | + <Text style={{ color: '#fff', fontWeight: '600' }}>Tap me</Text> |
| 70 | +</RNBounceable> |
| 71 | +``` |
| 72 | + |
| 73 | +### 2) Pressed feedback (function style) |
| 74 | + |
| 75 | +```jsx |
| 76 | +<RNBounceable |
| 77 | + bounceEffectIn={0.97} |
| 78 | + bounceEffectOut={1} |
| 79 | + bounceVelocityIn={0.15} |
| 80 | + bounceVelocityOut={0.4} |
| 81 | + bouncinessIn={0} |
| 82 | + bouncinessOut={0} |
| 83 | + style={(state) => [{ |
| 84 | + paddingVertical: 12, paddingHorizontal: 16, borderRadius: 12, |
| 85 | + backgroundColor: state.pressed ? '#0ea5e9' : '#3b82f6', |
| 86 | + }]} |
| 87 | + onPress={() => {}} |
| 88 | +> |
| 89 | + <Text style={{ color: '#fff', fontWeight: '600' }}>Pressed color</Text> |
| 90 | +</RNBounceable> |
| 91 | +``` |
| 92 | + |
| 93 | +### 3) Custom bounce tuning |
| 94 | + |
| 95 | +```jsx |
| 96 | +<RNBounceable |
| 97 | + bounceEffectIn={0.88} |
| 98 | + bounceEffectOut={1} |
| 99 | + bounceVelocityIn={0.35} |
| 100 | + bounceVelocityOut={0.7} |
| 101 | + bouncinessIn={16} |
| 102 | + bouncinessOut={6} |
| 103 | + style={{ backgroundColor: '#22c55e', padding: 12, borderRadius: 12 }} |
| 104 | +> |
| 105 | + <Text style={{ color: '#fff', fontWeight: '700' }}>Custom spring</Text> |
| 106 | +</RNBounceable> |
| 107 | +``` |
| 108 | + |
| 109 | +### 4) Disabled (no bounce) |
| 110 | + |
| 111 | +```jsx |
| 112 | +<RNBounceable disabled style={{ |
| 113 | + backgroundColor: '#9ca3af', padding: 12, borderRadius: 12, opacity: 0.6, |
| 114 | +}}> |
| 115 | + <Text style={{ color: '#fff' }}>Disabled</Text> |
| 116 | +</RNBounceable> |
| 117 | +``` |
| 118 | + |
| 119 | +### 5) onPressIn / onPressOut |
| 120 | + |
| 121 | +```jsx |
| 122 | +<RNBounceable |
| 123 | + bounceEffectIn={0.95} |
| 124 | + bounceEffectOut={1} |
| 125 | + bounceVelocityIn={0.25} |
| 126 | + bounceVelocityOut={0.5} |
| 127 | + bouncinessIn={10} |
| 128 | + bouncinessOut={0} |
| 129 | + onPressIn={() => console.log('press in')} |
| 130 | + onPressOut={() => console.log('press out')} |
| 131 | + style={{ backgroundColor: '#111827', padding: 12, borderRadius: 12 }} |
| 132 | +> |
| 133 | + <Text style={{ color: '#fff' }}>Press events</Text> |
| 134 | +</RNBounceable> |
| 135 | +``` |
| 136 | + |
| 137 | +### 6) Long press |
| 138 | + |
| 139 | +```jsx |
| 140 | +<RNBounceable |
| 141 | + bounceEffectIn={0.85} |
| 142 | + bounceEffectOut={1} |
| 143 | + bounceVelocityIn={0.4} |
| 144 | + bounceVelocityOut={0.65} |
| 145 | + bouncinessIn={14} |
| 146 | + bouncinessOut={4} |
| 147 | + onLongPress={() => console.log('long press')} |
| 148 | + delayLongPress={300} |
| 149 | + style={{ backgroundColor: '#111827', padding: 12, borderRadius: 12 }} |
| 150 | +> |
| 151 | + <Text style={{ color: '#fff' }}>Hold me</Text> |
| 152 | +</RNBounceable> |
| 153 | +``` |
| 154 | + |
| 155 | +### 7) Icon / Image as child |
| 156 | + |
| 157 | +```jsx |
| 158 | +<RNBounceable |
| 159 | + bounceEffectIn={0.9} |
| 160 | + bounceEffectOut={1} |
| 161 | + bounceVelocityIn={0.5} |
| 162 | + bounceVelocityOut={0.6} |
| 163 | + bouncinessIn={18} |
| 164 | + bouncinessOut={6} |
| 165 | + onPress={() => {}} |
| 166 | + style={{ height: 44, width: 44, borderRadius: 22, alignItems: 'center', justifyContent: 'center', backgroundColor: '#fff' }} |
| 167 | +> |
| 168 | + <Text style={{ fontSize: 20 }}>❤️</Text> |
| 169 | +</RNBounceable> |
| 170 | +``` |
| 171 | + |
52 | 172 | # Configuration - Props |
53 | 173 |
|
54 | | -| Property | Type | Default | Description | |
55 | | -| --------------- | :------: | :-------: | ------------------------------------------------ | |
56 | | -| onPress | function | undefined | set your own logic for the onPress functionality | |
57 | | -| style | style | undefined | set the style like any other View container | |
58 | | -| bounceEffect | number | 0.9 | change the bounce effect's value | |
59 | | -| bounceFriction | number | 3 | change the bounce effect's friction value | |
60 | | -| useNativeDriver | boolean | true | change the useNativeDriver's usage | |
61 | | -| animate | function | default | activate the bounce effect animation | |
| 174 | +| Property | Type | Default | Description | |
| 175 | +| ------------------ | :----------------: | :-----: | ---------------------------------------------------------- | |
| 176 | +| onPress | function | - | Callback for press | |
| 177 | +| style | Pressable `style` | - | Style object/array or function `(state) => style` | |
| 178 | +| bounceEffectIn | number | 0.93 | Scale value applied on press in | |
| 179 | +| bounceEffectOut | number | 1 | Scale value applied on press out | |
| 180 | +| bounceVelocityIn | number | 0.1 | Spring velocity for press in | |
| 181 | +| bounceVelocityOut | number | 0.4 | Spring velocity for press out | |
| 182 | +| bouncinessIn | number | 0 | Spring bounciness for press in | |
| 183 | +| bouncinessOut | number | 0 | Spring bounciness for press out | |
| 184 | +| useNativeDriver | boolean | true | Use native driver for animation | |
| 185 | + |
| 186 | +All React Native `Pressable` props are supported and forwarded (including `onPressIn`, `onPressOut`, `disabled`, and `ref`). The bounce effect is skipped when `disabled` is true. |
62 | 187 |
|
63 | 188 | ## Future Plans |
64 | 189 |
|
|
0 commit comments