Skip to content

Commit 48f0610

Browse files
committed
chore: update log view
1 parent b2ff2c1 commit 48f0610

File tree

3 files changed

+85
-89
lines changed

3 files changed

+85
-89
lines changed

sample/src/App.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import React, { useEffect } from 'react';
66
import { SendbirdUIKitContainer, useSendbirdChat } from '@sendbird/uikit-react-native';
77
import { DarkUIKitTheme, LightUIKitTheme } from '@sendbird/uikit-react-native-foundation';
88

9+
// import LogView from './components/LogView';
910
import { APP_ID } from './env';
1011
import {
1112
ClipboardService,
@@ -17,7 +18,6 @@ import {
1718
SetSendbirdSDK,
1819
} from './factory';
1920
import useAppearance from './hooks/useAppearance';
20-
// import createLogView from './libs/logView';
2121
import { Routes, navigationRef } from './libs/navigation';
2222
import { onForegroundAndroid, onForegroundIOS } from './libs/notification';
2323
import {
@@ -68,8 +68,6 @@ const App = () => {
6868
);
6969
};
7070

71-
// const LogView = createLogView();
72-
7371
const Navigations = () => {
7472
const { currentUser } = useSendbirdChat();
7573
const { scheme } = useAppearance();

sample/src/components/LogView.tsx

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import format from 'date-fns/format';
2+
import React, { useEffect, useLayoutEffect, useRef, useState } from 'react';
3+
import { Animated, ScrollView, Text, TouchableOpacity, View, useWindowDimensions } from 'react-native';
4+
5+
interface Log {
6+
type: 'log' | 'warn' | 'error' | 'info';
7+
data: string;
8+
timestamp: number;
9+
}
10+
11+
const TypeColor: Record<Log['type'], string> = {
12+
log: '#2d2d2d',
13+
warn: '#ffc443',
14+
error: '#ff4332',
15+
info: '#0773ff',
16+
};
17+
18+
const LogView = () => {
19+
const [logs, setLogs] = useState<Log[]>([]);
20+
const [isCollapsed, setIsCollapsed] = useState(false);
21+
22+
useLayoutEffect(() => {
23+
(['log', 'warn', 'error', 'info'] as const).forEach((type) => {
24+
const origin = console[type];
25+
26+
console[type] = function (...args: unknown[]) {
27+
origin(...args);
28+
setLogs((prev) => [
29+
...prev,
30+
{
31+
type,
32+
data: args.join(','),
33+
timestamp: Date.now(),
34+
},
35+
]);
36+
};
37+
});
38+
}, []);
39+
40+
useEffect(() => {
41+
Animated.timing(animated, { toValue: isCollapsed ? 0 : 1, duration: 250, useNativeDriver: false }).start();
42+
}, [isCollapsed]);
43+
44+
const animated = useRef(new Animated.Value(0)).current;
45+
46+
const { width } = useWindowDimensions();
47+
48+
return (
49+
<Animated.View
50+
style={{
51+
position: 'absolute',
52+
zIndex: 999,
53+
backgroundColor: '#969696',
54+
width: animated.interpolate({ extrapolate: 'clamp', inputRange: [0, 1], outputRange: [70, width] }),
55+
height: animated.interpolate({ extrapolate: 'clamp', inputRange: [0, 1], outputRange: [70, width] }),
56+
bottom: animated.interpolate({ extrapolate: 'clamp', inputRange: [0, 1], outputRange: [150, 0] }),
57+
right: animated.interpolate({ extrapolate: 'clamp', inputRange: [0, 1], outputRange: [15, 0] }),
58+
}}
59+
>
60+
<TouchableOpacity
61+
style={{ paddingHorizontal: 8, paddingVertical: 2, backgroundColor: 'orange', alignItems: 'center' }}
62+
onPress={() => setIsCollapsed((prev) => !prev)}
63+
>
64+
<Text>{isCollapsed ? 'Expand' : 'Collapse'}</Text>
65+
</TouchableOpacity>
66+
<ScrollView>
67+
{logs.map(({ type, data, timestamp }, idx) => {
68+
return (
69+
<View
70+
key={idx}
71+
style={{ marginBottom: 1, backgroundColor: TypeColor[type], paddingHorizontal: 4, paddingVertical: 2 }}
72+
>
73+
<Text style={{ color: 'white' }}>
74+
{format(timestamp, 'p')} / {data}
75+
</Text>
76+
</View>
77+
);
78+
})}
79+
</ScrollView>
80+
</Animated.View>
81+
);
82+
};
83+
84+
export default LogView;

sample/src/libs/logView.tsx

Lines changed: 0 additions & 86 deletions
This file was deleted.

0 commit comments

Comments
 (0)