Skip to content

Commit 02a1d4f

Browse files
EvanBaconkmagiera
authored andcommitted
[web] Fixed buttons (software-mansion#644)
The buttons don't style or function as expected in the browser. This fixes the bugs related to them (only tested on web so far).
1 parent a0ea0f1 commit 02a1d4f

4 files changed

+21
-15
lines changed

GestureHandlerButton.web.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import React from 'react';
2-
import { TouchableWithoutFeedback, View } from 'react-native';
2+
import { TouchableOpacity } from 'react-native';
33

4-
export default class RNGestureHandlerButton extends React.Component {
5-
render() {
6-
const { children, ...rest } = this.props;
7-
8-
return (
9-
<TouchableWithoutFeedback accessibilityRole="button" {...rest}>
10-
<View>{children}</View>
11-
</TouchableWithoutFeedback>
12-
);
13-
}
14-
}
4+
// Use TouchableOpacity with the transparency disabled to most closely emulate
5+
// the native view's ability to wrap children and apply styles.
6+
export default React.forwardRef((props, ref) => (
7+
<TouchableOpacity
8+
ref={ref}
9+
accessibilityRole="button"
10+
{...props}
11+
activeOpacity={1.0}
12+
focusOpacity={1.0}
13+
/>
14+
));

PlatformConstants.web.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
export default {
2-
forceTouchAvailable: false,
2+
get forceTouchAvailable() {
3+
return false;
4+
},
35
};

touchables/TouchableOpacity.web.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import { TouchableOpacity } from 'react-native';
2+
export default TouchableOpacity;

touchables/TouchableWithoutFeedback.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import GenericTouchable from './GenericTouchable';
21
import React from 'react';
2+
import GenericTouchable from './GenericTouchable';
33

4-
const TouchableWithoutFeedback = props => <GenericTouchable {...props} />;
4+
const TouchableWithoutFeedback = React.forwardRef((props, ref) => (
5+
<GenericTouchable ref={ref} {...props} />
6+
));
57

68
TouchableWithoutFeedback.defaultProps = GenericTouchable.defaultProps;
79

0 commit comments

Comments
 (0)