Skip to content
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

Add an ability to have custom preview #103

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions example/src/screens/Playground/Playground.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
import React, { memo, useMemo } from 'react';
import { View } from 'react-native';
import { Alert, Text, View } from 'react-native';

import { HoldItem } from 'react-native-hold-menu';

import styles from './styles';
import { useAppContext } from '../../hooks/useAppContext';
import StyleGuide from '../../utilities/styleGuide';
import { Pressable } from 'react-native';

interface PlaygroundProps {}

const PreviewComp = () => {
return (
<Pressable
onPress={() => {
Alert.alert('sss');
}}
style={{
width: '100%',
height: '100%',
minWidth: 200,
minHeight: 200,
backgroundColor: 'green',
borderRadius: 16,
}}
>
<Text>Presss</Text>
</Pressable>
);
};

const Playground = ({}: PlaygroundProps) => {
const { theme } = useAppContext();

Expand Down Expand Up @@ -88,12 +109,12 @@ const Playground = ({}: PlaygroundProps) => {
<View style={themeStyles.containerStyles}>
<View style={[styles.column, styles.content]}>
<View style={[styles.row]}>
<HoldItem items={items} menuAnchorPosition="bottom-left">
<HoldItem items={items} previewComponent={PreviewComp} bottom={true}>
<View style={themeStyles.item}>
<View style={[themeStyles.dot, styles.bottomLeft]} />
<View style={[themeStyles.dot, styles.topLeft]} />
</View>
</HoldItem>
<HoldItem items={items}>
<HoldItem items={items} bottom={true}>
<View style={themeStyles.item}>
<View style={[themeStyles.dot, styles.topCenter]} />
</View>
Expand All @@ -105,7 +126,7 @@ const Playground = ({}: PlaygroundProps) => {
</HoldItem>
</View>
<View style={[styles.row]}>
<HoldItem items={items}>
<HoldItem items={items} previewComponent={PreviewComp}>
<View style={themeStyles.item}>
<View style={[themeStyles.dot, styles.topLeft]} />
</View>
Expand All @@ -123,7 +144,11 @@ const Playground = ({}: PlaygroundProps) => {
</View>
</View>
<View style={[themeStyles.footer, styles.row]}>
<HoldItem menuAnchorPosition="bottom-left" items={items}>
<HoldItem
menuAnchorPosition="bottom-left"
items={items}
previewComponent={PreviewComp}
>
<View style={themeStyles.item}>
<View style={[themeStyles.dot, styles.bottomLeft]} />
</View>
Expand Down
51 changes: 47 additions & 4 deletions example/src/screens/Whatsapp/MessageItem.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,57 @@
import React, { memo, useMemo } from 'react';
import { View, Text, StyleSheet } from 'react-native';
import { View, Text, StyleSheet, Alert, TouchableOpacity } from 'react-native';

import StyleGuide from '../../utilities/styleGuide';

import { MessageStyles } from './variables';
import {
MessageStyles,
ReactionContainerStyles,
ReactionStyles,
} from './variables';
import { useAppContext } from '../../hooks/useAppContext';

// React Native Hold Menu Components
import { HoldItem } from 'react-native-hold-menu';
import { HoldItem, PreviewComponentProps } from 'react-native-hold-menu';
import { IS_IOS } from '../../constants';

const MessagePreview = ({ children, close }: PreviewComponentProps) => {
const { theme } = useAppContext();

const triggerReaction = () => {
Alert.alert('Reaction pressed');
close();
};

return (
<>
<View style={ReactionContainerStyles(theme)}>
<TouchableOpacity
style={ReactionStyles(theme)}
onPress={triggerReaction}
/>
<TouchableOpacity
style={ReactionStyles(theme)}
onPress={triggerReaction}
/>
<TouchableOpacity
style={ReactionStyles(theme)}
onPress={triggerReaction}
/>
<TouchableOpacity
style={ReactionStyles(theme)}
onPress={triggerReaction}
/>
<TouchableOpacity
style={ReactionStyles(theme)}
onPress={triggerReaction}
/>
</View>

{children}
</>
);
};

const MessageItemComp = ({
senderMenu,
receiverMenu,
Expand Down Expand Up @@ -57,6 +99,8 @@ const MessageItemComp = ({
maxWidth: '80%',
}}
closeOnTap
previewComponent={MessagePreview}
anchorEdge="bottom"
>
<View
style={[
Expand All @@ -78,7 +122,6 @@ export default MessageItem;

const styles = StyleSheet.create({
messageContainer: {
position: 'relative',
width: '100%',
display: 'flex',
flexDirection: 'column',
Expand Down
21 changes: 21 additions & 0 deletions example/src/screens/Whatsapp/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,24 @@ export const MessageStyles = (fromMe: boolean, theme: 'light' | 'dark') => {
StyleGuide.palette.whatsapp[theme].messageBackgroundReceiver,
};
};

export const ReactionContainerStyles = (theme: 'light' | 'dark') => {
return {
borderRadius: StyleGuide.spacing,
backgroundColor:
StyleGuide.palette.whatsapp[theme].reactionContainerBackground,
marginBottom: StyleGuide.spacing,
flexGrow: 0,
flexDirection: 'row',
} as const;
};

export const ReactionStyles = (theme: 'light' | 'dark') => {
return {
borderRadius: StyleGuide.spacing * 2,
backgroundColor: StyleGuide.palette.whatsapp[theme].reactionBackground,
width: 30,
height: 30,
margin: StyleGuide.spacing,
};
};
4 changes: 4 additions & 0 deletions example/src/utilities/styleGuide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ const StyleGuide = {
messageBackgroundSender: 'rgb(218, 248, 201)',
messageBackgroundReceiver: '#FFF',
messageText: '#474747',
reactionContainerBackground: '#FFF',
reactionBackground: '#474747',
},
dark: {
chatBackground: '#131415',
messageBackgroundSender: '#075E54',
messageBackgroundReceiver: '#2b2d2e',
messageText: '#FFF',
reactionContainerBackground: '#2b2d2e',
reactionBackground: '#FFF',
},
},
telegram: {
Expand Down
Loading