@@ -15,15 +15,17 @@ import {
1515 UIKitThemeProvider ,
1616} from '@sendbird/uikit-react-native-foundation' ;
1717import { SBUConfig , UIKitConfigProvider } from '@sendbird/uikit-tools' ;
18- import type {
18+ import {
19+ Logger ,
20+ NOOP ,
1921 PartialDeep ,
2022 SendbirdChatSDK ,
2123 SendbirdGroupChannel ,
2224 SendbirdGroupChannelCreateParams ,
2325 SendbirdMember ,
2426 SendbirdUser ,
27+ useIsFirstMount ,
2528} from '@sendbird/uikit-utils' ;
26- import { NOOP , useIsFirstMount } from '@sendbird/uikit-utils' ;
2729
2830import { LocalizationContext , LocalizationProvider } from '../contexts/LocalizationCtx' ;
2931import { PlatformServiceProvider } from '../contexts/PlatformServiceCtx' ;
@@ -50,7 +52,7 @@ import type {
5052 PlayerServiceInterface ,
5153 RecorderServiceInterface ,
5254} from '../platform/types' ;
53- import type { ErrorBoundaryProps , LocalCacheStorage } from '../types' ;
55+ import { ErrorBoundaryProps , LocalCacheStorage } from '../types' ;
5456import VERSION from '../version' ;
5557import InternalErrorBoundaryContainer from './InternalErrorBoundaryContainer' ;
5658
@@ -78,13 +80,13 @@ const chatOmitKeys = [
7880 'appVersion' ,
7981 'localCacheEnabled' ,
8082 'useAsyncStorageStore' ,
83+ 'useMMKVStorageStore' ,
8184] as const ;
8285function sanitizeChatOptions < T extends Record < string , unknown > > ( chatOptions : T ) : T {
8386 const opts = { ...chatOptions } ;
8487 chatOmitKeys . forEach ( ( key ) => delete opts [ key ] ) ;
8588 return opts ;
8689}
87-
8890export type SendbirdUIKitContainerProps = React . PropsWithChildren < {
8991 appId : string ;
9092 platformServices : {
@@ -95,11 +97,11 @@ export type SendbirdUIKitContainerProps = React.PropsWithChildren<{
9597 player : PlayerServiceInterface ;
9698 recorder : RecorderServiceInterface ;
9799 } ;
98- chatOptions : {
99- localCacheStorage : LocalCacheStorage ;
100- onInitialized ?: ( sdkInstance : SendbirdChatSDK ) => SendbirdChatSDK ;
101- } & Partial < ChatOmittedInitParams > &
102- Partial < ChatRelatedFeaturesInUIKit > ;
100+ chatOptions : Partial < ChatOmittedInitParams > &
101+ Partial < ChatRelatedFeaturesInUIKit > & {
102+ onInitialized ?: ( sdkInstance : SendbirdChatSDK ) => SendbirdChatSDK ;
103+ localCacheStorage : LocalCacheStorage ;
104+ } ;
103105 uikitOptions ?: PartialDeep < {
104106 common : SBUConfig [ 'common' ] ;
105107 groupChannel : Omit < SBUConfig [ 'groupChannel' ] [ 'channel' ] , 'enableReactionsSupergroup' > & {
@@ -162,6 +164,10 @@ const SendbirdUIKitContainer = (props: SendbirdUIKitContainerProps) => {
162164
163165 if ( ! chatOptions . localCacheStorage ) {
164166 throw new Error ( 'SendbirdUIKitContainer: chatOptions.localCacheStorage is required' ) ;
167+ } else if ( 'getItem' in chatOptions . localCacheStorage ) {
168+ Logger . warn (
169+ 'SendbirdUIKitContainer: localCacheStorage for `AsyncStorage` is deprecated. Please use `MMKV` instead.' ,
170+ ) ;
165171 }
166172
167173 const defaultStringSet = localization ?. stringSet ?? StringSetEn ;
@@ -171,7 +177,7 @@ const SendbirdUIKitContainer = (props: SendbirdUIKitContainerProps) => {
171177
172178 const [ internalStorage ] = useState ( ( ) => new InternalLocalCacheStorage ( chatOptions . localCacheStorage ) ) ;
173179 const [ sdkInstance , setSdkInstance ] = useState < SendbirdChatSDK > ( ( ) => {
174- const sendbird = initializeSendbird ( appId , { internalStorage , ... sanitizeChatOptions ( chatOptions ) } ) ;
180+ const sendbird = initializeSendbird ( appId , sanitizeChatOptions ( chatOptions ) ) ;
175181 unsubscribes . current = sendbird . unsubscribes ;
176182 return sendbird . chatSDK ;
177183 } ) ;
@@ -183,7 +189,7 @@ const SendbirdUIKitContainer = (props: SendbirdUIKitContainerProps) => {
183189
184190 useLayoutEffect ( ( ) => {
185191 if ( ! isFirstMount ) {
186- const sendbird = initializeSendbird ( appId , { internalStorage , ... sanitizeChatOptions ( chatOptions ) } ) ;
192+ const sendbird = initializeSendbird ( appId , sanitizeChatOptions ( chatOptions ) ) ;
187193 setSdkInstance ( sendbird . chatSDK ) ;
188194 unsubscribes . current = sendbird . unsubscribes ;
189195 }
@@ -288,21 +294,23 @@ const SendbirdUIKitContainer = (props: SendbirdUIKitContainerProps) => {
288294} ;
289295
290296interface InitOptions extends ChatOmittedInitParams {
291- internalStorage : InternalLocalCacheStorage ;
297+ localCacheStorage : LocalCacheStorage ;
292298 onInitialized ?: ( sdk : SendbirdChatSDK ) => SendbirdChatSDK ;
293299}
294300const initializeSendbird = ( appId : string , options : InitOptions ) => {
295301 let chatSDK : SendbirdChatSDK ;
296302 const unsubscribes : Array < ( ) => void > = [ ] ;
297- const { internalStorage , onInitialized, ...chatInitParams } = options ;
303+ const { localCacheStorage , onInitialized, ...chatInitParams } = options ;
298304
305+ const isMMKVStorage = 'getString' in localCacheStorage ;
299306 chatSDK = SendbirdChat . init ( {
300307 ...chatInitParams ,
301308 appId,
302309 newInstance : true ,
303310 modules : [ new GroupChannelModule ( ) , new OpenChannelModule ( ) ] ,
304311 localCacheEnabled : true ,
305- useAsyncStorageStore : internalStorage as never ,
312+ useMMKVStorageStore : isMMKVStorage ? ( localCacheStorage as never ) : undefined ,
313+ useAsyncStorageStore : ! isMMKVStorage ? ( localCacheStorage as never ) : undefined ,
306314 } ) ;
307315
308316 if ( onInitialized ) {
0 commit comments