Skip to content

Commit

Permalink
feat: update chat fragment component
Browse files Browse the repository at this point in the history
  • Loading branch information
AsteriskZuo committed Sep 12, 2023
1 parent 025de77 commit 0c26f52
Show file tree
Hide file tree
Showing 9 changed files with 2,550 additions and 2,277 deletions.
10 changes: 3 additions & 7 deletions packages/react-native-chat-uikit/src/contexts/DialogContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,9 @@ const DialogContextView = (props: DialogContextViewProps) => {
const update = useForceUpdate();

React.useEffect(() => {
const sub = DeviceEventEmitter.addListener(
'uikit_modal_update',
(event) => {
console.log('test:zuoyu:1', event);
update();
}
);
const sub = DeviceEventEmitter.addListener('uikit_modal_update', () => {
update();
});
return () => {
sub.remove();
};
Expand Down
57 changes: 57 additions & 0 deletions packages/react-native-chat-uikit/src/contexts/ImSdkChatContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React from 'react';
import type { ChatMessageChatType } from 'react-native-chat-sdk';

import type { ChatSdkChatContextType } from './types';

export class UIKitChatSdkChatContext implements ChatSdkChatContextType {
chatId: string;
chatType: ChatMessageChatType;
setChat: (params: { chatId: string; chatType: ChatMessageChatType }) => void;
getChat: () => { chatId: string; chatType: ChatMessageChatType };
constructor(params: { chatId: string; chatType: ChatMessageChatType }) {
this.chatId = params.chatId;
this.chatType = params.chatType;
this.setChat = (params: {
chatId: string;
chatType: ChatMessageChatType;
}) => {
this.chatId = params.chatId;
this.chatType = params.chatType;
};
this.getChat = () => {
return {
chatId: this.chatId,
chatType: this.chatType,
};
};
}
}

type ImSdkChatContextProps = React.PropsWithChildren<{
chat: ChatSdkChatContextType;
}>;

const ChatSdkChatContext = React.createContext<
ChatSdkChatContextType | undefined
>(undefined);
ChatSdkChatContext.displayName = 'UIKitChatSdkChatContext';

export function ChatSdkChatContextProvider({
chat,
children,
}: ImSdkChatContextProps) {
return (
<ChatSdkChatContext.Provider value={chat}>
{children}
</ChatSdkChatContext.Provider>
);
}

/**
* Components packaged by chat sdk. Typical application scenarios: Encapsulate methods such as login and logout to facilitate the use of UI components.
*/
export function useChatSdkChatContext(): ChatSdkChatContextType {
const chat = React.useContext(ChatSdkChatContext);
if (!chat) throw Error(`${ChatSdkChatContext.displayName} is not provided`);
return chat;
}
5 changes: 5 additions & 0 deletions packages/react-native-chat-uikit/src/contexts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export {
} from './DialogContext';
export { HeaderStyleProvider, useHeaderContext } from './HeaderContext';
export { I18nContextProvider, useI18nContext } from './I18nContext';
export {
ChatSdkChatContextProvider,
UIKitChatSdkChatContext,
useChatSdkChatContext,
} from './ImSdkChatContext';
export {
ChatSdkContextProvider,
UIKitChatSdkContext,
Expand Down
7 changes: 6 additions & 1 deletion packages/react-native-chat-uikit/src/contexts/types.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ChatClient } from 'react-native-chat-sdk';
import type { ChatClient, ChatMessageChatType } from 'react-native-chat-sdk';

import type {
ButtonStateColor,
Expand Down Expand Up @@ -63,6 +63,11 @@ export interface ChatSdkContextType {
getCurrentId: () => string;
}

export interface ChatSdkChatContextType {
setChat: (params: { chatId: string; chatType: ChatMessageChatType }) => void;
getChat: () => { chatId: string; chatType: ChatMessageChatType };
}

export type HeaderContextType = {
defaultHeight: number;
defaultStatusBarTranslucent: boolean;
Expand Down
Loading

0 comments on commit 0c26f52

Please sign in to comment.