Skip to content

Commit

Permalink
feat(messy): add onPress to list message
Browse files Browse the repository at this point in the history
  • Loading branch information
vokhuyetOz committed May 31, 2024
1 parent 44523f8 commit 83d064d
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 45 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ import { Messy } from '@vokhuyet/react-native-messy';
listProps={{
onEndReached,
ListHeaderComponent: ChatListHeader,
onPress: () => {
//hide all bottom sheet modal inlcuding: emoji picker,...
dismissAll();
//hide keyboard
Keyboard.dismiss();
},
}}
messageProps={{
hideOwnerAvatar: true,
Expand Down Expand Up @@ -205,7 +211,7 @@ input: {
- `user`([TUser](#tuser)): sender information;
- `theme`: ([TColor](#tcolor)): custom theme for message;
- `footerProps`([TMessyFooterProps](#tmessyfooterprops)): Custom props for Element below list messages;
- `listProps`(TListProps): custom flatlist props;
- `listProps`(TListProps): custom flatlist props and onPress event;
- `messageProps`([TMessageProps](#tmessageprops));
- `parsedShape`([ParseShape[]](https://github.com/taskrabbit/react-native-parsed-text)): Custom parse patterns for react-native-parsed-text ;
- `showDateTime`(boolean): show created time of message;
Expand Down
96 changes: 59 additions & 37 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,57 +276,79 @@ function ExtraLeft({ animatedPosition }) {
elevation: 6,
}}
animationConfigs={{ duration: 300 }}
snapPoints={[100, 600]}
snapPoints={[100, '90%']}
animatedPosition={animatedPosition}
>
<Text style={{ alignSelf: 'center' }}>Demo</Text>
</BottomSheetModal>
</View>
);
}
const App = () => {
function BasicExample() {
const [mess, setMess] = useState([...mockMessage.reverse()]);

const { dismissAll } = useBottomSheetModal();
return (
<Messy
BaseModule={{
Image: ImageV,
Cache: {
get: MMKVwithID.getMap,
set: MMKVwithID.setMap,
},
}}
messageProps={{
hideOwnerAvatar: true,
hidePartnerAvatar: false,
onPress: () => {
console.log('press item');
},
onLongPress: () => {
console.log('long press item');
},
}}
listProps={{
onStartReached: () => {
console.log('onStartReached');
},
onEndReached: () => {
console.log('onEndReached');
},
onPress: () => {
//hide all bottom sheet modal
dismissAll();
//hide keyboard
Keyboard.dismiss();
},
}}
messages={mess}
user={{ id: 2 }}
footerProps={{
onSend: async (message: TMessyMessage) => {
message;
mess.unshift(message);
setMess([...mess]);
// upload image
setTimeout(() => {
//@ts-ignore
mess[0].status = 'sent';
setMess([...mess]);
}, 2000);

//send to server by socket
},
ExtraLeft: <ExtraLeft />,
}}
/>
);
}
const App = () => {
return (
<GestureHandlerRootView style={{ flex: 1 }}>
<SafeAreaView style={{ flex: 1 }}>
<BottomSheetModalProvider>
<KeyboardProvider>
<Messy
BaseModule={{
Image: ImageV,
Cache: {
get: MMKVwithID.getMap,
set: MMKVwithID.setMap,
},
}}
listProps={{
onStartReached: () => {
console.log('onStartReached');
},
onEndReached: () => {
console.log('onEndReached');
},
}}
messages={mess}
user={{ id: 2 }}
footerProps={{
onSend: async (message: TMessyMessage) => {
message;
mess.unshift(message);
setMess([...mess]);
// upload image
setTimeout(() => {
//@ts-ignore
mess[0].status = 'sent';
setMess([...mess]);
}, 2000);

//send to server by socket
},
ExtraLeft: <ExtraLeft />,
}}
/>
<BasicExample />
</KeyboardProvider>
</BottomSheetModalProvider>
</SafeAreaView>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vokhuyet/react-native-messy",
"version": "0.2.5",
"version": "0.2.6",
"description": "chat ui",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
7 changes: 5 additions & 2 deletions src/MessyFooter/MessyFooter.default.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,9 @@ export function MessyFooterDefault(props: TMessyFooterProps) {
Math.abs(height.value),
Math.abs(leftExtraHeight)
);

return {
height: maxHeight,
height: maxHeight - Sizes.padding,
};
}, [Sizes.device_height]);

Expand Down Expand Up @@ -498,7 +499,9 @@ export function MessyFooterDefault(props: TMessyFooterProps) {
}

return (
<View style={{ marginTop: Sizes.padding }}>
<View
style={{ marginTop: Sizes.padding, backgroundColor: Colors.background }}
>
<View>
<View
style={{
Expand Down
6 changes: 3 additions & 3 deletions src/MessyMessage/MessyMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { View } from 'react-native';
import { Pressable } from 'react-native';

import { TMessyMessageProps } from '../types';

Expand All @@ -11,9 +11,9 @@ export function MessyMessage({ renderMessage, ...rest }: TMessyMessageProps) {
return renderMessage(rest);
}
return (
<View>
<Pressable onPress={rest?.listProps?.onPress}>
<MessyMessageDateTime {...rest} />
<MessyMessageContent {...rest} />
</View>
</Pressable>
);
}
4 changes: 3 additions & 1 deletion src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import type { TColor } from './modules';
type TListProps = Omit<
FlatListProps<any>,
'data' | 'renderItem' | 'keyExtractor'
>;
> & {
onPress?: () => void | Promise<void>;
};
type TMessageProps = {
hideOwnerAvatar: boolean;
hidePartnerAvatar: boolean;
Expand Down

0 comments on commit 83d064d

Please sign in to comment.