Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ListItem touchable only when onPress props is present #2859

Open
michel-reyes opened this issue Dec 3, 2024 · 1 comment
Open

ListItem touchable only when onPress props is present #2859

michel-reyes opened this issue Dec 3, 2024 · 1 comment

Comments

@michel-reyes
Copy link

Current behavior

Event if the user does not pass onPress the listItem visual behavior is touchable, due to the wrapper: <TouchableOpactity>
i.e: compare: <DemoCommunityScreen> vs DemoDebugScreen

Solution overview

A way to fix this in the ListItem component is by conditionally render the TouchableOpacity, this is a functional code sample:

// PATH: app/components/ListItem.tsx

// check if obPress props is present
const isTouchable = TouchableOpacityProps.onPress !== undefined

const content = (
  <>
    <ListItemAction
      side="left"
      size={height}
      icon={leftIcon}
      iconColor={leftIconColor}
      Component={LeftComponent}
    />

    <Text {...TextProps} tx={tx} text={text} txOptions={txOptions} style={themed($textStyles)}>
      {children}
    </Text>

    <ListItemAction
      side="right"
      size={height}
      icon={rightIcon}
      iconColor={rightIconColor}
      Component={RightComponent}
    />
  </>
)

return (
  <View ref={ref} style={themed($containerStyles)}>
    {/* make the item touchable if required */}
    {isTouchable ? (
      <TouchableOpacity {...TouchableOpacityProps} style={$touchableStyles}>
        {content}
      </TouchableOpacity>
    ) : (
      {/* it could be raw View, styledView or React Fragment */}
      <View style={$touchableStyles}>{content}</View>
    )}
  </View>
)
@frankcalise
Copy link
Contributor

Hey thanks for the report! This is true, but should we check onPressIn/onPressOut as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants