1 | import { NativeModules, Platform, Linking } from 'react-native';
|
2 | import { Constants } from 'expo-constants';
|
3 | /*
|
4 | * Platform must be iOS
|
5 | * iOS 10.3 or greater
|
6 | * `SKStoreReviewController` class is available
|
7 | */
|
8 | export function isSupported() {
|
9 | return Platform.OS === 'ios' && NativeModules.ExponentStoreReview.isSupported;
|
10 | }
|
11 | /*
|
12 | Use the iOS `SKStoreReviewController` API to prompt a user rating without leaving the app.
|
13 | */
|
14 | export function requestReview() {
|
15 | if (isSupported()) {
|
16 | NativeModules.ExponentStoreReview.requestReview();
|
17 | }
|
18 | else {
|
19 | /*
|
20 | If StoreReview is unavailable then get the store URL from the `app.json` and open to the store.
|
21 | */
|
22 | const url = storeUrl();
|
23 | if (url) {
|
24 | Linking.canOpenURL(url)
|
25 | .then(supported => {
|
26 | if (!supported) {
|
27 | console.log("Expo.StoreReview.requestReview(): Can't open store url: ", url);
|
28 | return;
|
29 | }
|
30 | else {
|
31 | return Linking.openURL(url);
|
32 | }
|
33 | })
|
34 | .catch(err => console.warn('Expo.StoreReview.requestReview(): Error opening link to store: ', err));
|
35 | }
|
36 | else {
|
37 | // If the store URL is missing, let the dev know.
|
38 | console.log("Expo.StoreReview.requestReview(): Couldn't link to store, please make sure the `android.playStoreUrl` & `ios.appStoreUrl` fields are filled out in your `app.json`");
|
39 | }
|
40 | }
|
41 | }
|
42 | /*
|
43 | Get your app's store URLs from the `app.json`
|
44 |
|
45 | * iOS: https://docs.expo.io/versions/latest/workflow/configuration#appstoreurlurl-to-your-app-on-the-apple-app-store-if-you-have-deployed-it-there-this-is-used-to-link-to-your-store-page-from-your-expo-project-page-if-your-app-is-public
|
46 | * Android: https://docs.expo.io/versions/latest/workflow/configuration#playstoreurlurl-to-your-app-on-the-google-play-store-if-you-have-deployed-it-there-this-is-used-to-link-to-your-store-page-from-your-expo-project-page-if-your-app-is-public
|
47 | */
|
48 | export function storeUrl() {
|
49 | const { OS } = Platform;
|
50 | if (OS === 'ios') {
|
51 | return Constants.manifest.ios.appStoreUrl;
|
52 | }
|
53 | else if (OS === 'android') {
|
54 | return Constants.manifest.android.playStoreUrl;
|
55 | }
|
56 | else {
|
57 | console.warn(`Expo.StoreReview.storeUrl(): Unsupported OS: ${OS}`);
|
58 | }
|
59 | return null;
|
60 | }
|
61 | /*
|
62 | A flag to detect if this module can do anything
|
63 | */
|
64 | export function hasAction() {
|
65 | return !!storeUrl() || isSupported();
|
66 | }
|
67 | //# sourceMappingURL=StoreReview.js.map |
\ | No newline at end of file |