-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from cmaycumber/pressable
Pressable
- Loading branch information
Showing
3 changed files
with
75 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |