Skip to content

Commit 0aa38d1

Browse files
authored
Merge pull request #58 from sendbird/fix/new-message-update
[UIKIT-2874] Fix/new message button is disappeared when loading prev messages
2 parents ff9f2e5 + 6508144 commit 0aa38d1

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

packages/uikit-chat-hooks/src/channel/useGroupChannelMessages/reducer.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ const defaultReducer = ({ ...draft }: State, action: Action) => {
5757
.forEach((m) => delete draft[key][m.reqId]);
5858
}
5959

60-
if (action.type === 'update_messages') {
61-
draft['nextMessageMap'] = {};
62-
}
63-
6460
return draft;
6561
}
6662
case 'delete_messages':

packages/uikit-react-native/src/hooks/useKeyboardStatus.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ const useKeyboardStatus = () => {
3939
setKeyboardStatus({ visible: true, height, bottomSpace });
4040
}),
4141

42-
Keyboard.addListener(hideEvent, (event) => {
42+
Keyboard.addListener(hideEvent, () => {
4343
const height = 0;
4444
const bottomSpace = Platform.select({ default: height });
45-
const nextLayoutAnimation = Platform.select({ ios: configureNextLayoutAnimation, default: NOOP });
45+
// const nextLayoutAnimation = Platform.select({ ios: configureNextLayoutAnimation, default: NOOP });
4646

47-
nextLayoutAnimation(event);
47+
// nextLayoutAnimation(event);
4848
setKeyboardStatus({ visible: false, height, bottomSpace });
4949
}),
5050
];

packages/uikit-utils/src/hooks/index.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import type { DependencyList } from 'react';
3-
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
3+
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
4+
import { EdgeInsets, useSafeAreaInsets } from 'react-native-safe-area-context';
45

56
type Destructor = () => void;
67
type AsyncEffectCallback = () => void | Destructor | Promise<void> | Promise<Destructor>;
@@ -72,3 +73,31 @@ export const useFreshCallback = <T extends (...args: any[]) => any>(callback: T)
7273
ref.current = callback;
7374
return useCallback(((...args) => ref.current(...args)) as T, []);
7475
};
76+
77+
type EdgePaddingMap = {
78+
left: 'paddingLeft';
79+
right: 'paddingRight';
80+
top: 'paddingTop';
81+
bottom: 'paddingBottom';
82+
};
83+
const edgePaddingMap: EdgePaddingMap = {
84+
left: 'paddingLeft',
85+
right: 'paddingRight',
86+
top: 'paddingTop',
87+
bottom: 'paddingBottom',
88+
};
89+
export const useSafeAreaPadding = <
90+
T extends keyof EdgeInsets,
91+
Result extends { [key in EdgePaddingMap[T]]: EdgeInsets[T] },
92+
>(
93+
edges: T[],
94+
): Result => {
95+
const safeAreaInsets = useSafeAreaInsets();
96+
return useMemo(() => {
97+
return edges.reduce((map, edge) => {
98+
const paddingKey = edgePaddingMap[edge];
99+
map[paddingKey] = safeAreaInsets[edge];
100+
return map;
101+
}, {} as { [key in EdgePaddingMap[T]]: EdgeInsets[T] });
102+
}, edges) as Result;
103+
};

0 commit comments

Comments
 (0)