From 99763887b149afe64a0b6af6444482a579c1168f Mon Sep 17 00:00:00 2001 From: BrianRid Date: Mon, 25 Apr 2022 21:39:20 +0200 Subject: [PATCH 1/5] feat: integrating in app review modal for IOS and Android --- tumeplayMobile/App.js | 15 +++++++++++++++ tumeplayMobile/android/app/build.gradle | 5 +++-- .../java/com/tumeplaymobile/MainApplication.java | 4 ++++ tumeplayMobile/android/settings.gradle | 2 ++ tumeplayMobile/ios/Podfile | 2 ++ tumeplayMobile/package-lock.json | 11 +++++++++++ 6 files changed, 37 insertions(+), 2 deletions(-) diff --git a/tumeplayMobile/App.js b/tumeplayMobile/App.js index 0cd6314a..e694eb84 100644 --- a/tumeplayMobile/App.js +++ b/tumeplayMobile/App.js @@ -25,6 +25,7 @@ import Matomo from 'react-native-matomo'; import Loader from './src/components/global/Loader'; import {TourGuideProvider} from 'rn-tourguide'; import VersionCheck from 'react-native-version-check'; +import InAppReview from 'react-native-in-app-review'; import * as Sentry from '@sentry/react-native'; import Copilot from './src/components/Copilot/Copilot'; @@ -63,6 +64,19 @@ const App = () => { } }; + const handleAppReview = () => { + console.log(InAppReview.isAvailable()); + if (InAppReview.isAvailable()) { + InAppReview.RequestInAppReview() + .then(hasFlowFinishedSuccessfully => { + console.log('InAppReview in Android', hasFlowFinishedSuccessfully); + }) + .catch(error => { + console.log('InAppReview error', error); + }); + } + }; + const getMobileUser = async user_id => { const response = await fetch( REACT_APP_URL + '/utilisateurs-mobiles/' + user_id + '?version=2', @@ -130,6 +144,7 @@ const App = () => { useEffect(() => { // clearStorage(); + handleAppReview(); checkUserIdInStorage(); Matomo.initTracker(MATOMO_SITE_URL + 'matomo.php', parseInt(MATOMO_ID)); checkUpdateNeeded(); diff --git a/tumeplayMobile/android/app/build.gradle b/tumeplayMobile/android/app/build.gradle index 53f196d7..933ed664 100644 --- a/tumeplayMobile/android/app/build.gradle +++ b/tumeplayMobile/android/app/build.gradle @@ -226,8 +226,9 @@ dependencies { exclude group: 'com.google.android.gms', module: 'play-services-base' exclude group: 'com.google.android.gms', module: 'play-services-maps' } - implementation 'com.google.android.gms:play-services-base:18.0.1' - implementation 'com.google.android.gms:play-services-maps:17.0.0' + implementation 'com.google.android.gms:play-services-base:18.0.1' + implementation 'com.google.android.gms:play-services-maps:17.0.0' + implementation project(':react-native-in-app-review') } // Run this once to be able to run the application with BUCK diff --git a/tumeplayMobile/android/app/src/main/java/com/tumeplaymobile/MainApplication.java b/tumeplayMobile/android/app/src/main/java/com/tumeplaymobile/MainApplication.java index f5b8142b..9a75987d 100644 --- a/tumeplayMobile/android/app/src/main/java/com/tumeplaymobile/MainApplication.java +++ b/tumeplayMobile/android/app/src/main/java/com/tumeplaymobile/MainApplication.java @@ -4,6 +4,7 @@ import android.content.Context; import com.facebook.react.PackageList; import com.facebook.react.ReactApplication; +import com.ibits.react_native_in_app_review.AppReviewPackage; import io.xogus.reactnative.versioncheck.RNVersionCheckPackage; import com.reactnativecommunity.webview .RNCWebViewPackage; import com.reactnativecommunity.webview.RNCWebViewPackage; @@ -19,6 +20,7 @@ import java.util.List; import de.bonify.reactnativematomo.MatomoPackage; + public class MainApplication extends Application implements ReactApplication { private final ReactNativeHost mReactNativeHost = @@ -31,6 +33,7 @@ public boolean getUseDeveloperSupport() { @Override protected List getPackages() { new MatomoPackage(); + new AppReviewPackage(); @SuppressWarnings("UnnecessaryLocalVariable") List packages = new PackageList(this).getPackages(); // Packages that cannot be autolinked yet can be added manually here, for example: @@ -42,6 +45,7 @@ protected List getPackages() { protected String getJSMainModuleName() { return "index"; } + }; @Override diff --git a/tumeplayMobile/android/settings.gradle b/tumeplayMobile/android/settings.gradle index 95ff5a1a..62e6bff9 100644 --- a/tumeplayMobile/android/settings.gradle +++ b/tumeplayMobile/android/settings.gradle @@ -1,4 +1,6 @@ rootProject.name = 'tumeplay' +include ':react-native-in-app-review' +project(':react-native-in-app-review').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-in-app-review/android') include ':react-native-version-check' project(':react-native-version-check').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-version-check/android') include ':react-native-webview' diff --git a/tumeplayMobile/ios/Podfile b/tumeplayMobile/ios/Podfile index 939833d3..fa8d9d4d 100644 --- a/tumeplayMobile/ios/Podfile +++ b/tumeplayMobile/ios/Podfile @@ -25,6 +25,8 @@ target 'tumeplayMobile' do pod 'react-native-version-check', :path => '../node_modules/react-native-version-check' + pod 'react-native-in-app-review', :path => '../node_modules/react-native-in-app-review' + target 'tumeplayMobileTests' do inherit! :complete # Pods for testing diff --git a/tumeplayMobile/package-lock.json b/tumeplayMobile/package-lock.json index c5b26e76..a0a778c1 100644 --- a/tumeplayMobile/package-lock.json +++ b/tumeplayMobile/package-lock.json @@ -16,6 +16,7 @@ "react": "17.0.2", "react-native": "0.67.2", "react-native-copilot": "^2.5.1", + "react-native-in-app-review": "^4.1.1", "react-native-maps": "^0.30.1", "react-native-permissions": "^3.3.1", "react-native-picker-select": "^8.0.4", @@ -11602,6 +11603,11 @@ "react-native": "*" } }, + "node_modules/react-native-in-app-review": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/react-native-in-app-review/-/react-native-in-app-review-4.1.1.tgz", + "integrity": "sha512-kuZNKvawD9rICR8SEKSMRB1Ws5RjjyQScxVg/57dK8Yrx/CeVqSL5jJUJ1Nhl/MMxwP5XJ/keFcjTb2YRMglQw==" + }, "node_modules/react-native-iphone-x-helper": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/react-native-iphone-x-helper/-/react-native-iphone-x-helper-1.3.1.tgz", @@ -23376,6 +23382,11 @@ "dev": true, "requires": {} }, + "react-native-in-app-review": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/react-native-in-app-review/-/react-native-in-app-review-4.1.1.tgz", + "integrity": "sha512-kuZNKvawD9rICR8SEKSMRB1Ws5RjjyQScxVg/57dK8Yrx/CeVqSL5jJUJ1Nhl/MMxwP5XJ/keFcjTb2YRMglQw==" + }, "react-native-iphone-x-helper": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/react-native-iphone-x-helper/-/react-native-iphone-x-helper-1.3.1.tgz", From 60e3f46c45bebc461a980596251b9c92c81e7c23 Mon Sep 17 00:00:00 2001 From: BrianRid Date: Tue, 26 Apr 2022 11:54:38 +0200 Subject: [PATCH 2/5] feat: adding app review process after order --- tumeplayMobile/App.js | 15 --------------- .../src/components/Orders/OrderConfirm.js | 5 ++++- .../Orders/Pickup/PickupOrderConfirm.js | 5 ++++- tumeplayMobile/src/hooks/useAppReview.js | 19 +++++++++++++++++++ tumeplayMobile/src/views/HomePage.js | 8 +++++++- 5 files changed, 34 insertions(+), 18 deletions(-) create mode 100644 tumeplayMobile/src/hooks/useAppReview.js diff --git a/tumeplayMobile/App.js b/tumeplayMobile/App.js index e694eb84..0cd6314a 100644 --- a/tumeplayMobile/App.js +++ b/tumeplayMobile/App.js @@ -25,7 +25,6 @@ import Matomo from 'react-native-matomo'; import Loader from './src/components/global/Loader'; import {TourGuideProvider} from 'rn-tourguide'; import VersionCheck from 'react-native-version-check'; -import InAppReview from 'react-native-in-app-review'; import * as Sentry from '@sentry/react-native'; import Copilot from './src/components/Copilot/Copilot'; @@ -64,19 +63,6 @@ const App = () => { } }; - const handleAppReview = () => { - console.log(InAppReview.isAvailable()); - if (InAppReview.isAvailable()) { - InAppReview.RequestInAppReview() - .then(hasFlowFinishedSuccessfully => { - console.log('InAppReview in Android', hasFlowFinishedSuccessfully); - }) - .catch(error => { - console.log('InAppReview error', error); - }); - } - }; - const getMobileUser = async user_id => { const response = await fetch( REACT_APP_URL + '/utilisateurs-mobiles/' + user_id + '?version=2', @@ -144,7 +130,6 @@ const App = () => { useEffect(() => { // clearStorage(); - handleAppReview(); checkUserIdInStorage(); Matomo.initTracker(MATOMO_SITE_URL + 'matomo.php', parseInt(MATOMO_ID)); checkUpdateNeeded(); diff --git a/tumeplayMobile/src/components/Orders/OrderConfirm.js b/tumeplayMobile/src/components/Orders/OrderConfirm.js index d03bacfd..420b93b0 100644 --- a/tumeplayMobile/src/components/Orders/OrderConfirm.js +++ b/tumeplayMobile/src/components/Orders/OrderConfirm.js @@ -86,7 +86,10 @@ const OrderConfirm = props => { const handleClosingModal = () => { if (!isLoading) { Event.boxOrdered(); - navigation.navigate('Home', {screen: 'Accueil'}); + navigation.navigate('Home', { + screen: 'Accueil', + params: {shouldReview: true}, + }); setIsVisible(false); } }; diff --git a/tumeplayMobile/src/components/Orders/Pickup/PickupOrderConfirm.js b/tumeplayMobile/src/components/Orders/Pickup/PickupOrderConfirm.js index c52e36ef..d6721c38 100644 --- a/tumeplayMobile/src/components/Orders/Pickup/PickupOrderConfirm.js +++ b/tumeplayMobile/src/components/Orders/Pickup/PickupOrderConfirm.js @@ -91,7 +91,10 @@ const PickupOrderConfirm = props => { const handleClosingModal = () => { if (!isLoading) { - navigation.navigate('Home', {screen: 'Accueil'}); + navigation.navigate('Home', { + screen: 'Accueil', + params: {shouldReview: true}, + }); setIsVisible(false); } }; diff --git a/tumeplayMobile/src/hooks/useAppReview.js b/tumeplayMobile/src/hooks/useAppReview.js new file mode 100644 index 00000000..519e4156 --- /dev/null +++ b/tumeplayMobile/src/hooks/useAppReview.js @@ -0,0 +1,19 @@ +import {Alert} from 'react-native'; +import InAppReview from 'react-native-in-app-review'; + +export default function useAppReview() { + const onReview = async () => { + if (InAppReview.isAvailable()) { + InAppReview.RequestInAppReview() + .then(hasFlowFinishedSuccessfully => { + console.log('InAppReview', hasFlowFinishedSuccessfully); + }) + .catch(error => { + Alert.alert(); + }); + } + }; + return { + onReview, + }; +} diff --git a/tumeplayMobile/src/views/HomePage.js b/tumeplayMobile/src/views/HomePage.js index 77fea744..5ba8e950 100644 --- a/tumeplayMobile/src/views/HomePage.js +++ b/tumeplayMobile/src/views/HomePage.js @@ -15,9 +15,11 @@ import config from '../../config'; import {WebView} from 'react-native-webview'; import Event from '../services/api/matomo'; import handleRedirection from '../services/handleRedirection'; +import useAppReview from '../hooks/useAppReview'; -const HomePage = ({navigation}) => { +const HomePage = ({navigation, route}) => { const {user} = useContext(AppContext); + const {onReview} = useAppReview(); const [tiktokHtmls, setTiktokHtmls] = useState([]); const tiktokIds = [ '7058603040588188933', @@ -49,6 +51,10 @@ const HomePage = ({navigation}) => { } }, [data, loading]); + useEffect(() => { + route?.params?.shouldReview && onReview(); + }, [route]); + const renderItem = ({item}) => { return ( Date: Tue, 26 Apr 2022 12:10:01 +0200 Subject: [PATCH 3/5] feat: catching error on api call --- tumeplayMobile/src/hooks/useAppReview.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tumeplayMobile/src/hooks/useAppReview.js b/tumeplayMobile/src/hooks/useAppReview.js index 519e4156..08e0ffe6 100644 --- a/tumeplayMobile/src/hooks/useAppReview.js +++ b/tumeplayMobile/src/hooks/useAppReview.js @@ -9,7 +9,7 @@ export default function useAppReview() { console.log('InAppReview', hasFlowFinishedSuccessfully); }) .catch(error => { - Alert.alert(); + console.log(error); }); } }; From 93bf9181d923c9c133449d28d314a2cd84d533a5 Mon Sep 17 00:00:00 2001 From: BrianRid Date: Tue, 26 Apr 2022 12:17:45 +0200 Subject: [PATCH 4/5] fix: fixing input in order process with trim --- tumeplayMobile/src/components/Orders/HomeOrdersInput.js | 2 +- .../src/components/Orders/Pickup/PickupOrderUserInfos.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tumeplayMobile/src/components/Orders/HomeOrdersInput.js b/tumeplayMobile/src/components/Orders/HomeOrdersInput.js index 0bd3eb1d..18a96282 100644 --- a/tumeplayMobile/src/components/Orders/HomeOrdersInput.js +++ b/tumeplayMobile/src/components/Orders/HomeOrdersInput.js @@ -237,7 +237,7 @@ const HomeOrdersInput = props => { errors[item.name] ? '#D42201' : '#EAE2D7' } activeUnderlineColor="#D42201" - value={values[item.name]} + value={values[item.name].trim()} onChangeText={handleChange(item.name)} keyboardType={item.isNumber ? 'numeric' : 'default'} /> diff --git a/tumeplayMobile/src/components/Orders/Pickup/PickupOrderUserInfos.js b/tumeplayMobile/src/components/Orders/Pickup/PickupOrderUserInfos.js index cb19dc98..13556558 100644 --- a/tumeplayMobile/src/components/Orders/Pickup/PickupOrderUserInfos.js +++ b/tumeplayMobile/src/components/Orders/Pickup/PickupOrderUserInfos.js @@ -80,7 +80,7 @@ const PickupOrderUserInfos = props => { Date: Tue, 26 Apr 2022 12:19:48 +0200 Subject: [PATCH 5/5] fix: code smell --- tumeplayMobile/src/hooks/useAppReview.js | 1 - 1 file changed, 1 deletion(-) diff --git a/tumeplayMobile/src/hooks/useAppReview.js b/tumeplayMobile/src/hooks/useAppReview.js index 08e0ffe6..164f95ea 100644 --- a/tumeplayMobile/src/hooks/useAppReview.js +++ b/tumeplayMobile/src/hooks/useAppReview.js @@ -1,4 +1,3 @@ -import {Alert} from 'react-native'; import InAppReview from 'react-native-in-app-review'; export default function useAppReview() {