Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions src/components/hyper-ref/hyper-ref.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,22 @@ export default class HyperRef extends PureComponent<Props, State> {
const style = this.getStyle();
const { accessibilityLabel, testID } = createTestProps(this.props.element);
const { onLongPress, onPress, onPressIn, onPressOut } = pressHandlers;
const elementHasAction = !!this.props.element.getAttribute('action');
const elementHasHref = !!this.props.element.getAttribute('href');
const hasActionablePressBehavior = behaviors.some(behaviorElement => {
const behaviorAction = (
behaviorElement.getAttribute(BEHAVIOR_ATTRIBUTES.ACTION) || ''
).toLowerCase();
const behaviorHref = behaviorElement.getAttribute(
BEHAVIOR_ATTRIBUTES.HREF,
);
return (
(behaviorAction !== '' && behaviorAction !== 'amplitude') ||
!!behaviorHref
);
});
const disabled =
!elementHasAction && !elementHasHref && !hasActionablePressBehavior;

// If element is a <text> nested under another <text>, simply add press events
const isNestedUnderText =
Expand All @@ -310,22 +326,25 @@ export default class HyperRef extends PureComponent<Props, State> {
return (
<Text
accessibilityLabel={accessibilityLabel}
accessibilityState={disabled ? { disabled: true } : undefined}
accessible={false}
onLongPress={onLongPress}
onLongPress={disabled ? undefined : onLongPress}
// when no press handler set, we still need an empty handler for pressIn or pressOut
// handlers to work
onPress={
onPress ||
(onPressIn !== undefined || onPressOut !== undefined
? noop
: undefined)
disabled
? undefined
: onPress ||
(onPressIn !== undefined || onPressOut !== undefined
? noop
: undefined)
}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore TS2300: no overload matches this call
onResponderGrant={onPressIn}
onResponderGrant={disabled ? undefined : onPressIn}
// Both release and terminate responder are needed to properly pressOut
onResponderRelease={onPressOut}
onResponderTerminate={onPressOut}
onResponderRelease={disabled ? undefined : onPressOut}
onResponderTerminate={disabled ? undefined : onPressOut}
style={style}
suppressHighlighting
testID={testID}
Expand All @@ -338,8 +357,10 @@ export default class HyperRef extends PureComponent<Props, State> {
return (
<TouchableOpacity
accessibilityLabel={accessibilityLabel}
accessibilityState={disabled ? { disabled: true } : undefined}
accessible={false}
activeOpacity={1}
disabled={disabled}
onLongPress={onLongPress}
onPress={onPress}
onPressIn={onPressIn}
Expand Down