Skip to content

Commit b1bb503

Browse files
committed
add example project
1 parent 65a2059 commit b1bb503

File tree

84 files changed

+10465
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+10465
-0
lines changed

example/.buckconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
[android]
3+
target = Google Inc.:Google APIs:23
4+
5+
[maven_repositories]
6+
central = https://repo1.maven.org/maven2

example/.eslintrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
root: true,
3+
extends: '@react-native-community',
4+
};

example/.flowconfig

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
[ignore]
2+
; We fork some components by platform
3+
.*/*[.]android.js
4+
5+
; Ignore "BUCK" generated dirs
6+
<PROJECT_ROOT>/\.buckd/
7+
8+
; Ignore polyfills
9+
node_modules/react-native/Libraries/polyfills/.*
10+
11+
; These should not be required directly
12+
; require from fbjs/lib instead: require('fbjs/lib/warning')
13+
node_modules/warning/.*
14+
15+
; Flow doesn't support platforms
16+
.*/Libraries/Utilities/LoadingView.js
17+
18+
[untyped]
19+
.*/node_modules/@react-native-community/cli/.*/.*
20+
21+
[include]
22+
23+
[libs]
24+
node_modules/react-native/interface.js
25+
node_modules/react-native/flow/
26+
27+
[options]
28+
emoji=true
29+
30+
esproposal.optional_chaining=enable
31+
esproposal.nullish_coalescing=enable
32+
33+
module.file_ext=.js
34+
module.file_ext=.json
35+
module.file_ext=.ios.js
36+
37+
munge_underscores=true
38+
39+
module.name_mapper='^react-native/\(.*\)$' -> '<PROJECT_ROOT>/node_modules/react-native/\1'
40+
module.name_mapper='^@?[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '<PROJECT_ROOT>/node_modules/react-native/Libraries/Image/RelativeImageStub'
41+
42+
suppress_type=$FlowIssue
43+
suppress_type=$FlowFixMe
44+
suppress_type=$FlowFixMeProps
45+
suppress_type=$FlowFixMeState
46+
47+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)
48+
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)?:? #[0-9]+
49+
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
50+
51+
[lints]
52+
sketchy-null-number=warn
53+
sketchy-null-mixed=warn
54+
sketchy-number=warn
55+
untyped-type-import=warn
56+
nonstrict-import=warn
57+
deprecated-type=warn
58+
unsafe-getters-setters=warn
59+
inexact-spread=warn
60+
unnecessary-invariant=warn
61+
signature-verification-failure=warn
62+
deprecated-utility=error
63+
64+
[strict]
65+
deprecated-type
66+
nonstrict-import
67+
sketchy-null
68+
unclear-type
69+
unsafe-getters-setters
70+
untyped-import
71+
untyped-type-import
72+
73+
[version]
74+
^0.113.0

example/.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.pbxproj -text

example/.gitignore

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# OSX
2+
#
3+
.DS_Store
4+
5+
# Xcode
6+
#
7+
build/
8+
*.pbxuser
9+
!default.pbxuser
10+
*.mode1v3
11+
!default.mode1v3
12+
*.mode2v3
13+
!default.mode2v3
14+
*.perspectivev3
15+
!default.perspectivev3
16+
xcuserdata
17+
*.xccheckout
18+
*.moved-aside
19+
DerivedData
20+
*.hmap
21+
*.ipa
22+
*.xcuserstate
23+
24+
# Android/IntelliJ
25+
#
26+
build/
27+
.idea
28+
.gradle
29+
local.properties
30+
*.iml
31+
32+
# node.js
33+
#
34+
node_modules/
35+
npm-debug.log
36+
yarn-error.log
37+
38+
# BUCK
39+
buck-out/
40+
\.buckd/
41+
*.keystore
42+
!debug.keystore
43+
44+
# fastlane
45+
#
46+
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
47+
# screenshots whenever they are needed.
48+
# For more information about the recommended setup visit:
49+
# https://docs.fastlane.tools/best-practices/source-control/
50+
51+
*/fastlane/report.xml
52+
*/fastlane/Preview.html
53+
*/fastlane/screenshots
54+
55+
# Bundle artifact
56+
*.jsbundle
57+
58+
# CocoaPods
59+
/ios/Pods/

example/.prettierrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
bracketSpacing: false,
3+
jsxBracketSameLine: true,
4+
singleQuote: true,
5+
trailingComma: 'all',
6+
};

example/.watchmanconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

example/App.js

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
import React, {useEffect, useState} from 'react';
2+
import {
3+
View,
4+
Text,
5+
ToastAndroid,
6+
StyleSheet,
7+
TouchableHighlight,
8+
DeviceEventEmitter,
9+
Image,
10+
} from 'react-native';
11+
import RNBootSplash from 'react-native-bootsplash';
12+
import messaging from '@react-native-firebase/messaging';
13+
import Clipboard from '@react-native-community/clipboard';
14+
import IncomingCall from 'react-native-incoming-call';
15+
16+
export function handleRemoteMessage(remoteMessage) {
17+
if (remoteMessage?.notification?.title === 'Incoming call') {
18+
IncomingCall.display(
19+
'123',
20+
'Quocs',
21+
'https://avatars3.githubusercontent.com/u/16166195',
22+
);
23+
// Could also persist data here for later uses
24+
}
25+
}
26+
27+
const App = () => {
28+
const [deviceToken, setDeviceToken] = useState(null);
29+
const [callPayload, setCallPayload] = useState(null);
30+
31+
useEffect(() => {
32+
RNBootSplash.hide({duration: 250});
33+
34+
// Get the device token
35+
messaging()
36+
.getToken()
37+
.then(token => {
38+
return setDeviceToken(token);
39+
});
40+
41+
// Listen to whether the token changes
42+
return messaging().onTokenRefresh(token => {
43+
setDeviceToken(token);
44+
});
45+
}, []);
46+
47+
useEffect(() => {
48+
const unsubscribe = messaging().onMessage(async remoteMessage => {
49+
handleRemoteMessage(remoteMessage);
50+
});
51+
52+
return unsubscribe;
53+
}, []);
54+
55+
async function handleIncomingCall() {
56+
const launchPayload = await IncomingCall.getLaunchParameters();
57+
console.log('launchParameters', launchPayload);
58+
IncomingCall.clearLaunchParameters();
59+
if (launchPayload) {
60+
// Start call here
61+
setCallPayload(launchPayload);
62+
}
63+
64+
DeviceEventEmitter.addListener('endCall', payload => {
65+
// End call action here
66+
setCallPayload(payload);
67+
});
68+
DeviceEventEmitter.addListener('answerCall', payload => {
69+
// Start call action here
70+
setCallPayload(payload);
71+
});
72+
}
73+
74+
useEffect(() => {
75+
handleIncomingCall();
76+
}, []);
77+
78+
function handleCopyToken() {
79+
Clipboard.setString(deviceToken);
80+
ToastAndroid.show('Device token copied!', 2000);
81+
}
82+
83+
function handleClearPayload() {
84+
setCallPayload(null);
85+
}
86+
87+
return (
88+
<View style={styles.wrapper}>
89+
<Text style={styles.appTitle}>RNCall</Text>
90+
<Text style={styles.appDesc}>example for react-native-incoming-call</Text>
91+
<View style={styles.container}>
92+
{callPayload ? (
93+
<>
94+
<Image
95+
style={styles.image}
96+
source={require('./images/incoming-call.jpg')}
97+
/>
98+
<Text style={styles.header}>Incoming Call Payload</Text>
99+
<Text style={styles.text}>{JSON.stringify(callPayload)}</Text>
100+
<TouchableHighlight
101+
onPress={handleClearPayload}
102+
style={styles.button}
103+
underlayColor="#C0B7FD">
104+
<Text style={styles.btnLabel}>Clear</Text>
105+
</TouchableHighlight>
106+
</>
107+
) : deviceToken ? (
108+
<>
109+
<Image
110+
style={styles.image}
111+
source={require('./images/waiting-call.jpg')}
112+
/>
113+
<Text style={styles.header}>FCM Device Token</Text>
114+
<Text style={styles.text}>{deviceToken}</Text>
115+
<TouchableHighlight
116+
onPress={handleCopyToken}
117+
style={styles.button}
118+
underlayColor="#C0B7FD">
119+
<Text style={styles.btnLabel}>Copy To Clipboard</Text>
120+
</TouchableHighlight>
121+
</>
122+
) : (
123+
<>
124+
<Image
125+
style={styles.image}
126+
source={require('./images/no-device-token.jpg')}
127+
/>
128+
<Text style={styles.text}>No Device Token Found!</Text>
129+
</>
130+
)}
131+
</View>
132+
</View>
133+
);
134+
};
135+
136+
const styles = StyleSheet.create({
137+
wrapper: {
138+
flex: 1,
139+
backgroundColor: '#8271FC',
140+
},
141+
appTitle: {
142+
textAlign: 'center',
143+
marginTop: 40,
144+
fontSize: 24,
145+
color: '#FFFFFF',
146+
fontFamily: 'monospace',
147+
fontWeight: '700',
148+
},
149+
appDesc: {
150+
textAlign: 'center',
151+
marginTop: 20,
152+
fontSize: 10,
153+
marginHorizontal: 20,
154+
color: '#FFFFFF',
155+
fontFamily: 'monospace',
156+
textTransform: 'uppercase',
157+
letterSpacing: 2,
158+
},
159+
container: {
160+
marginTop: 40,
161+
paddingTop: 20,
162+
paddingHorizontal: 20,
163+
paddingBottom: 50,
164+
marginHorizontal: 20,
165+
borderRadius: 10,
166+
backgroundColor: '#FFFFFF',
167+
elevation: 5,
168+
},
169+
header: {
170+
fontSize: 20,
171+
color: '#21346E',
172+
marginBottom: 10,
173+
fontFamily: 'monospace',
174+
fontWeight: '700',
175+
},
176+
text: {
177+
fontSize: 14,
178+
color: '#7984A7',
179+
fontFamily: 'monospace',
180+
},
181+
button: {
182+
position: 'absolute',
183+
height: 50,
184+
borderRadius: 10,
185+
paddingHorizontal: 20,
186+
bottom: -25,
187+
backgroundColor: '#FDDA97',
188+
justifyContent: 'center',
189+
alignItems: 'center',
190+
alignSelf: 'center',
191+
elevation: 5,
192+
},
193+
btnLabel: {
194+
fontSize: 14,
195+
color: '#21346E',
196+
fontFamily: 'monospace',
197+
fontWeight: '700',
198+
},
199+
image: {
200+
alignSelf: 'center',
201+
width: 300,
202+
height: 300,
203+
},
204+
});
205+
206+
export default App;

example/__tests__/App-test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @format
3+
*/
4+
5+
import 'react-native';
6+
import React from 'react';
7+
import App from '../App';
8+
9+
// Note: test renderer must be required after react-native.
10+
import renderer from 'react-test-renderer';
11+
12+
it('renders correctly', () => {
13+
renderer.create(<App />);
14+
});

0 commit comments

Comments
 (0)