Skip to content

Commit 8d4468c

Browse files
authored
Merge pull request #44 from sendbird/v1/fix/auto-resend-ios
[UIKIT-2363] v1/fix/auto resend ios
2 parents 3bfe517 + 0889f81 commit 8d4468c

File tree

7 files changed

+110
-13
lines changed

7 files changed

+110
-13
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 createStyleSheet from '../../styles/createStyleSheet';
@@ -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
@@ -91,7 +91,7 @@ export const SendbirdChatProvider = ({
9191
const listener = (status: AppStateStatus) => {
9292
// 'active' | 'background' | 'inactive' | 'unknown' | 'extension';
9393
if (status === 'active') sdkInstance.getConnectionState() === 'CLOSED' && sdkInstance.setForegroundState();
94-
else sdkInstance.getConnectionState() === 'OPEN' && sdkInstance.setBackgroundState();
94+
else if (status === 'background') sdkInstance.getConnectionState() === 'OPEN' && sdkInstance.setBackgroundState();
9595
};
9696

9797
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/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ SPEC CHECKSUMS:
717717
Flipper-RSocket: d9d9ade67cbecf6ac10730304bf5607266dd2541
718718
FlipperKit: d8d346844eca5d9120c17d441a2f38596e8ed2b9
719719
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
720-
glog: 5337263514dd6f09803962437687240c5dc39aa4
720+
glog: 85ecdd10ee8d8ec362ef519a6a45ff9aa27b2e85
721721
GoogleDataTransport: 5fffe35792f8b96ec8d6775f5eccd83c998d5a3b
722722
GoogleUtilities: e0913149f6b0625b553d70dae12b49fc62914fd1
723723
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
@@ -730,7 +730,7 @@ SPEC CHECKSUMS:
730730
Permission-PhotoLibrary: fda0fda455bebaa2602f3dfdf8296b28247c1484
731731
Permission-PhotoLibraryAddOnly: e5ae346a7ad3effb3f4da07220cf487ff6a2bcba
732732
PromisesObjC: 99b6f43f9e1044bd87a95a60beff28c2c44ddb72
733-
RCT-Folly: a21c126816d8025b547704b777a2ba552f3d9fa9
733+
RCT-Folly: 803a9cfd78114b2ec0f140cfa6fa2a6bafb2d685
734734
RCTRequired: 4bf86c70714490bca4bf2696148638284622644b
735735
RCTTypeSafety: c475a7059eb77935fa53d2c17db299893f057d5d
736736
React: f64af14e3f2c50f6f2c91a5fd250e4ff1b3c3459

sample/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sendbird/sample",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"private": true,
55
"scripts": {
66
"postinstall": "patch-package",

sample/src/App.tsx

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

71+
// const LogView = createLogView();
72+
7073
const Navigations = () => {
7174
const { currentUser } = useSendbirdChat();
7275
const { scheme } = useAppearance();
@@ -82,6 +85,7 @@ const Navigations = () => {
8285

8386
return (
8487
<NavigationContainer ref={navigationRef} theme={isLightTheme ? DefaultTheme : DarkTheme}>
88+
{/*<LogView />*/}
8589
<RootStack.Navigator screenOptions={{ headerShown: false }}>
8690
{!currentUser ? (
8791
<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)