Commit 93533fd
authored
## Description
Currently our components (`BaseButton`, `RectButton` and `BorderlessButton`) don't support `refs`, so it is impossible to use methods like `measure`.
This PR adds wrapper to these components, so that they are now exported as `ForwardRef`.
Fixes #2894
## Test plan
<details>
<summary> Tested on slightly modified code from issue </summary>
```jsx
import React, { useRef } from 'react';
import { Text, StyleSheet } from 'react-native';
import {
BaseButton,
BorderlessButton,
GestureHandlerRootView,
RectButton,
} from 'react-native-gesture-handler';
export default function App() {
const rectButtonRef = useRef(null);
const borderlessButtonRef = useRef(null);
const baseButtonRef = useRef(null);
const handlePress = () => {
try {
baseButtonRef.current?.measure?.((x, y, width, height) => {
console.log('baseButtonRef', x, y, width, height);
});
rectButtonRef.current?.measure?.((x, y) => {
console.log('rectButtonRef', x, y);
});
borderlessButtonRef.current?.measure?.((x, y) => {
console.log('borderlessButtonRef', x, y);
});
} catch (e) {
console.error(e);
}
};
return (
<GestureHandlerRootView style={styles.container}>
<RectButton onPress={handlePress} style={styles.button}>
<Text style={styles.text}>Press me</Text>
</RectButton>
<BaseButton ref={baseButtonRef} style={styles.button}>
<Text style={styles.text}>Test</Text>
</BaseButton>
<BorderlessButton ref={borderlessButtonRef} style={styles.button}>
<Text style={styles.text}>Test</Text>
</BorderlessButton>
<RectButton ref={rectButtonRef} style={styles.button}>
<Text style={styles.text}>Test</Text>
</RectButton>
</GestureHandlerRootView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
gap: 20,
},
button: {
justifyContent: 'center',
alignItems: 'center',
borderRadius: 5,
backgroundColor: 'grey',
paddingHorizontal: 20,
paddingVertical: 10,
},
text: {
color: 'white',
},
});
```
</details>
1 parent 33cf212 commit 93533fd
1 file changed
+36
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
68 | 72 | | |
69 | 73 | | |
70 | 74 | | |
| |||
94 | 98 | | |
95 | 99 | | |
96 | 100 | | |
| 101 | + | |
| 102 | + | |
97 | 103 | | |
98 | 104 | | |
99 | 105 | | |
| |||
108 | 114 | | |
109 | 115 | | |
110 | 116 | | |
| 117 | + | |
| 118 | + | |
111 | 119 | | |
112 | 120 | | |
113 | 121 | | |
| |||
117 | 125 | | |
118 | 126 | | |
119 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
120 | 132 | | |
121 | 133 | | |
122 | 134 | | |
123 | 135 | | |
124 | 136 | | |
125 | | - | |
| 137 | + | |
126 | 138 | | |
127 | 139 | | |
128 | 140 | | |
| |||
222 | 234 | | |
223 | 235 | | |
224 | 236 | | |
| 237 | + | |
225 | 238 | | |
226 | 239 | | |
227 | 240 | | |
| |||
231 | 244 | | |
232 | 245 | | |
233 | 246 | | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
234 | 252 | | |
235 | 253 | | |
236 | 254 | | |
| |||
243 | 261 | | |
244 | 262 | | |
245 | 263 | | |
246 | | - | |
| 264 | + | |
247 | 265 | | |
248 | 266 | | |
249 | 267 | | |
| |||
272 | 290 | | |
273 | 291 | | |
274 | 292 | | |
| 293 | + | |
275 | 294 | | |
276 | 295 | | |
277 | 296 | | |
| |||
294 | 313 | | |
295 | 314 | | |
296 | 315 | | |
297 | | - | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
298 | 322 | | |
299 | 323 | | |
300 | 324 | | |
| |||
316 | 340 | | |
317 | 341 | | |
318 | 342 | | |
319 | | - | |
| 343 | + | |
320 | 344 | | |
321 | 345 | | |
322 | 346 | | |
323 | 347 | | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
324 | 351 | | |
325 | 352 | | |
326 | 353 | | |
| |||
329 | 356 | | |
330 | 357 | | |
331 | 358 | | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
332 | 364 | | |
0 commit comments