### Install React Native In-App Review (Free User) Source: https://github.com/minasamir11/react-native-in-app-review/blob/master/README.md Install the react-native-in-app-review package using npm or yarn for free users. The latest version will be available on the public registry after a delay. ```bash $ npm install react-native-in-app-review ``` ```bash $ yarn add react-native-in-app-review ``` -------------------------------- ### Install CocoaPods for iOS Source: https://github.com/minasamir11/react-native-in-app-review/blob/master/README.md For iOS development, ensure CocoaPods is installed and then add the library to your Podfile. Run 'pod install' to complete the process. ```bash sudo gem install cocoapods ``` ```ruby pod 'react-native-in-app-review', :path => '../node_modules/react-native-in-app-review' ``` ```bash npx pod-install ``` -------------------------------- ### Mock React Native In-App Review using Jest Setup File Source: https://github.com/minasamir11/react-native-in-app-review/blob/master/README.md Configure Jest to mock the react-native-in-app-review package by adding this to your jest.setup.js file. This ensures your tests can run without the actual native module. ```javascript // jest.setup.js jest.mock('react-native-in-app-review', () => ({ RequestInAppReview: jest.fn(), isAvailable: jest.fn(), })); ``` -------------------------------- ### Jest Mocking for In-App Review Source: https://context7.com/minasamir11/react-native-in-app-review/llms.txt Provides examples of how to mock the react-native-in-app-review library for unit testing in a Jest environment. ```APIDOC ## Jest Mocking ### Description To unit test components that use `react-native-in-app-review`, the native module must be mocked in Jest. Two common methods are using a `__mocks__` file or an inline `jest.mock` call. ### Option A: `__mocks__` file Create a file named `react-native-in-app-review.js` inside your project's `__mocks__` directory. ```javascript // __mocks__/react-native-in-app-review.js module.exports = { RequestInAppReview: jest.fn().mockResolvedValue(true), requestInAppCommentAppGallery: jest.fn().mockResolvedValue(102), isAvailable: jest.fn().mockReturnValue(true), }; ``` ### Option B: Inline `jest.mock` Use `jest.mock` in a setup file (e.g., `jest.setup.js`) referenced in your `jest.config.js`. ```javascript // jest.setup.js jest.mock('react-native-in-app-review', () => ({ RequestInAppReview: jest.fn().mockResolvedValue(true), requestInAppCommentAppGallery: jest.fn().mockResolvedValue(102), isAvailable: jest.fn().mockReturnValue(true), })); ``` ### Example Test Demonstrates how to use the mock in a Jest test. ```javascript import InAppReview from 'react-native-in-app-review'; describe('ReviewScreen', () => { it('calls RequestInAppReview when review button is pressed', async () => { // Arrange: mock resolves successfully InAppReview.RequestInAppReview.mockResolvedValueOnce(true); // Act const result = await InAppReview.RequestInAppReview(); // Assert expect(InAppReview.RequestInAppReview).toHaveBeenCalledTimes(1); expect(result).toBe(true); }); it('isAvailable returns false for unsupported devices', () => { InAppReview.isAvailable.mockReturnValueOnce(false); expect(InAppReview.isAvailable()).toBe(false); }); }); ``` ``` -------------------------------- ### Jest Mocking for InAppReview Source: https://context7.com/minasamir11/react-native-in-app-review/llms.txt Mock the `react-native-in-app-review` native module for Jest environments. Two patterns are supported: a `__mocks__` file or an inline `jest.mock` call in a setup file. This allows for unit testing components that rely on the library. ```javascript // Option A: __mocks__/react-native-in-app-review.js // Place this file at /__mocks__/react-native-in-app-review.js module.exports = { RequestInAppReview: jest.fn().mockResolvedValue(true), requestInAppCommentAppGallery: jest.fn().mockResolvedValue(102), isAvailable: jest.fn().mockReturnValue(true), }; // Option B: jest.setup.js (referenced via setupFilesAfterEach in jest.config) jest.mock('react-native-in-app-review', () => ({ RequestInAppReview: jest.fn().mockResolvedValue(true), requestInAppCommentAppGallery: jest.fn().mockResolvedValue(102), isAvailable: jest.fn().mockReturnValue(true), })); // Example test using the mock import InAppReview from 'react-native-in-app-review'; describe('ReviewScreen', () => { it('calls RequestInAppReview when review button is pressed', async () => { // Arrange: mock resolves successfully InAppReview.RequestInAppReview.mockResolvedValueOnce(true); // Act const result = await InAppReview.RequestInAppReview(); // Assert expect(InAppReview.RequestInAppReview).toHaveBeenCalledTimes(1); expect(result).toBe(true); }); it('isAvailable returns false for unsupported devices', () => { InAppReview.isAvailable.mockReturnValueOnce(false); expect(InAppReview.isAvailable()).toBe(false); }); }); ``` -------------------------------- ### Request Huawei AppGallery Comment Source: https://github.com/minasamir11/react-native-in-app-review/blob/master/README.md Triggers the in-app comment UI for Huawei AppGallery. This requires HMS integration and the app to be officially released on AppGallery with users having a recent version of AppGallery installed and signed in. ```APIDOC ## requestInAppCommentAppGallery ### Description Triggers the in-app comment UI for Huawei AppGallery. This method is intended for users who have integrated Huawei Mobile Services (HMS) and meet the AppGallery requirements. ### Method `InAppReview.requestInAppCommentAppGallery()` ### Returns - `Promise`: Resolves with a `resultCode` indicating the outcome (e.g., 102 for Rating submitted, 103 for Comment submitted). Rejects with an error if an issue occurs. ### Example ```javascript InAppReview.requestInAppCommentAppGallery() .then((resultCode) => { console.log('AppGallery comment result code:', resultCode); }) .catch((error) => { console.error('Error requesting AppGallery comment:', error); }); ``` ``` -------------------------------- ### Request Huawei AppGallery In-App Comment Source: https://context7.com/minasamir11/react-native-in-app-review/llms.txt Triggers the Huawei AppGallery in-app comment flow on Android devices. This method requires HMS Core and AppGallery 11.3.2.302+ installed. It returns a Promise that resolves with a result code or rejects with an error code. ```APIDOC ## `InAppReview.requestInAppCommentAppGallery()` ### Description Launches the Huawei AppGallery in-app comment intent. This method is Android-only and requires specific versions of HMS Core and AppGallery. ### Method `requestInAppCommentAppGallery()` ### Parameters None ### Returns A `Promise` that resolves with a numeric result code: - `102`: User submitted a rating. - `103`: User submitted a comment. Rejects with an error code indicating the failure reason: - `"0"`: Unknown error. - `"24"`: Activity doesn't exist. - `"101"`: App not correctly released on AppGallery. - `"104"`: HUAWEI ID sign-in issue. - `"105"`: User does not meet display conditions. - `"106"`: Commenting function is disabled. - `"107"`: Service not supported (Chinese mainland apps). - `"108"`: User canceled the comment. ### Request Example ```javascript import InAppReview from 'react-native-in-app-review'; import { Platform } from 'react-native'; if (Platform.OS === 'android') { InAppReview.requestInAppCommentAppGallery() .then((resultCode) => { console.log('AppGallery comment result code:', resultCode); }) .catch((errorCode) => { console.error('AppGallery comment error code:', errorCode); }); } ``` ``` -------------------------------- ### Trigger Huawei AppGallery In-App Comment Flow Source: https://context7.com/minasamir11/react-native-in-app-review/llms.txt Use this method on Android devices with HMS Core and AppGallery 11.3.2.302+ installed to launch the Huawei AppGallery in-app comment intent. It returns a Promise that resolves with a numeric result code or rejects with an error code. ```javascript import InAppReview from 'react-native-in-app-review'; import { Platform } from 'react-native'; // Only invoke on Android Huawei devices with HMS if (Platform.OS === 'android') { InAppReview.requestInAppCommentAppGallery() .then((resultCode) => { // 102 → User submitted a rating // 103 → User submitted a comment console.log('AppGallery comment result code:', resultCode); }) .catch((errorCode) => { // Error codes from AppGallery: // "0" → Unknown error // "24" → Activity doesn't exist // "101" → App not correctly released on AppGallery // "104" → HUAWEI ID sign-in issue // "105" → User does not meet display conditions (< 10 opens in last 3 months) // "106" → Commenting function is disabled // "107" → Service not supported (Chinese mainland apps) // "108" → User canceled the comment console.error('AppGallery comment error code:', errorCode); }); } ``` -------------------------------- ### InAppReview.RequestInAppReview() Source: https://context7.com/minasamir11/react-native-in-app-review/llms.txt Asynchronously launches the platform-native review dialog. Returns a Promise that resolves with a boolean indicating success or rejects with an error code. ```APIDOC ## InAppReview.RequestInAppReview() ### Description Asynchronously launches the platform-native review dialog. On Android, this uses `ReviewManagerFactory` to request a `ReviewInfo` token and then launches the review flow via `launchReviewFlow`. On iOS (14+), it uses `AppStore.requestReview(in:)` targeting the active `UIWindowScene`; on iOS 10.3–13 it falls back to `SKStoreReviewController.requestReview()`. Returns a `Promise` — resolves `true` when the flow completes or is launched; rejects with an error code on failure. ### Method Asynchronous function call returning a Promise ### Endpoint N/A (Native module function) ### Parameters None ### Request Example ```javascript import InAppReview from 'react-native-in-app-review'; // Trigger the in-app review dialog with full error handling InAppReview.RequestInAppReview() .then((hasFlowFinishedSuccessfully) => { // Android: true means the review flow UI was shown and dismissed (user may or may not have rated) // iOS: true means the review prompt was successfully launched // NOTE: The API does not reveal whether the user actually submitted a review if (hasFlowFinishedSuccessfully) { console.log('Review flow completed.'); // Optionally record the timestamp to avoid re-prompting too soon } }) .catch((errorCode) => { // Error codes: // "21" → ERROR_DEVICE_VERSION (device OS too old) // "22" → GOOGLE_SERVICES_NOT_AVAILABLE (Android only) // "23" → Unexpected Google Play error // "24" → ACTIVITY_DOESN'T_EXIST (Android) / current activity unavailable // "25" → SCENE_DOESN'T_EXIST (iOS) / no active UIWindowScene console.error('InAppReview error code:', errorCode); }); ``` ### Response #### Success Response - **hasFlowFinishedSuccessfully** (boolean) - `true` if the review flow was successfully launched or completed. #### Error Response - **errorCode** (string) - A string representing the error code encountered during the review flow attempt. ``` -------------------------------- ### Android Settings Gradle Configuration Source: https://github.com/minasamir11/react-native-in-app-review/blob/master/README.md Add this to your android/settings.gradle file to include the library. ```gradle 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') ``` -------------------------------- ### Android MainApplication Java Imports Source: https://github.com/minasamir11/react-native-in-app-review/blob/master/README.md Import the AppReviewPackage at the top of your MainApplication.java file. ```java import com.ibits.react_native_in_app_review.AppReviewPackage; ``` -------------------------------- ### Import InAppReview Module Source: https://github.com/minasamir11/react-native-in-app-review/blob/master/README.md Import the InAppReview module at the beginning of your JavaScript file. ```javascript import InAppReview from 'react-native-in-app-review'; ``` -------------------------------- ### Set npm Registry for Paid Users Source: https://github.com/minasamir11/react-native-in-app-review/blob/master/README.md For paid users, configure your package manager to use the PayDevs registry. This involves setting the registry URL and logging in. ```bash npm set registry https://npm.paydevs.com/ npm login npm update ``` ```bash yarn config set registry https://npm.paydevs.com/ yarn login yarn upgrade ``` -------------------------------- ### InAppReview.isAvailable() Source: https://context7.com/minasamir11/react-native-in-app-review/llms.txt Checks if the current device and OS version support the in-app review feature. Returns a boolean value. ```APIDOC ## InAppReview.isAvailable() ### Description Checks if in-app review is supported on the current device. Returns a synchronous boolean indicating whether the current device and OS version support in-app review. On Android, requires API level 21 or higher. On iOS, checks for the presence of `SKStoreReviewController`. Returns `false` on unsupported platforms (e.g., Windows, web). ### Method Synchronous function call ### Usage ```javascript import InAppReview from 'react-native-in-app-review'; // Check availability before attempting to trigger the review flow if (InAppReview.isAvailable()) { console.log('In-app review is supported on this device.'); } else { console.log('In-app review is NOT supported (OS too old or unsupported platform).'); // Android < API 21 or iOS < 10.3 → fall back to opening the store URL manually } ``` ``` -------------------------------- ### Android MainApplication Java Packages Source: https://github.com/minasamir11/react-native-in-app-review/blob/master/README.md Include AppReviewPackage in the list of React packages in your MainApplication.java. ```java @Override protected List getPackages() { return Arrays.asList( new MainReactPackage(), new AppReviewPackage() ); } ``` -------------------------------- ### Check In-App Review Availability Source: https://context7.com/minasamir11/react-native-in-app-review/llms.txt Use this synchronous method to determine if the current device and OS version support in-app reviews before attempting to trigger the review flow. Returns false on unsupported platforms or older OS versions. ```javascript import InAppReview from 'react-native-in-app-review'; // Check availability before attempting to trigger the review flow if (InAppReview.isAvailable()) { console.log('In-app review is supported on this device.'); } else { console.log('In-app review is NOT supported (OS too old or unsupported platform).'); // Android < API 21 or iOS < 10.3 → fall back to opening the store URL manually } ``` -------------------------------- ### AndroidX Migration Properties Source: https://github.com/minasamir11/react-native-in-app-review/blob/master/README.md Ensure these properties are set in android/gradle.properties for AndroidX migration (version >= 5.0.0). ```properties android.useAndroidX=true android.enableJetifier=true ``` -------------------------------- ### Request In-App Review Source: https://context7.com/minasamir11/react-native-in-app-review/llms.txt Requests the standard in-app review prompt. This is often used in conjunction with a throttling mechanism to avoid excessive prompts. ```APIDOC ## `InAppReview.RequestInAppReview()` ### Description Requests the standard in-app review prompt. This method is typically used after checking conditions like a minimum re-prompt interval. ### Method `RequestInAppReview()` ### Parameters None ### Returns Typically returns a `Promise` that resolves when the review flow is completed or dismissed. The exact resolution value might vary, but often indicates success or failure. ### Request Example ```javascript import InAppReview from 'react-native-in-app-review'; // Assuming conditions are met to prompt for review InAppReview.RequestInAppReview() .then(() => { console.log('In-app review prompt shown successfully.'); }) .catch((error) => { console.error('Error showing in-app review prompt:', error); }); ``` ``` -------------------------------- ### Throttled Review Hook with AsyncStorage Source: https://context7.com/minasamir11/react-native-in-app-review/llms.txt Implement a custom hook to gate `RequestInAppReview` behind a minimum re-prompt interval stored in AsyncStorage. This prevents repeated prompts and respects platform quotas by checking the last review date. ```javascript import React from 'react'; import { View, Text, Pressable } from 'react-native'; import { useAsyncStorage } from '@react-native-async-storage/async-storage'; import InAppReview from 'react-native-in-app-review'; const REVIEW_INTERVAL_DAYS = 15; const STORAGE_KEY = 'in_App_Review'; function useAppReview() { const { getItem, setItem } = useAsyncStorage(STORAGE_KEY); const onReview = async () => { const lastReviewDate = await getItem(); if (lastReviewDate !== null) { const diffMs = Math.abs(new Date() - Date.parse(lastReviewDate)); const diffDays = Math.ceil(diffMs / (1000 * 60 * 60 * 24)); if (diffDays > REVIEW_INTERVAL_DAYS) { await setItem(new Date().toString()); InAppReview.RequestInAppReview(); } // else: still within cooldown window — do not prompt } else { // First time — store date and prompt immediately await setItem(new Date().toString()); InAppReview.RequestInAppReview(); } }; return { onReview }; } // Usage inside a component (e.g., triggered on checkout or task completion) export default function CheckoutScreen() { const { onReview } = useAppReview(); return ( Checkout ); } ``` -------------------------------- ### Android App Build Gradle Dependency Source: https://github.com/minasamir11/react-native-in-app-review/blob/master/README.md For versions >= 5.0.0, add this implementation to your android/app/build.gradle dependencies. ```gradle implementation project(':react-native-in-app-review') ``` -------------------------------- ### Request In-App Review Source: https://github.com/minasamir11/react-native-in-app-review/blob/master/README.md Check if the in-app review is available and then request it. This package is only available on Android version >= 21 and iOS >= 10.3. The result indicates if the user finished or closed the review flow on Android, or if the flow was launched on iOS. ```javascript // This package is only available on android version >= 21 and iOS >= 10.3 // Give you result if version of device supported to rate app or not! InAppReview.isAvailable(); // trigger UI InAppreview InAppReview.RequestInAppReview() .then((hasFlowFinishedSuccessfully) => { // when return true in android it means user finished or close review flow console.log('InAppReview in android', hasFlowFinishedSuccessfully); // when return true in ios it means review flow lanuched to user. console.log( 'InAppReview in ios has launched successfully', hasFlowFinishedSuccessfully, ); // 1- you have option to do something ex: (navigate Home page) (in android). // 2- you have option to do something, // ex: (save date today to lanuch InAppReview after 15 days) (in android and ios). // 3- another option: if (hasFlowFinishedSuccessfully) { // do something for ios // do something for android } // for android: // The flow has finished. The API does not indicate whether the user // reviewed or not, or even whether the review dialog was shown. Thus, no // matter the result, we continue our app flow. // for ios // the flow lanuched successfully, The API does not indicate whether the user // reviewed or not, or he/she closed flow yet as android, Thus, no // matter the result, we continue our app flow. }) .catch((error) => { //we continue our app flow. // we have some error could happen while lanuching InAppReview, // Check table for errors and code number that can return in catch. console.log(error); }); ``` -------------------------------- ### Request In-App Review Source: https://github.com/minasamir11/react-native-in-app-review/blob/master/README.md Triggers the in-app review UI. The behavior and return values differ slightly between Android and iOS. ```APIDOC ## RequestInAppReview ### Description Triggers the in-app review UI. On Android, it indicates if the user finished or closed the review flow. On iOS, it indicates if the review flow was launched successfully. ### Method `InAppReview.RequestInAppReview()` ### Returns - `Promise`: Resolves with `true` if the review flow was completed or launched successfully, `false` otherwise. Rejects with an error if an issue occurs. ### Example ```javascript InAppReview.RequestInAppReview() .then((hasFlowFinishedSuccessfully) => { console.log('InAppReview result:', hasFlowFinishedSuccessfully); }) .catch((error) => { console.error('Error requesting in-app review:', error); }); ``` ``` -------------------------------- ### Check Review Availability Source: https://context7.com/minasamir11/react-native-in-app-review/llms.txt Checks if the in-app review functionality is available on the current device and platform. ```APIDOC ## `InAppReview.isAvailable()` ### Description Determines if the in-app review feature is available on the current device and platform. This is useful for conditionally displaying review prompts. ### Method `isAvailable()` ### Parameters None ### Returns A boolean value: `true` if in-app review is available, `false` otherwise. ### Request Example ```javascript import InAppReview from 'react-native-in-app-review'; if (InAppReview.isAvailable()) { // Show review prompt or button console.log('In-app review is available.'); } else { // Handle cases where review is not available console.log('In-app review is not available.'); } ``` ``` -------------------------------- ### Check Review Availability Source: https://github.com/minasamir11/react-native-in-app-review/blob/master/README.md Checks if the in-app review functionality is available on the current device. This package is only available on Android version >= 21 and iOS >= 10.3. ```APIDOC ## isAvailable ### Description Checks if the in-app review functionality is available on the current device. ### Method `InAppReview.isAvailable()` ### Returns - `boolean`: Returns true if the review functionality is available, false otherwise. ``` -------------------------------- ### Mock React Native In-App Review for Jest Source: https://github.com/minasamir11/react-native-in-app-review/blob/master/README.md Use this mock for Jest tests when integrating the react-native-in-app-review package. Adapt the mocked methods as needed for your specific test cases. ```javascript // __mocks__/react-native-in-app-review.js module.exports = { RequestInAppReview: jest.fn(), isAvailable: jest.fn(), // add more methods as needed }; ``` -------------------------------- ### Trigger In-App Review Flow Source: https://context7.com/minasamir11/react-native-in-app-review/llms.txt Asynchronously launches the native review dialog. Handles different platform implementations (Android, iOS 10.3+). Resolves with a boolean indicating success or rejects with an error code on failure. Note that the API does not reveal if the user actually submitted a review. ```javascript import InAppReview from 'react-native-in-app-review'; // Trigger the in-app review dialog with full error handling InAppReview.RequestInAppReview() .then((hasFlowFinishedSuccessfully) => { // Android: true means the review flow UI was shown and dismissed (user may or may not have rated) // iOS: true means the review prompt was successfully launched // NOTE: The API does not reveal whether the user actually submitted a review if (hasFlowFinishedSuccessfully) { console.log('Review flow completed.'); // Optionally record the timestamp to avoid re-prompting too soon } }) .catch((errorCode) => { // Error codes: // "21" → ERROR_DEVICE_VERSION (device OS too old) // "22" → GOOGLE_SERVICES_NOT_AVAILABLE (Android only) // "23" → Unexpected Google Play error // "24" → ACTIVITY_DOESN'T_EXIST (Android) / current activity unavailable // "25" → SCENE_DOESN'T_EXIST (iOS) / no active UIWindowScene console.error('InAppReview error code:', errorCode); }); ``` -------------------------------- ### Request Huawei AppGallery Comment Source: https://github.com/minasamir11/react-native-in-app-review/blob/master/README.md Trigger the UI for requesting a review or comment on Huawei AppGallery. Requires HMS integration and the app to be officially released on AppGallery with users having AppGallery version 11.3.2.302 or later and signed in with HUAWEI IDs. ```javascript // trigger UI in app comment to request review for App Gallery; InAppReview.requestInAppCommentAppGallery() .then((resultCode) => { // when return resultCode (102,103) in android it means Rating submitted or Comment submitted console.log('in app comment app gallery', resultCode); }) .catch((error) => { //we continue our app flow. // we have some error could happen while lanuching in app comment, // Check table for errors appears in app gallery and code number that can return in catch. console.log(error); }); ``` -------------------------------- ### Resolve TypeError in In-App Review Mock Source: https://github.com/minasamir11/react-native-in-app-review/blob/master/README.md If you encounter a 'TypeError: Cannot read property 'then' of undefined' when mocking RequestInAppReview, use this implementation to provide a resolving promise. ```javascript RequestInAppReview: jest.fn().mockImplementation(() => { return Promise.resolve(); }), ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.