-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update chat fragment component
- Loading branch information
1 parent
025de77
commit 0c26f52
Showing
9 changed files
with
2,550 additions
and
2,277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
packages/react-native-chat-uikit/src/contexts/ImSdkChatContext.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.