Skip to content

Commit b1b384b

Browse files
committed
chore: add secret menu to SampleApp
1 parent b2de80c commit b1b384b

File tree

2 files changed

+96
-5
lines changed

2 files changed

+96
-5
lines changed

examples/SampleApp/src/components/MenuDrawer.tsx

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1-
import React from 'react';
2-
import { Image, SafeAreaView, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
1+
import React, { useCallback, useEffect, useState } from 'react';
2+
import {
3+
Image,
4+
SafeAreaView,
5+
StyleSheet,
6+
Text,
7+
TouchableOpacity,
8+
Pressable,
9+
View,
10+
} from 'react-native';
311
import { Edit, Group, User, useTheme } from 'stream-chat-react-native';
412

513
import { useAppContext } from '../context/AppContext';
14+
import { SecretMenu } from './SecretMenu.tsx';
615

716
import type { DrawerContentComponentProps } from '@react-navigation/drawer';
817

9-
const styles = StyleSheet.create({
18+
export const styles = StyleSheet.create({
1019
avatar: {
1120
borderRadius: 20,
1221
height: 40,
@@ -44,12 +53,26 @@ const styles = StyleSheet.create({
4453
});
4554

4655
export const MenuDrawer = ({ navigation }: DrawerContentComponentProps) => {
56+
const [secretMenuPressCounter, setSecretMenuPressCounter] = useState(0);
57+
const [secretMenuVisible, setSecretMenuVisible] = useState(false);
58+
4759
const {
4860
theme: {
4961
colors: { black, grey, white },
5062
},
5163
} = useTheme();
5264

65+
useEffect(() => {
66+
if (!secretMenuVisible && secretMenuPressCounter >= 7) {
67+
setSecretMenuVisible(true);
68+
}
69+
}, [secretMenuVisible, secretMenuPressCounter]);
70+
71+
const closeSecretMenu = useCallback(() => {
72+
setSecretMenuPressCounter(0);
73+
setSecretMenuVisible(false);
74+
}, []);
75+
5376
const { chatClient, logout } = useAppContext();
5477

5578
if (!chatClient) {
@@ -59,7 +82,7 @@ export const MenuDrawer = ({ navigation }: DrawerContentComponentProps) => {
5982
return (
6083
<View style={[styles.container, { backgroundColor: white }]}>
6184
<SafeAreaView style={{ flex: 1 }}>
62-
<View style={[styles.userRow]}>
85+
<Pressable onPress={() => setSecretMenuPressCounter(c => c + 1)} style={[styles.userRow]}>
6386
<Image
6487
source={{
6588
uri: chatClient.user?.image,
@@ -76,9 +99,10 @@ export const MenuDrawer = ({ navigation }: DrawerContentComponentProps) => {
7699
>
77100
{chatClient.user?.name}
78101
</Text>
79-
</View>
102+
</Pressable>
80103
<View style={styles.menuContainer}>
81104
<View>
105+
<SecretMenu visible={secretMenuVisible} close={closeSecretMenu} />
82106
<TouchableOpacity
83107
onPress={() => navigation.navigate('NewDirectMessagingScreen')}
84108
style={styles.menuItem}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import React from 'react';
2+
import Animated, { useAnimatedStyle, useSharedValue, withSpring, withTiming } from 'react-native-reanimated';
3+
import { LayoutChangeEvent, Text, TouchableOpacity, View } from 'react-native';
4+
import { Close, Notification, useTheme } from 'stream-chat-react-native';
5+
import { styles as menuDrawerStyles } from './MenuDrawer.tsx';
6+
7+
export const SlideInView = ({ visible, children }: { visible: boolean; children: React.ReactNode }) => {
8+
const animatedHeight = useSharedValue(0);
9+
10+
const onLayout = (event: LayoutChangeEvent) => {
11+
const { height } = event.nativeEvent.layout;
12+
animatedHeight.value = height;
13+
};
14+
15+
const animatedStyle = useAnimatedStyle(() => ({
16+
height: withSpring(visible ? animatedHeight.value : 0, { damping: 10 }),
17+
opacity: withTiming(visible ? 1 : 0, { duration: 500 }),
18+
}), [visible]);
19+
20+
return (
21+
<Animated.View style={animatedStyle}>
22+
{visible ? <View onLayout={onLayout} style={{ position: 'absolute', width: '100%' }}>
23+
{children}
24+
</View> : null}
25+
</Animated.View>
26+
);
27+
};
28+
29+
export const SecretMenu = ({ close, visible }: { close: () => void, visible: boolean }) => {
30+
const {
31+
theme: {
32+
colors: { black, grey },
33+
},
34+
} = useTheme();
35+
36+
return <SlideInView visible={visible} >
37+
<TouchableOpacity style={menuDrawerStyles.menuItem}>
38+
<Notification height={24} pathFill={grey} width={24} />
39+
<Text
40+
style={[
41+
menuDrawerStyles.menuTitle,
42+
{
43+
color: black,
44+
},
45+
]}
46+
>
47+
BRUH
48+
</Text>
49+
</TouchableOpacity>
50+
<TouchableOpacity onPress={close} style={menuDrawerStyles.menuItem}>
51+
<Close height={24} pathFill={grey} width={24} />
52+
<Text
53+
style={[
54+
menuDrawerStyles.menuTitle,
55+
{
56+
color: black,
57+
},
58+
]}
59+
>
60+
Close
61+
</Text>
62+
</TouchableOpacity>
63+
<View style={menuDrawerStyles.menuItem}>
64+
<View style={{ backgroundColor: grey, height: 1, width: '100%', opacity: 0.2 }}/>
65+
</View>
66+
</SlideInView>;
67+
};

0 commit comments

Comments
 (0)