Skip to content

Commit

Permalink
fix: button state based styling in native devices
Browse files Browse the repository at this point in the history
  • Loading branch information
rajat693 committed Aug 22, 2024
1 parent d56b859 commit 18a13fa
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import React, { useMemo } from 'react';
import { createButton } from '@gluestack-ui/button';
import { Svg } from 'react-native-svg';
import type { PressableProps } from 'react-native';
import { tva } from '@gluestack-ui/nativewind-utils/tva';
import {
withStyleContext,
Expand All @@ -20,6 +21,12 @@ import {
import type { VariantProps } from '@gluestack-ui/nativewind-utils';

const SCOPE = 'BUTTON';
const ButtonWrapper = React.forwardRef<
React.ElementRef<typeof Pressable>,
PressableProps
>(({ ...props }, ref) => {
return <Pressable {...props} ref={ref} />;
});

type IPrimitiveIcon = React.ComponentPropsWithoutRef<typeof Svg> & {
height?: number | string;
Expand Down Expand Up @@ -81,8 +88,8 @@ const PrimitiveIcon = React.forwardRef(

const Root =
Platform.OS === 'web'
? withStyleContext(Pressable, SCOPE)
: withStyleContextAndStates(Pressable, SCOPE);
? withStyleContext(ButtonWrapper, SCOPE)
: withStyleContextAndStates(ButtonWrapper, SCOPE);

const UIButton = createButton({
Root: Root,
Expand All @@ -92,7 +99,7 @@ const UIButton = createButton({
Icon: withStates(PrimitiveIcon),
});

cssInterop(UIButton, { className: 'style' });
cssInterop(Root, { className: 'style' });
cssInterop(UIButton.Text, { className: 'style' });
cssInterop(UIButton.Group, { className: 'style' });
cssInterop(UIButton.Spinner, {
Expand Down

0 comments on commit 18a13fa

Please sign in to comment.