Skip to content

Control pressable component styles #66

Description

@SergeyYuhimovich

What is the best way to style dynamic components, which style could change (i.e. during user interaction)?

For instance, I've created this custom Button component:

type Props = SpacingShorthandProps<Theme> &
  VariantProps<Theme, 'buttonVariants'> & {
    label?: string;
    onPress: () => void;
  };

export const Button = ({ label, onPress, ...rest }: Props) => {
  const props = useRestyle(restyleFunctions, rest);

  return (
    <Pressable onPress={onPress} {...props}>
      <Text variant="text">{label}</Text>
    </Pressable>
  );
};

and using it like this somewhere outside:

<Button variant='primary' onPress={_onPress} label='Submit' />

So the task is to somehow apply different styles when button is being pressed. Do I need to create another variant but for pressed state (like, primaryPressed) and somehow change the variant from outside? Or is there something I missed when reading docs and there's easier way to do this?

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions