-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle Pressable function style prop #138
Conversation
Hey @codybrouwers, thanks for looking into this! The solution looks fine but it currently throws some typescript errors because the style prop is typed as Could you have a look at fixing that? |
@sbalay sure thing, will take a look this weekend! |
@sbalay Made some adjustments and got all of the types working, let me know what you think! |
Thanks @codybrouwers! I'll have a look during this week. |
src/hooks/useRestyle.ts
Outdated
return [style, props.style].filter(Boolean); | ||
const styleProp = props.style; | ||
if (typeof styleProp === 'function') { | ||
return (...args: any[]) => [style, styleProp(...args)]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it is worth having the .filter(Boolean)
on this returned array as well?
should we revert this PR in order to solve #159 ? |
Agree, @sbalay would that be possible to revert this change or rewrite in a way that doesn't break typesafety? |
Currently when using the style prop along with Restyle provided props, only style objects are accepted but the Pressable component also accepts a function in order to access the
pressed
state.This PR detects if the style prop is a function and if so, returns another function that merges the Restyle generated styles and the style prop styles.
I just threw together this fix in a few minutes so maybe there is some edge cases I haven't thought of, feel free to disregard if the problem is actually a lot harder then my small fix. It does work locally for me at least.
Thanks!
Should resolve #58