FaridSafi / react-native-gifted-chat

💬 The most complete chat UI for React Native
https://gifted.chat
MIT License
13.44k stars 3.54k forks source link

Better type than `any` for `context` in `onPress` and `onLongPress` handlers. #2509

Open xdumaine opened 1 month ago

xdumaine commented 1 month ago

Issue Description

Would love a better type than any for context in onPress and onLongPress handlers.

as is, context.showActionSheetWithOptions(...) doesn't have any typing.

xdumaine commented 1 month ago

Looks like the better type is IGiftedChatContext but it's not an easy type swap due to some internals of how it's passed around and used on TouchableOpacity events.

Varryme commented 3 weeks ago

I see it

Varryme commented 3 weeks ago

Is it mine

xdumaine commented 2 weeks ago

Related: the onPressAvatar doesn't get this param at all, as far as I can tell. It'd be useful (for action sheet). Using this doesn't work for me, weirdly it silently fails:

const { actionSheet } = useChatContext()

const onPressAvatar = useCallback((user: User) => {
  actionSheet().showActionSheetWithOptions(...) // Fails - no error, nothing shown
}, [...]);

onLongPress = useCallback((context: IGiftedChatContext, msg: IMessage) => {
  context.actionSheet().showActionSheetWithOptions(...) // works!
}, [...]);