Skip to content

Commit 9a925a0

Browse files
authored
Merge pull request #45 from sendbird/fix/auto-resend-ios
[UIKIT-2363] v2/hotfix/auto resend ios
2 parents 955f7ad + decad8c commit 9a925a0

File tree

5 files changed

+107
-10
lines changed

5 files changed

+107
-10
lines changed

packages/uikit-react-native-foundation/src/ui/Toast/index.tsx

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import React, { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
2-
import { Animated } from 'react-native';
1+
import React, { createContext, useContext, useEffect, useMemo, useRef, useState } from 'react';
2+
import { Animated, KeyboardAvoidingView, Platform } from 'react-native';
33
import { useSafeAreaInsets } from 'react-native-safe-area-context';
44

55
import Icon from '../../components/Icon';
@@ -22,10 +22,10 @@ type Props = React.PropsWithChildren<{
2222

2323
const useOpacity = () => {
2424
const opacity = useRef(new Animated.Value(0)).current;
25-
const transition = useCallback(
26-
(value: number) => Animated.timing(opacity, { toValue: value, duration: 500, useNativeDriver: true }).start(),
27-
[],
28-
);
25+
const transition = (value: number) => {
26+
Animated.timing(opacity, { toValue: value, duration: 500, useNativeDriver: true }).start();
27+
};
28+
2929
return {
3030
opacity,
3131
show: () => transition(1),
@@ -87,9 +87,15 @@ export const ToastProvider = ({
8787
return (
8888
<ToastContext.Provider value={{ show: (text, type = 'normal') => text && setState({ text, type, visible: true }) }}>
8989
{children}
90-
<Toast type={state.type} visible={state.visible} bottom={bottom + styles.toastPosition.bottom}>
91-
{state.text}
92-
</Toast>
90+
<KeyboardAvoidingView
91+
behavior={Platform.OS === 'ios' ? 'position' : undefined}
92+
keyboardVerticalOffset={-bottom}
93+
pointerEvents={'none'}
94+
>
95+
<Toast type={state.type} visible={state.visible} bottom={bottom + styles.toastPosition.bottom}>
96+
{state.text}
97+
</Toast>
98+
</KeyboardAvoidingView>
9399
</ToastContext.Provider>
94100
);
95101
};

packages/uikit-react-native/src/contexts/SendbirdChat.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export const SendbirdChatProvider = ({
9696
const listener = (status: AppStateStatus) => {
9797
// 'active' | 'background' | 'inactive' | 'unknown' | 'extension';
9898
if (status === 'active') sdkInstance.connectionState === 'CLOSED' && sdkInstance.setForegroundState();
99-
else sdkInstance.connectionState === 'OPEN' && sdkInstance.setBackgroundState();
99+
else if (status === 'background') sdkInstance.connectionState === 'OPEN' && sdkInstance.setBackgroundState();
100100
};
101101

102102
const subscriber = AppState.addEventListener('change', listener);

sample/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { AppRegistry, LogBox } from 'react-native';
33
import { withTouchReload } from 'react-native-touch-reload';
4+
// import Sendbird from 'sendbird';
45

56
import { Logger } from '@sendbird/uikit-utils';
67

sample/src/App.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
SetSendbirdSDK,
1919
} from './factory';
2020
import useAppearance from './hooks/useAppearance';
21+
// import createLogView from './libs/logView';
2122
import { Routes, navigationRef } from './libs/navigation';
2223
import { onForegroundAndroid, onForegroundIOS } from './libs/notification';
2324
import {
@@ -68,6 +69,8 @@ const App = () => {
6869
);
6970
};
7071

72+
// const LogView = createLogView();
73+
7174
const Navigations = () => {
7275
const { sdk, currentUser } = useSendbirdChat();
7376
const { scheme } = useAppearance();
@@ -89,6 +92,7 @@ const Navigations = () => {
8992

9093
return (
9194
<NavigationContainer ref={navigationRef} theme={isLightTheme ? DefaultTheme : DarkTheme}>
95+
{/*<LogView />*/}
9296
<RootStack.Navigator screenOptions={{ headerShown: false }}>
9397
{!currentUser ? (
9498
<RootStack.Screen name={Routes.SignIn} component={SignInScreen} />

sample/src/libs/logView.tsx

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

0 commit comments

Comments
 (0)