Skip to content

Instantly share code, notes, and snippets.

@Misaka-0x447f
Created August 18, 2021 03:48
Show Gist options
  • Save Misaka-0x447f/69ef54aaf7689ad1554f98aada28eaaf to your computer and use it in GitHub Desktop.
Save Misaka-0x447f/69ef54aaf7689ad1554f98aada28eaaf to your computer and use it in GitHub Desktop.
react native 创建基于原生组件的透明组件
// 合并的方式不是给 style 传一个可能带 function 的 array,而是给 style 传一个返回值一定不带 function 的 (whatever: any) => unknown[]
export const PressableWithFeedback: React.FC<PressableProps> = props => {
return (
<Pressable
{...props}
style={args => [
isFunction(props.style) ? props.style(args) : props.style,
{
backgroundColor: args.pressed ? 'white' : 'transparent',
},
]}
/>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment