Skip to content

Commit 79a23dd

Browse files
committed
fix(TouchableOpacity): bind event to bara with React event.persist() to preserve its props
1 parent c18daa6 commit 79a23dd

File tree

1 file changed

+37
-12
lines changed

1 file changed

+37
-12
lines changed

src/lib/exports/TouchableOpacity/TouchableOpacity.tsx

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,56 @@ export const TouchableOpacity = React.forwardRef(
2424
ref: any,
2525
) => {
2626
const context = useBaraContext()
27-
const onPress: typeof _onPress = e => {
28-
context.components.touchableOpacity.onPress({ name, kind, ...props })
27+
28+
const onPress: typeof _onPress = event => {
29+
event.persist()
30+
context.components.touchableOpacity.onPress({
31+
name,
32+
kind,
33+
event,
34+
...props,
35+
})
2936
if (_onPress) {
30-
_onPress(e)
37+
_onPress(event)
3138
}
3239
}
3340

34-
const onPressIn: typeof _onPressIn = e => {
35-
context.components.touchableOpacity.onPressIn({ name, kind, ...props })
41+
const onPressIn: typeof _onPressIn = event => {
42+
event.persist()
43+
context.components.touchableOpacity.onPressIn({
44+
name,
45+
kind,
46+
event,
47+
...props,
48+
})
3649
if (_onPressIn) {
37-
_onPressIn(e)
50+
_onPressIn(event)
3851
}
3952
}
4053

41-
const onPressOut: typeof _onPressOut = e => {
42-
context.components.touchableOpacity.onPressOut({ name, kind, ...props })
54+
const onPressOut: typeof _onPressOut = event => {
55+
event.persist()
56+
context.components.touchableOpacity.onPressOut({
57+
name,
58+
kind,
59+
event,
60+
...props,
61+
})
4362
if (_onPressOut) {
44-
_onPressOut(e)
63+
_onPressOut(event)
4564
}
4665
}
4766

48-
const onLongPress: typeof _onLongPress = e => {
49-
context.components.touchableOpacity.onLongPress({ name, kind, ...props })
67+
const onLongPress: typeof _onLongPress = event => {
68+
event.persist()
69+
context.components.touchableOpacity.onLongPress({
70+
name,
71+
kind,
72+
event,
73+
...props,
74+
})
5075
if (_onLongPress) {
51-
_onLongPress(e)
76+
_onLongPress(event)
5277
}
5378
}
5479

0 commit comments

Comments
 (0)