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

Switch disappears on touchableOpacity onPress #27094

Closed
theo-mesnil opened this issue Nov 2, 2019 · 2 comments
Closed

Switch disappears on touchableOpacity onPress #27094

theo-mesnil opened this issue Nov 2, 2019 · 2 comments
Labels
Bug Component: Switch Component: TouchableOpacity Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@theo-mesnil
Copy link

React Native version: SDK 35 (with expo)

Steps To Reproduce

  1. I have an Item who is a TouchableOpacity
export const More = ({ screenProps: { setThemeName, themeName } }) => {
  const setTheme = () => setThemeName(themeName === 'dark' ? '' : 'dark')

  return (
   <Item activeOpacity={0.6} isLast onPress={setTheme}>
      <Item.Content>
         <Item.Title>Use dark mode</Item.Title>
         <Item.Subtitle>Get that whiteness out of my sight</Item.Subtitle>
      </Item.Content>
      <Switch onChange={setTheme} value={themeName === 'dark'} />
   </Item>
  )
}
  1. And inside a Switch component
export const Switch = props => {
  const theme = useContext(ThemeContext)

  return (
    <SwitchNative
      ios_backgroundColor={theme.colors.light500}
      thumbColor={theme.switch.thumb}
      trackColor={{ false: theme.colors.light500, true: theme.colors.primary500 }}
      {...props}
    />
  )
}

When i press on the Item (who is a TouchableOpacity) my Switch dissapears :

switchIssue

I don't know if i'm doing wrong or if is a bug =)

Thanks !

If you want to see my styled components for the Item :

import styled, { css } from 'styled-components/native'

import { centeredStyled } from './Centered'

export const List = styled.View(
  ({ theme }) => css`
    width: 100%;
    background-color: ${theme.background.ahead};
    padding: ${theme.space.xl} 0 ${theme.space.sm};
    margin-bottom: ${theme.space.sm};
  `
)

List.Title = styled.Text(
  ({ theme }) => css`
    ${centeredStyled}
    font-family: 'bold';
    color: ${theme.colors.primary500};
    font-size: ${theme.fontSizes.h4};
    text-transform: uppercase;
  `
)

export const Item = styled.TouchableOpacity(
  ({ isLast, theme }) => css`
    ${centeredStyled};
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding: ${isLast
      ? `${theme.space.xl} ${theme.space.xl} ${theme.space.xs}`
      : `${theme.space.xl}`};
    border-bottom-width: ${isLast ? 0 : theme.borderWidths.sm};
    border-color: ${theme.colors.light700};
  `
)

Item.Content = styled.View`
  flex-direction: column;
  width: auto;
`

Item.Title = styled.Text(
  ({ theme }) => css`
    color: ${theme.colors.dark900};
    font-size: ${theme.fontSizes.body1};
  `
)

Item.Subtitle = styled.Text(
  ({ theme }) => css`
    color: ${theme.colors.light100};
    font-size: ${theme.fontSizes.body2};
    padding-top: 2;
  `
)
@stale
Copy link

stale bot commented Jan 31, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Jan 31, 2020
@stale
Copy link

stale bot commented Feb 8, 2020

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Feb 8, 2020
@facebook facebook locked as resolved and limited conversation to collaborators Feb 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Component: Switch Component: TouchableOpacity Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

2 participants