标签: pressable

在 React Native 中 HitRect 如何与 Pressable 一起使用?

我们计划从 TouchableOpacity 切换到 Pressable。

我们希望使用 Pressable 的可选 HitRec 来确保我们的命中目标大小适当(我们将计算尺寸)以实现可访问性。

Pressable 文档没有有关使用 HitRect 的信息。我在其他地方找到了对 HitRect 的引用,但它们也没有有用的信息。

任何人都可以描述如何使用 Pressable 实现 HitRect 吗?

react-native pressable

3
推荐指数
1
解决办法
1370
查看次数

来自 Pressable TypeScript 错误的自定义 TouchableOpacity

有这个自定义 TouchableOpacity 函数组件,但对于 style prop 我收到了 TS 错误

\n
import { StyleSheet, Pressable, PressableProps, GestureResponderEvent } from 'react-native';\n\nexport default function TouchableOpacity(props: PressableProps) {\n  const { style, onPress, children } = props;\n\n  return (\n    <Pressable\n      onPress={(event: GestureResponderEvent) => {\n        onPress?.(event);\n      }}\n      style={({ pressed }) => [style, pressed ? styles.buttonPressedOpacity : null]}>\n      {children}\n    </Pressable>\n  );\n}\n\nconst styles = StyleSheet.create({\n  buttonPressedOpacity: {\n    opacity: 0.5,\n  },\n});\n
Run Code Online (Sandbox Code Playgroud)\n

以下是完整的 TS 投诉:

\n
\n

TS2322: 类型 '({ pressable}: PressableStateCallbackType) =>\n(StyleProp | ((state: PressableStateCallbackType) =>\nStyleProp<...>) | { ...; …

typescript react-native touchableopacity pressable

2
推荐指数
1
解决办法
844
查看次数