diff --git a/examples/example/App.tsx b/examples/example/App.tsx index d7f44b30..9525cc1a 100644 --- a/examples/example/App.tsx +++ b/examples/example/App.tsx @@ -7,10 +7,11 @@ import { DripsyProvider, Container, Theme, + Pressable, } from 'dripsy' // Import from core import { H4 } from '@dripsy/core' -import { Text } from 'react-native' +import { Text, Pressable as RNPressable } from 'react-native' const theme = { useBodyStyles: false, @@ -84,20 +85,35 @@ export default function App() { height: [400, 800], }} > -

Test

- {/* - {({ pressed }) => ( - - {pressed ? 'Joi!' : 'Press Me'} - - )} - */} +

Test

Hey Hi! Card + + {({ pressed }) => + + } + + ({ + height: 50, + width: 50, + backgroundColor: pressed ? 'green' : 'red', + })} + /> diff --git a/packages/core/src/components/index.tsx b/packages/core/src/components/index.tsx index b8def2d5..92a67267 100644 --- a/packages/core/src/components/index.tsx +++ b/packages/core/src/components/index.tsx @@ -24,6 +24,7 @@ import { import { createThemedComponent } from '../css/create-themed-component' import Indicator from './activity-indicator' +export { default as Pressable } from './pressable' export const View = createThemedComponent(rView) diff --git a/packages/core/src/components/pressable.tsx b/packages/core/src/components/pressable.tsx new file mode 100644 index 00000000..7b9712a4 --- /dev/null +++ b/packages/core/src/components/pressable.tsx @@ -0,0 +1,49 @@ +import React, { ComponentProps } from 'react' +import { styled } from '../css/styled' +import { Pressable as NativePressable, Platform } from 'react-native' + +declare module 'react-native' { + interface PressableStateCallbackType { + hovered?: boolean + focused?: boolean + } +} + +const StyledPressable = styled(NativePressable)({}) +const Press = React.forwardRef(function Pressable( + { + sx = {}, + style, + disabled, + ...props + }: ComponentProps, + ref: ComponentProps['ref'] +) { + // TODO: Pressable accepts a function as a style with the computed properties figure out a way to pass these along + if (style) + console.error( + `[dripsy] Hey there. Looks like you used an invalid prop "style" on the Pressable component. Please use the `sx` prop directly instead, or use a child function. If this is a problem feel free to open an issue on github.` + ) + + return ( + + ) +}) + +export default Press