1-
2- import React , { useEffect , useRef , useState } from 'react' ;
3- import { ActivityIndicator , PermissionsAndroid , Platform , SafeAreaView , StatusBar , StyleSheet , View } from 'react-native' ;
4- import { CometChat } from "@cometchat/chat-sdk-react-native" ;
5- import { AppConstants } from './AppConstants' ;
6- import { CometChatContextProvider , CometChatLocalize } from '@cometchat/chat-uikit-react-native' ;
7- import { CometChatTheme } from '@cometchat/chat-uikit-react-native' ;
8- import { CometChatUIKit } from '@cometchat/chat-uikit-react-native' ;
1+ import React , { useEffect , useRef , useState } from 'react' ;
2+ import {
3+ ActivityIndicator ,
4+ PermissionsAndroid ,
5+ Platform ,
6+ StatusBar ,
7+ StyleSheet ,
8+ View ,
9+ } from 'react-native' ;
10+ import { CometChat } from '@cometchat/chat-sdk-react-native' ;
11+ import { AppConstants } from './AppConstants' ;
12+ import {
13+ CometChatContextProvider ,
14+ CometChatLocalize ,
15+ } from '@cometchat/chat-uikit-react-native' ;
16+ import { CometChatTheme } from '@cometchat/chat-uikit-react-native' ;
17+ import { CometChatUIKit } from '@cometchat/chat-uikit-react-native' ;
918import StackNavigator from './src/StackNavigator' ;
10- import { UserContextProvider } from './UserContext' ;
11- import { CometChatIncomingCall } from '@cometchat/chat-uikit-react-native' ;
12- import { CometChatUIEventHandler } from '@cometchat/chat-uikit-react-native' ;
13- import { metaInfo } from './src/metaInfo' ;
14- var listnerID = "UNIQUE_LISTENER_ID" ;
19+ import { UserContextProvider } from './UserContext' ;
20+ import { CometChatIncomingCall } from '@cometchat/chat-uikit-react-native' ;
21+ import { CometChatUIEventHandler } from '@cometchat/chat-uikit-react-native' ;
22+ import { metaInfo } from './src/metaInfo' ;
23+ import { SafeAreaView } from 'react-native-safe-area-context' ;
24+ const listenerID = 'UNIQUE_LISTENER_ID' ;
1525
1626const App = ( ) => {
17-
1827 const getPermissions = ( ) => {
19- if ( Platform . OS == " android" ) {
28+ if ( Platform . OS === ' android' ) {
2029 PermissionsAndroid . requestMultiple ( [
2130 PermissionsAndroid . PERMISSIONS . WRITE_EXTERNAL_STORAGE ,
2231 PermissionsAndroid . PERMISSIONS . READ_EXTERNAL_STORAGE ,
@@ -25,11 +34,11 @@ const App = () => {
2534 PermissionsAndroid . PERMISSIONS . POST_NOTIFICATIONS ,
2635 ] ) ;
2736 }
28- }
37+ } ;
2938
3039 const [ callReceived , setCallReceived ] = useState ( false ) ;
3140 const [ isInitialized , setIsInitialized ] = useState ( false ) ;
32- const incomingCall = useRef ( null ) ;
41+ const incomingCall = useRef < CometChat . Call | null > ( null ) ;
3342
3443 useEffect ( ( ) => {
3544 getPermissions ( ) ;
@@ -39,8 +48,10 @@ const App = () => {
3948 region : AppConstants . REGION ,
4049 } )
4150 . then ( ( ) => {
42- CometChatLocalize . setLocale ( "en" ) ;
43- try { CometChat . setDemoMetaInfo ( metaInfo ) } catch ( err ) { }
51+ CometChatLocalize . setLocale ( 'en' ) ;
52+ try {
53+ CometChat . setDemoMetaInfo ( metaInfo ) ;
54+ } catch ( err ) { }
4455 if ( CometChat . setSource ) {
4556 CometChat . setSource ( 'ui-kit' , Platform . OS , 'react-native' ) ;
4657 }
@@ -51,58 +62,57 @@ const App = () => {
5162 } ) ;
5263
5364 CometChat . addCallListener (
54- listnerID ,
65+ listenerID ,
5566 new CometChat . CallListener ( {
56- onIncomingCallReceived : ( call ) => {
67+ onIncomingCallReceived : ( call : CometChat . Call ) => {
5768 incomingCall . current = call ;
5869 setCallReceived ( true ) ;
5970 } ,
60- onOutgoingCallRejected : ( call ) => {
71+ onOutgoingCallAccepted : ( call : CometChat . Call ) => {
6172 incomingCall . current = null ;
6273 setCallReceived ( false ) ;
6374 } ,
64- onIncomingCallCancelled : ( call ) => {
75+ onIncomingCallCancelled : ( call : CometChat . Call ) => {
6576 incomingCall . current = null ;
6677 setCallReceived ( false ) ;
6778 }
68- } )
79+ } ) ,
6980 ) ;
7081
71- CometChatUIEventHandler . addCallListener ( listnerID , {
82+ CometChatUIEventHandler . addCallListener ( listenerID , {
7283 ccCallEnded : ( ) => {
7384 incomingCall . current = null ;
7485 setCallReceived ( false ) ;
7586 } ,
7687 } ) ;
7788
7889 return ( ) => {
79- CometChatUIEventHandler . removeCallListener ( listnerID ) ;
80- CometChat . removeCallListener ( listnerID )
81- }
82-
90+ CometChatUIEventHandler . removeCallListener ( listenerID ) ;
91+ CometChat . removeCallListener ( listenerID ) ;
92+ } ;
8393 } , [ ] ) ;
8494
8595 return (
86- < View style = { styles . container } >
96+ < SafeAreaView style = { styles . container } >
8797 { isInitialized ? (
88- < SafeAreaView style = { { flex : 1 } } >
89- < StatusBar backgroundColor = { " white" } barStyle = { " dark-content" } />
98+ < >
99+ < StatusBar backgroundColor = { ' white' } barStyle = { ' dark-content' } />
90100 { callReceived && (
91101 < CometChatIncomingCall
92102 call = { incomingCall . current }
93- onDecline = { ( call ) => {
103+ onDecline = { call => {
94104 setCallReceived ( false ) ;
95105 } }
96- onError = { ( error ) => {
106+ onError = { error => {
97107 setCallReceived ( false ) ;
98108 } }
99109 incomingCallStyle = { {
100- backgroundColor : " white" ,
101- titleColor : " black" ,
102- subtitleColor : " gray" ,
110+ backgroundColor : ' white' ,
111+ titleColor : ' black' ,
112+ subtitleColor : ' gray' ,
103113 titleFont : {
104114 fontSize : 20 ,
105- fontWeight : " bold" ,
115+ fontWeight : ' bold' ,
106116 } ,
107117 } }
108118 />
@@ -112,21 +122,26 @@ const App = () => {
112122 < StackNavigator />
113123 </ CometChatContextProvider >
114124 </ UserContextProvider >
115- </ SafeAreaView >
125+ </ >
116126 ) : (
117- < View style = { [ styles . container , { justifyContent : "center" } ] } >
127+ < View style = { styles . loading } >
118128 < ActivityIndicator />
119129 </ View >
120130 ) }
121- </ View >
131+ </ SafeAreaView >
122132 ) ;
123133} ;
124134
125135const styles = StyleSheet . create ( {
126136 container : {
127137 flex : 1 ,
128- backgroundColor : "#fff"
129- }
130- } )
138+ backgroundColor : '#fff' ,
139+ } ,
140+ loading : {
141+ flex : 1 ,
142+ justifyContent : 'center' ,
143+ alignItems : 'center' ,
144+ } ,
145+ } ) ;
131146
132147export default App ;
0 commit comments