Skip to content

Commit

Permalink
Merge pull request #81 from cmaycumber/pressable
Browse files Browse the repository at this point in the history
Pressable
  • Loading branch information
nandorojo authored May 7, 2021
2 parents 45ca0fc + 3c0205f commit b59984b
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 9 deletions.
34 changes: 25 additions & 9 deletions examples/example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -84,20 +85,35 @@ export default function App() {
height: [400, 800],
}}
>
<H4 sx={{ color: 'text', mb: 2, mt: 0, fontSize: [5] }}>Test</H4>
{/* <Pressable>
{({ pressed }) => (
<DripText sx={{ cursor: 'pointer' }}>
{pressed ? 'Joi!' : 'Press Me'}
</DripText>
)}
</Pressable> */}
<H4 sx={{ color: 'text', mb: 2, mt: 0, fontSize: [5] }}>Test</H4>
<G variant="primary">Hey</G>
<G>Hi!</G>
<View sx={{ bg: 'white', boxShadow: 'md' }}>
<Text>Card</Text>
</View>
<ResponsiveSquare />
<Pressable
sx={{
height: 50,
width: 50,
}}
>
{({ pressed }) =>
<View
sx={{
flex: 1,
backgroundColor: pressed ? 'green' : 'red',
}}
/>
}
</Pressable>
<RNPressable
style={({ pressed }) => ({
height: 50,
width: 50,
backgroundColor: pressed ? 'green' : 'red',
})}
/>
</View>
</Container>
</DripsyProvider>
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
49 changes: 49 additions & 0 deletions packages/core/src/components/pressable.tsx
Original file line number Diff line number Diff line change
@@ -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<typeof StyledPressable>,
ref: ComponentProps<typeof NativePressable>['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 (
<StyledPressable
{...props}
// TODO: Figure out why the pressable type is wrong
ref={ref as any}
disabled={disabled}
sx={{
...Platform.select({
web: {
cursor:
props.onPress || props.accessibilityRole === 'link' || !disabled
? 'pointer'
: 'default',
},
}),
...sx,
}}
/>
)
})

export default Press

0 comments on commit b59984b

Please sign in to comment.