1 | import { NativeModules } from 'react-native';
|
2 |
|
3 | const { RNStoreReview } = NativeModules;
|
4 |
|
5 | /**
|
6 | * Whether or not the requestReview() function is available.
|
7 | */
|
8 | export const isAvailable = !!RNStoreReview && RNStoreReview.isAvailable;
|
9 |
|
10 | /**
|
11 | * Asks the user to rate the app in the iOS App Store.
|
12 | * @throws Will throw an Error if native module is not present or not supported by the iOS version.
|
13 | */
|
14 | export function requestReview() {
|
15 | if (!RNStoreReview) {
|
16 | throw new Error('StoreReview native module not available, did you forget to link the library?');
|
17 | }
|
18 | if (!isAvailable) {
|
19 | throw new Error('StoreReview is not available on this version of iOS');
|
20 | }
|
21 | return RNStoreReview.requestReview();
|
22 | }
|