-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebViewer.tsx
More file actions
70 lines (62 loc) · 2.11 KB
/
WebViewer.tsx
File metadata and controls
70 lines (62 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import React, { useState } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { WebView, WebViewNavigation } from 'react-native-webview';
export interface WebViewerProps {
url: string;
onSuccess: () => void;
onFail: () => void;
}
export enum VerificationStatus {
PENDING = "PENDING",
PASS = "PASS",
FAIL = "FAIL"
}
const styles = StyleSheet.create({
webview: {
flex: 1
}
});
export const WebViewer: React.FC<WebViewerProps> = ({ url, onSuccess, onFail }) => {
const [currentUrl, setCurrentUrl] = useState<string | null>(null);
if (!url || !onSuccess || !onFail) {
console.log('Make sure url, onSuccess, onError have been set when using WebViewer.')
}
// The Incode ID URL within the Web View will change as you progress through screens.
// The URL for a passing verification includes "success". URL for failed verification includes "fail" or "error".
const onNavigationChange = (navState: WebViewNavigation) => {
const sourceUrl: string = navState?.url;
if (sourceUrl) {
if (sourceUrl.includes("success")) {
setTimeout(() => {
onSuccess();
}, 3000);
} else if (sourceUrl.includes("fail")) {
setTimeout(() => {
onFail();
}, 3000);
} else if (sourceUrl.includes("error")) {
setTimeout(() => {
onFail();
}, 3000);
}
setCurrentUrl(sourceUrl);
}
};
return (
<WebView
style={styles.webview}
useWebKit
originWhitelist={['*']}
allowsInlineMediaPlayback
bounces={true}
mediaPlaybackRequiresUserAction={false}
mediaCapturePermissionGrantType="grantIfSameHostElsePrompt"
source={{ uri: url }}
startInLoadingState
scalesPageToFit
javaScriptEnabledAndroid={true}
javaScriptEnabled={true}
onNavigationStateChange={onNavigationChange}
/>
)
};