Skip to content

Commit

Permalink
Prevent navigation and add webview style.
Browse files Browse the repository at this point in the history
douglasjunior committed Jul 3, 2020
1 parent 1e38ce3 commit 0439cb7
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-recaptcha-that-works",
"version": "0.0.3",
"version": "0.0.4",
"private": false,
"description": "⚛ A reCAPTCHA bridge for React Native that works.",
"repository": {
22 changes: 20 additions & 2 deletions src/Recaptcha.js
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ import getTemplate from './get-template';
const styles = StyleSheet.create({
webView: {
flex: 1,
backgroundColor: 'transparent',
backgroundColor: 'rgba(0, 0, 0, 0.5)',
},
loading: {
position: 'absolute',
@@ -56,6 +56,10 @@ const styles = StyleSheet.create({
});

const originWhitelist = ['*'];
const handleShouldStartLoadWithRequest = () => {
// prevent navigation on iOS
return false;
}

const Recaptcha = forwardRef(
(
@@ -71,6 +75,7 @@ const Recaptcha = forwardRef(
siteKey,
baseUrl,
lang,
style,
},
$ref,
) => {
@@ -166,6 +171,15 @@ const Recaptcha = forwardRef(
[handleClose],
);

const handleNavigationStateChange = useCallback(() => {
// prevent navigation on Android
if (!loading) {
$webView.current.stopLoading();
}
}, [loading]);

const webViewStyles = useMemo(() => [styles.webView, style], [style]);

const renderLoading = () => {
if (!loading && source) {
return null;
@@ -184,8 +198,12 @@ const Recaptcha = forwardRef(
ref={$webView}
originWhitelist={originWhitelist}
source={source}
style={styles.webView}
style={webViewStyles}
onMessage={handleMessage}
allowsBackForwardNavigationGestures={false}
onShouldStartLoadWithRequest={handleShouldStartLoadWithRequest}
onNavigationStateChange={handleNavigationStateChange}
bounces={false}
/>
{renderLoading()}
</Modal>
1 change: 0 additions & 1 deletion src/get-template.js
Original file line number Diff line number Diff line change
@@ -157,7 +157,6 @@ const getTemplate = (params) => {
.container {
display: flex;
background-color: rgba(0, 0, 0, 0.5);
justify-content: center;
align-items: center;
}

0 comments on commit 0439cb7

Please sign in to comment.