react-native-my-survey-sdk 2.0.1 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +4 -15
- package/package.json +7 -3
- package/src/SurveyWebView.js +13 -0
- package/src/useFaqSurvey.js +28 -0
- package/src/useSurveyAlert.js +25 -0
- package/src/useSurveyTimer.js +39 -0
package/index.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const SurveyWebView = ({ url }) => {
|
|
7
|
-
const SURVEY_URL = url
|
|
8
|
-
return (
|
|
9
|
-
<SafeAreaView style={{ flex: 1 }}>
|
|
10
|
-
<WebView source={{ uri: SURVEY_URL }} />
|
|
11
|
-
</SafeAreaView>
|
|
12
|
-
);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export default SurveyWebView;
|
|
1
|
+
export { default as SurveyWebView } from "./src/SurveyWebView";
|
|
2
|
+
export { useFaqSurvey } from "./src/useFaqSurvey";
|
|
3
|
+
export { useSurveyTimer } from "./src/useSurveyTimer";
|
|
4
|
+
export { useSurveyAlert } from "./src/useSurveyAlert";
|
package/package.json
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-my-survey-sdk",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.0.4",
|
|
4
|
+
"description": "Survey SDK for xebo.ai",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
8
|
},
|
|
9
9
|
"author": "sheetal",
|
|
10
10
|
"license": "ISC",
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"react-native-webview": "^13.16.0"
|
|
13
|
+
},
|
|
11
14
|
"peerDependencies": {
|
|
15
|
+
"@react-navigation/native": ">=6.0.0",
|
|
12
16
|
"react": ">=18.2.0 <19.0.0",
|
|
13
|
-
"react-native": ">=0.71.0 <0.
|
|
17
|
+
"react-native": ">=0.71.0 <0.78.0"
|
|
14
18
|
}
|
|
15
19
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View } from "react-native";
|
|
3
|
+
import { WebView } from "react-native-webview";
|
|
4
|
+
|
|
5
|
+
const SurveyWebView = ({ url }) => {
|
|
6
|
+
return (
|
|
7
|
+
<View style={{ flex: 1 }}>
|
|
8
|
+
<WebView source={{ uri: url }} />
|
|
9
|
+
</View>
|
|
10
|
+
);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default SurveyWebView;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { useNavigation } from "@react-navigation/native";
|
|
3
|
+
|
|
4
|
+
export const useFaqSurvey = ({
|
|
5
|
+
faqScreenName,
|
|
6
|
+
surveyScreenName,
|
|
7
|
+
surveyUrl,
|
|
8
|
+
visitLimit,
|
|
9
|
+
}) => {
|
|
10
|
+
const [faqVisitCount, setFaqVisitCount] = useState(0);
|
|
11
|
+
const navigation = useNavigation();
|
|
12
|
+
|
|
13
|
+
const handleFAQPress = () => {
|
|
14
|
+
setFaqVisitCount((prev) => {
|
|
15
|
+
const newCount = prev + 1;
|
|
16
|
+
|
|
17
|
+
if (newCount >= visitLimit) {
|
|
18
|
+
navigation.navigate(surveyScreenName, { url: surveyUrl });
|
|
19
|
+
return 0; // reset after survey
|
|
20
|
+
} else {
|
|
21
|
+
navigation.navigate(faqScreenName);
|
|
22
|
+
return newCount;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return { handleFAQPress, faqVisitCount };
|
|
28
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Alert } from "react-native";
|
|
2
|
+
import { useNavigation } from "@react-navigation/native";
|
|
3
|
+
|
|
4
|
+
export const useSurveyAlert = ({
|
|
5
|
+
surveyScreenName,
|
|
6
|
+
surveyUrl,
|
|
7
|
+
title = "Survey",
|
|
8
|
+
message = "Click OK to proceed to the survey.",
|
|
9
|
+
}) => {
|
|
10
|
+
const navigation = useNavigation();
|
|
11
|
+
|
|
12
|
+
const showSurveyAlert = () => {
|
|
13
|
+
Alert.alert(title, message, [
|
|
14
|
+
{
|
|
15
|
+
text: "OK",
|
|
16
|
+
onPress: () => {
|
|
17
|
+
navigation.navigate(surveyScreenName, { url: surveyUrl });
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
{ text: "Cancel", style: "cancel" },
|
|
21
|
+
]);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
return { showSurveyAlert };
|
|
25
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
import { useNavigation } from "@react-navigation/native";
|
|
3
|
+
|
|
4
|
+
export const useSurveyTimer = ({
|
|
5
|
+
isActive,
|
|
6
|
+
surveyScreenName,
|
|
7
|
+
surveyUrl,
|
|
8
|
+
delay,
|
|
9
|
+
}) => {
|
|
10
|
+
const timerRef = useRef(null);
|
|
11
|
+
const navigation = useNavigation();
|
|
12
|
+
|
|
13
|
+
const navigateToSurvey = () => {
|
|
14
|
+
navigation.navigate(surveyScreenName, { url: surveyUrl });
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (isActive) {
|
|
19
|
+
timerRef.current = setTimeout(() => {
|
|
20
|
+
if (isActive) {
|
|
21
|
+
navigateToSurvey();
|
|
22
|
+
}
|
|
23
|
+
}, delay);
|
|
24
|
+
} else {
|
|
25
|
+
if (timerRef.current) {
|
|
26
|
+
clearTimeout(timerRef.current);
|
|
27
|
+
timerRef.current = null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return () => {
|
|
32
|
+
if (timerRef.current) {
|
|
33
|
+
clearTimeout(timerRef.current);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}, [isActive, delay]);
|
|
37
|
+
|
|
38
|
+
return { navigateToSurvey };
|
|
39
|
+
};
|