### Install react-native-inappbrowser-reborn Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/README.md Install the library using npm and run pod install for iOS. This is the initial setup step for using the library. ```bash npm install react-native-inappbrowser-reborn cd ios && pod install && cd .. ``` -------------------------------- ### iOS Manual Installation Steps Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/README.md Manual installation steps for iOS, involving adding the project to Xcode, linking the library, and adding it to build phases. ```bash 1. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]` 2. Go to `node_modules` ➜ `react-native-inappbrowser-reborn` and add `RNInAppBrowser.xcodeproj` 3. In XCode, in the project navigator, select your project. Add `libRNInAppBrowser.a` to your project's `Build Phases` ➜ `Link Binary With Libraries` 4. Run your project (`Cmd+R`) ``` -------------------------------- ### iOS Deep Linking Example (Info.plist) Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/configuration.md An example of iOS deep linking setup in Info.plist using a reverse domain name notation for the URL scheme. ```xml CFBundleURLTypes CFBundleTypeRole Editor CFBundleURLName com.mycompany.myapp CFBundleURLSchemes com.mycompany.myapp ``` -------------------------------- ### Install Package with Yarn Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/configuration.md Use this command to install the package using Yarn. ```bash yarn add react-native-inappbrowser-reborn ``` -------------------------------- ### Usage Example for Deep Linking Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/configuration.md Example demonstrating how to use the `getDeepLink` utility function to construct an authentication URL and then open it using `InAppBrowser.openAuth()`. ```javascript const deepLink = getDeepLink('callback'); const authUrl = `https://auth-provider.com/oauth?redirect_uri=${encodeURIComponent(deepLink)}`; const result = await InAppBrowser.openAuth(authUrl, deepLink); ``` -------------------------------- ### Android Deep Linking Example (AndroidManifest.xml) Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/configuration.md An example of Android deep linking setup in AndroidManifest.xml, demonstrating a specific scheme and host for handling callback URLs. ```xml ``` -------------------------------- ### Install Package with npm Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/configuration.md Use this command to install the package using npm. ```bash npm install react-native-inappbrowser-reborn --save ``` -------------------------------- ### iOS Manual Installation Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/configuration.md Use this command for manual linking if you are using React Native versions below 0.60. ```bash react-native link react-native-inappbrowser-reborn ``` -------------------------------- ### Android InAppBrowser Configuration Example Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/types.md Demonstrates how to configure Android-specific options for the InAppBrowser, including custom colors, URL bar hiding, and headers. This example shows a comprehensive set of options. ```javascript const androidOptions = { showTitle: true, toolbarColor: '#6200EE', secondaryToolbarColor: 'black', navigationBarColor: 'black', navigationBarDividerColor: 'white', enableUrlBarHiding: true, enableDefaultShare: true, forceCloseOnRedirection: false, animations: { startEnter: 'slide_in_right', startExit: 'slide_out_left', endEnter: 'slide_in_left', endExit: 'slide_out_right' }, headers: { 'X-Custom-Header': 'value', 'Authorization': 'Bearer token123' }, hasBackButton: true, showInRecents: true, includeReferrer: true }; await InAppBrowser.open(url, androidOptions); ``` -------------------------------- ### Install React Native InAppBrowser Reborn Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/README.md Install the package using npm. This is the first step to integrating the in-app browser functionality. ```bash $ npm install react-native-inappbrowser-reborn --save ``` -------------------------------- ### Flow Usage Example Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/api-reference/module-exports.md Demonstrates importing InAppBrowser and InAppBrowserOptions in a Flow-typed JavaScript file. ```flow // @flow import type { InAppBrowserOptions } from 'react-native-inappbrowser-reborn'; import { InAppBrowser } from 'react-native-inappbrowser-reborn'; const openUrl = async (url: string, options?: InAppBrowserOptions): Promise => { await InAppBrowser.open(url, options); }; ``` -------------------------------- ### Android Integration Setup Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/quick-reference.md Add this code to your MainActivity.java file to integrate the InAppBrowser module on Android. This ensures the module is properly initialized when the app starts. ```java import com.proyecto26.inappbrowser.RNInAppBrowserModule; public class MainActivity extends AppCompatActivity { @Override protected void onStart() { super.onStart(); RNInAppBrowserModule.onStart(this); } } ``` -------------------------------- ### iOS Pod Install Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/README.md After installing the package, run 'pod install' for iOS to link the native dependencies. This is required for React Native versions 0.60 and above. ```bash $ cd ios && pod install && cd .. ``` -------------------------------- ### Platform-Agnostic InAppBrowser Options Example Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/types.md Shows how to define a single options object that includes both iOS and Android specific configurations for InAppBrowser.open(). ```javascript const platformAgnosticOptions = { // iOS options dismissButtonStyle: 'cancel', preferredBarTintColor: '#453AA4', // Android options showTitle: true, toolbarColor: '#6200EE' }; await InAppBrowser.open(url, platformAgnosticOptions); // Only iOS options used on iOS, Android options used on Android ``` -------------------------------- ### Example Usage of InAppBrowseriOSOptions Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/types.md Demonstrates how to configure and pass iOS-specific options when opening the InAppBrowser. Ensure these options are only used on iOS. ```javascript const iosOptions = { dismissButtonStyle: 'cancel', preferredBarTintColor: '#453AA4', preferredControlTintColor: 'white', readerMode: false, animated: true, modalPresentationStyle: 'formSheet', modalTransitionStyle: 'flipHorizontal', modalEnabled: true, enableBarCollapsing: true, formSheetPreferredContentSize: { width: 400, height: 500 } }; await InAppBrowser.open(url, iosOptions); ``` -------------------------------- ### TypeScript Usage Example Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/README.md Shows how to import and use the InAppBrowser module with TypeScript, including type definitions for options and results. ```typescript import { InAppBrowser, InAppBrowserOptions, BrowserResult } from 'react-native-inappbrowser-reborn'; const openUrl = async ( url: string, options?: InAppBrowserOptions ): Promise => { return await InAppBrowser.open(url, options); }; ``` -------------------------------- ### JavaScript/ES Modules Import and Usage Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/api-reference/module-exports.md Demonstrates both default and named imports for InAppBrowser in JavaScript/ES Modules, followed by a direct usage example. ```javascript // Default import import InAppBrowser from 'react-native-inappbrowser-reborn'; // Named import (equivalent) import { InAppBrowser } from 'react-native-inappbrowser-reborn'; // Direct usage InAppBrowser.open('https://example.com'); ``` -------------------------------- ### Manual Installation for React Native < 0.60 Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/README.md Link the package manually for React Native versions older than 0.60 using the react-native link command. ```bash $ react-native link react-native-inappbrowser-reborn ``` -------------------------------- ### Flow Type Usage Example Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/configuration.md Shows how to use the InAppBrowser with Flow types, including importing types and configuring options for opening a URL. ```flow // @flow import type { InAppBrowserOptions, BrowserResult } from 'react-native-inappbrowser-reborn'; import { InAppBrowser } from 'react-native-inappbrowser-reborn'; const openUrl = async (url: string): Promise => { const options: InAppBrowserOptions = { dismissButtonStyle: 'close' }; return await InAppBrowser.open(url, options); }; ``` -------------------------------- ### Install TypeScript Dependencies Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/README.md Installs TypeScript and React Native types as development dependencies for TypeScript support. ```bash npm install --save-dev typescript @types/react-native ``` -------------------------------- ### iOS Debug Output Example Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/platform-specific.md This snippet shows typical debug output from the Xcode console for the InAppBrowser on iOS. ```text Xcode Console: 2024-01-15 10:23:45.123 [RNInAppBrowser] Opening URL: https://example.com 2024-01-15 10:23:46.456 [RNInAppBrowser] Browser dismissed ``` -------------------------------- ### iOS Automatic Linking Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/configuration.md Run this command after installing the package if you are using React Native 0.60 or above for automatic linking. ```bash cd ios && pod install && cd .. ``` -------------------------------- ### Android Debug Output Example Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/platform-specific.md This snippet shows typical debug output from Logcat for the InAppBrowser on Android. ```text Logcat: [RNInAppBrowser] Opening Custom Tab [RNInAppBrowser] Service connected [RNInAppBrowser] Browser closed ``` -------------------------------- ### Example Usage of openAuth with AuthSessionResult Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/types.md Demonstrates how to handle the result of InAppBrowser.openAuth(), checking for success to extract an authentication code or handling user cancellation. ```javascript const result = await InAppBrowser.openAuth(url, redirectUrl); if (result.type === 'success') { // Extract auth code from result.url const code = new URL(result.url).searchParams.get('code'); } else if (result.type === 'cancel') { // User canceled authentication console.log('User canceled'); } ``` -------------------------------- ### Warm up Browser on App Start Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/usage-examples.md Pre-initializes the InAppBrowser on application startup to improve performance for subsequent launches. It also suggests URLs that the user might visit soon. ```javascript import { useEffect } from 'react'; import { InAppBrowser } from 'react-native-inappbrowser-reborn'; const AppInitializer = () => { useEffect(() => { const initializeBrowser = async () => { try { // Warm up the browser on app start const warmed = await InAppBrowser.warmup(); console.log('Browser warmup successful:', warmed); // Pre-render likely URLs InAppBrowser.mayLaunchUrl( 'https://myapp.com/home', [ 'https://myapp.com/products', 'https://myapp.com/checkout' ] ); } catch (error) { console.log('Browser optimization failed:', error); } }; initializeBrowser(); }, []); return null; }; ``` -------------------------------- ### iOS Deep Linking Setup (Info.plist) Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/quick-reference.md Configure your Info.plist file on iOS to handle deep links. This allows your app to respond to URLs with the specified scheme. ```xml CFBundleURLTypes CFBundleURLSchemes com.myapp ``` -------------------------------- ### iOS Deep Linking Setup (Info.plist) Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/configuration.md Configure your app's URL scheme in Info.plist to enable OAuth flows with deep linking. Replace 'my-scheme' with your app's unique URL scheme. ```xml CFBundleURLTypes CFBundleTypeRole Editor CFBundleURLName my-scheme CFBundleURLSchemes my-scheme ``` -------------------------------- ### Configure Android Settings Gradle Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/README.md Append lines to your android/settings.gradle file to include the react-native-inappbrowser-reborn project. This step is crucial for Android setup. ```gradle include ':react-native-inappbrowser-reborn' project(':react-native-inappbrowser-reborn').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-inappbrowser-reborn/android') ``` -------------------------------- ### Unit Test Example for OAuth Flow Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/usage-examples.md This unit test demonstrates how to test an OAuth flow using the mocked InAppBrowser. It covers successful authentication and cancellation scenarios. ```javascript import { InAppBrowser } from 'react-native-inappbrowser-reborn'; jest.mock('react-native-inappbrowser-reborn'); describe('OAuth Flow', () => { it('should call openAuth with correct parameters', async () => { const url = 'https://auth.example.com'; const redirectUrl = 'myapp://oauth/callback'; InAppBrowser.openAuth.mockResolvedValue({ type: 'success', url: 'myapp://oauth/callback?code=abc123' }); await performOAuth(url, redirectUrl); expect(InAppBrowser.openAuth).toHaveBeenCalledWith( url, redirectUrl, expect.any(Object) ); }); it('should handle auth cancellation', async () => { InAppBrowser.openAuth.mockResolvedValue({ type: 'cancel' }); const result = await performOAuth('url', 'redirectUrl'); expect(result).toBeNull(); }); }); ``` -------------------------------- ### Android Deep Linking Setup (AndroidManifest.xml) Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/configuration.md Configure your app's intent filter in AndroidManifest.xml to enable OAuth flows with deep linking. This allows specific URL schemes and hosts to open your app. ```xml ``` -------------------------------- ### Add iOS Podfile Dependency Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/README.md Add the RNInAppBrowser pod to your project's Podfile for iOS integration. Ensure you run 'pod install' afterwards. ```bash pod 'RNInAppBrowser', :path => '../node_modules/react-native-inappbrowser-reborn' ``` -------------------------------- ### onStart() (Android Integration) Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/api-reference/InAppBrowser.md A static method to be called from Android MainActivity.onStart() to initialize the browser connection service for performance optimizations. ```APIDOC ## onStart() (Android Integration) ### Description This is a static method that should be called from your Android `MainActivity.onStart()` method to initialize the browser connection service. This is separate from the main module but documented here as it's essential for Android optimizations. ### Method ```java // In your MainActivity.java import com.proyecto26.inappbrowser.RNInAppBrowserModule; public class MainActivity extends ReactActivity { @Override protected void onStart() { super.onStart(); RNInAppBrowserModule.onStart(this); } } ``` ### Purpose - Initializes a bound background service for the Custom Tabs connection - Allows the browser to warm up in the background - Improves launch performance on subsequent `open()` calls ### Notes - Should be called in `onCreate()` or early in the activity lifecycle - Only for Android—iOS handles this automatically ### Platform Support - Android: Initializes the Custom Tabs service connection - iOS: Not applicable ``` -------------------------------- ### Performance Comparison: Warmup vs. No Warmup Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/platform-specific.md Compares the user experience timelines for opening a link with and without the warmup() optimization. Highlights the significant reduction in load times when the Custom Tabs service and browser are pre-initialized. ```text Timeline without warmup: User clicks link │ ├─ Initialize service (300-500ms) ├─ Load browser (400-600ms) ├─ Open URL (200-300ms) │ ▼ Total: 900-1400ms Timeline with warmup(): App starts │ └─ warmup() at startup (happens in background) │ ├─ Initialize service (happens early) └─ Browser loaded in background User clicks link │ ├─ Service already connected (0ms) ├─ Browser already loading (0ms) ├─ Open URL (200-300ms) │ ▼ Total: 200-300ms (4-6x faster) ``` -------------------------------- ### Basic and OAuth Usage Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/README.md Demonstrates how to open a simple URL and initiate an OAuth flow using the InAppBrowser. Ensure the browser is available before opening URLs. ```javascript import { InAppBrowser } from 'react-native-inappbrowser-reborn'; // Simple URL opening if (await InAppBrowser.isAvailable()) { await InAppBrowser.open('https://github.com'); } // OAuth flow const result = await InAppBrowser.openAuth(authUrl, redirectUrl); if (result.type === 'success') { // Handle successful auth with result.url } ``` -------------------------------- ### Pre-loading URLs with mayLaunchUrl() Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/platform-specific.md Demonstrates how to use mayLaunchUrl() to hint to the browser about upcoming navigation targets. This allows the browser to pre-render or pre-load content, improving perceived performance for the user. ```javascript mayLaunchUrl('https://example.com/product/123', ['https://example.com/checkout', 'https://example.com/reviews']) ``` -------------------------------- ### Android Chrome Not Installed Check Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/platform-specific.md This snippet shows how to check if Chrome is installed on Android, which is a prerequisite for Custom Tabs. ```javascript // Chrome not installed isAvailable() returns false ``` -------------------------------- ### iOS Network Error Example Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/platform-specific.md This snippet represents a network connectivity error on iOS. ```javascript // Network error Error: Network connection lost ``` -------------------------------- ### Android Network Unreachable Error Example Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/platform-specific.md This snippet represents a network connectivity error on Android. ```javascript // Network error Error: Network unreachable ``` -------------------------------- ### Warmup and Pre-render URLs (Android) Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/README.md Prepares the in-app browser service in the background and suggests URLs to be pre-rendered for faster loading. This is typically done once during app startup. ```javascript useEffect(() => { InAppBrowser.warmup(); InAppBrowser.mayLaunchUrl(primaryUrl, [secondaryUrl]); }, []); ``` -------------------------------- ### Suggest URL to Launch (Android) Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/README.md The 'mayLaunchUrl' method on Android suggests a URL to the browser. Provide the most likely URL first, followed by less likely ones in decreasing priority. ```javascript await InAppBrowser.mayLaunchUrl('https://example.com/next', ['https://example.com/later']); ``` -------------------------------- ### Summary of Imports Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/api-reference/module-exports.md This snippet summarizes the recommended imports for using the library, including the main InAppBrowser object and its type definitions. ```javascript import { InAppBrowser } from 'react-native-inappbrowser-reborn'; import type { InAppBrowserOptions, BrowserResult } from 'react-native-inappbrowser-reborn'; ``` -------------------------------- ### iOS In-App Browser Architecture Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/README.md Illustrates the flow for opening URLs and initiating OAuth authentication on iOS using SFSafariViewController and ASWebAuthenticationSession respectively. ```text App ├─ InAppBrowser.open() │ └─ SFSafariViewController (iOS 9+) │ └─ Isolated Safari view │ └─ InAppBrowser.openAuth() └─ ASWebAuthenticationSession (iOS 11+) ├─ User consent dialog └─ OAuth redirect → back to app ``` -------------------------------- ### TypeScript Usage with Type Import Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/api-reference/module-exports.md Example of importing InAppBrowser as default and types separately using 'import type' in TypeScript. ```typescript import InAppBrowser from 'react-native-inappbrowser-reborn'; import type { InAppBrowserOptions, BrowserResult } from 'react-native-inappbrowser-reborn'; const openUrl = async (url: string, options?: InAppBrowserOptions): Promise => { return await InAppBrowser.open(url, options); }; ``` -------------------------------- ### Initialize Browser Service in MainActivity (Android) Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/configuration.md Add `RNInAppBrowserModule.onStart()` to your Android `MainActivity` to enable browser warmup and pre-loading optimizations. This initializes a background service connection to the Custom Tabs provider, allowing the browser to warm up in the background and significantly improving launch time on subsequent `open()` calls. ```java import com.proyecto26.inappbrowser.RNInAppBrowserModule; import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity { @Override protected void onStart() { super.onStart(); RNInAppBrowserModule.onStart(this); } } ``` -------------------------------- ### Android Activity Not Available Error Example Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/platform-specific.md This snippet demonstrates an error that can occur on Android if the necessary activity to handle the intent cannot be resolved. ```javascript // Activity not available Error: Can't resolve activity ``` -------------------------------- ### iOS Browser Permission Error Example Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/platform-specific.md This snippet illustrates an error that occurs on iOS if the user denies or cancels browser access. ```javascript // Browser permission error Error: User cancelled or denied access ``` -------------------------------- ### open() Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/api-reference/InAppBrowser.md Opens a URL in the system's native in-app browser. This method supports custom configurations for both iOS and Android platforms. ```APIDOC ## open() ### Description Opens a URL in the system's native in-app browser. On iOS, it uses `SFSafariViewController`; on Android, it uses Chrome Custom Tabs. ### Method `open(url: string, options?: InAppBrowserOptions): Promise` ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * **url** (string) - Required - The URL to open in the browser. * **options** (InAppBrowserOptions) - Optional - Configuration options for the browser. Can include both iOS and Android specific options. Defaults to `{ animated: true, modalEnabled: true, dismissButtonStyle: 'close', readerMode: false, enableBarCollapsing: false }`. ### Request Example ```javascript import { InAppBrowser } from 'react-native-inappbrowser-reborn'; import { Alert } from 'react-native'; const openURL = async () => { try { if (await InAppBrowser.isAvailable()) { const result = await InAppBrowser.open('https://github.com/proyecto26', { // iOS options dismissButtonStyle: 'cancel', preferredBarTintColor: '#453AA4', preferredControlTintColor: 'white', readerMode: false, animated: true, modalPresentationStyle: 'fullScreen', // Android options showTitle: true, toolbarColor: '#6200EE', enableUrlBarHiding: true }); Alert.alert('Browser Result', JSON.stringify(result)); } } catch (error) { Alert.alert('Error', error.message); } }; ``` ### Response #### Success Response Returns a `Promise` that resolves with: - `{ type: 'cancel' }` if the user manually closed the browser - `{ type: 'dismiss' }` if the browser was closed via the `close()` method #### Response Example ```json { "type": "cancel" } ``` ### Error Handling May reject with an error if the URL is invalid or the browser fails to open. The error message describes the failure reason. ``` -------------------------------- ### TypeScript Usage with Types Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/api-reference/module-exports.md Example of importing InAppBrowser along with specific types (InAppBrowserOptions, BrowserResult) in TypeScript for typed function usage. ```typescript import { InAppBrowser, InAppBrowserOptions, BrowserResult } from 'react-native-inappbrowser-reborn'; const openUrl = async (url: string, options: InAppBrowserOptions): Promise => { return await InAppBrowser.open(url, options); }; ``` -------------------------------- ### Initialize Background Service (Android) Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/README.md Call 'onStart' on Android to initialize a background service. This allows the application to communicate its intention to the browser for faster navigation. ```javascript await InAppBrowser.onStart(); ``` -------------------------------- ### InAppBrowser isAvailable() Return Values Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/quick-reference.md The `isAvailable()` method returns a boolean indicating if the InAppBrowser is ready to be used. On Android, this checks for Chrome installation. ```javascript true // Available on this device false // Not available (Android: Chrome not installed) ``` -------------------------------- ### Project Dependencies Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/configuration.md Lists the core dependencies required for the library: invariant for error checking and opencollective-postinstall for optional donations. ```json { "dependencies": { "invariant": "^2.2.4", "opencollective-postinstall": "^2.0.3" } } ``` -------------------------------- ### Android Invalid URL Scheme Error Example Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/platform-specific.md This snippet shows an error on Android when no activity is found to handle the specified URL scheme. ```javascript // Invalid URL scheme Error: No Activity found to handle intent ``` -------------------------------- ### Pre-render URLs with mayLaunchUrl (Android only) Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/quick-reference.md Suggests URLs to the browser for pre-rendering, potentially speeding up navigation. This is an Android-only feature. ```javascript InAppBrowser.mayLaunchUrl('https://example.com', [ 'https://example.com/page2', 'https://example.com/page3' ]); ``` -------------------------------- ### iOS URL Validation Error Example Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/platform-specific.md This snippet shows a typical error message encountered on iOS when an invalid URL scheme is used. ```javascript // URL validation error Error: The attempted URL has an invalid scheme ``` -------------------------------- ### Warmup and Pre-render Browser in JavaScript Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/configuration.md In your app's initialization code, call `InAppBrowser.warmup()` once to warm up the browser process and `InAppBrowser.mayLaunchUrl()` before users are likely to open URLs. List URLs in order of decreasing likelihood and do not update pre-rendered URLs on every component render. ```javascript import { InAppBrowser } from 'react-native-inappbrowser-reborn'; import { useEffect } from 'react'; const App = () => { useEffect(() => { // Warm up the browser process InAppBrowser.warmup().catch(error => { console.log('Browser warmup failed:', error); }); // Pre-render likely URLs InAppBrowser.mayLaunchUrl( 'https://example.com/likely-page', [ 'https://example.com/other-page-1', 'https://example.com/other-page-2' ] ); }, []); return null; }; export default App; ``` -------------------------------- ### Android Configuration for Legacy Support Library Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/configuration.md Configure android/build.gradle for legacy Android Support Library support, specifying build tools, SDK versions, and support library version. ```gradle buildscript { ext { buildToolsVersion = "28.0.3" minSdkVersion = 16 compileSdkVersion = 28 targetSdkVersion = 28 supportLibVersion = "28.0.0" } } ``` -------------------------------- ### Check if InAppBrowser is available Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/quick-reference.md Determines if the in-app browser feature is available on the current device. Returns true on iOS, and true on Android if Chrome is installed. ```javascript const available = await InAppBrowser.isAvailable(); // true on iOS, true on Android if Chrome installed ``` -------------------------------- ### mayLaunchUrl Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/quick-reference.md Pre-renders specified URLs in the background to speed up navigation when those URLs are eventually opened. This is an Android-only feature. ```APIDOC ## mayLaunchUrl(url, otherUrls) ### Description Pre-renders URLs (Android only). ### Method `mayLaunchUrl` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **url** (string) - The primary URL to pre-render. * **otherUrls** (array of strings) - An array of additional URLs to pre-render. ### Request Example ```javascript InAppBrowser.mayLaunchUrl('https://example.com', [ 'https://example.com/page2', 'https://example.com/page3' ]); ``` ### Response None. ``` -------------------------------- ### Android Configuration for AndroidX Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/configuration.md Configure android/build.gradle for AndroidX support, specifying build tools, SDK versions, and AndroidX library versions. ```gradle buildscript { ext { buildToolsVersion = "30.0.2" minSdkVersion = 21 compileSdkVersion = 30 targetSdkVersion = 30 ndkVersion = "21.4.7075529" // AndroidX versions androidXAnnotation = "1.2.0" androidXBrowser = "1.3.0" } } ``` -------------------------------- ### TypeScript Definitions Structure Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/api-reference/module-exports.md Example of how the module interface is declared in TypeScript's index.d.ts file. This defines the shape of the exported InAppBrowser class methods. ```typescript declare module "react-native-inappbrowser-reborn" { // Type definitions export interface RedirectEvent { } export interface BrowserResult { } export interface RedirectResult { } export type InAppBrowseriOSOptions = { } export type InAppBrowserAndroidOptions = { } export type InAppBrowserOptions = { } export type AuthSessionResult = { } // Class methods interface interface InAppBrowserClassMethods { open(url, options?): Promise close(): void // ... other methods } // Main export export const InAppBrowser: InAppBrowserClassMethods export default InAppBrowser } ``` -------------------------------- ### Android In-App Browser Architecture Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/README.md Details the Android in-app browser flow, including background initialization with warmup(), URL pre-rendering with mayLaunchUrl(), and the use of Chrome Custom Tabs for opening URLs and OAuth. ```text App ├─ warmup() │ └─ Initialize Custom Tabs service (background) │ ├─ mayLaunchUrl() │ └─ Pre-render/pre-load URLs │ ├─ InAppBrowser.open() │ └─ Chrome Custom Tab │ └─ Toolbar, navigation, web content │ └─ InAppBrowser.openAuth() ├─ Custom Tab with auth URL ├─ Redirect to app's URL scheme └─ Activity resume event └─ Linking API detects redirect ``` -------------------------------- ### warmup() Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/api-reference/InAppBrowser.md Warms up the browser process to make URL opening significantly faster. This is an optimization primarily for Android. ```APIDOC ## warmup() ### Description Warms up the browser process to make URL opening significantly faster. This is an optimization for Android. ### Method ```typescript warmup(): Promise ``` ### Parameters None ### Return Value Returns a `Promise`: - `true` on Android if warmup succeeded - `false` on iOS (not supported on iOS) or if warmup failed ### Example ```javascript import { InAppBrowser } from 'react-native-inappbrowser-reborn'; import { useEffect } from 'react'; const MyComponent = () => { useEffect(() => { // Warm up the browser on app start InAppBrowser.warmup().catch(error => { console.log('Warmup failed:', error); }); }, []); return null; }; ``` ### Notes - **Android only** — iOS implementation returns a resolved promise with `false` - Can be called multiple times safely - Should be called early in your app's lifecycle (e.g., in `useEffect` on app start) - See `onStart()` method below for additional warmup integration in Android `MainActivity` ### Platform Support - Android: Initializes the Custom Tabs service connection - iOS: No-op, returns `false` ``` -------------------------------- ### Check In-App Browser Availability Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/api-reference/InAppBrowser.md Detects whether the device supports this plugin. On Android, it checks if Chrome or another compatible Custom Tabs provider is installed. On iOS, it always returns true. ```typescript isAvailable(): Promise ``` ```javascript import { InAppBrowser, Linking } from 'react-native-inappbrowser-reborn'; const openLinkSafely = async (url) => { try { if (await InAppBrowser.isAvailable()) { await InAppBrowser.open(url); } else { // Fallback to system browser Linking.openURL(url); } } catch (error) { Linking.openURL(url); } }; ``` -------------------------------- ### mayLaunchUrl() Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/api-reference/InAppBrowser.md Tells the browser of likely future navigations to URLs. The browser can use this information to pre-render content, speeding up subsequent open() calls. ```APIDOC ## mayLaunchUrl() ### Description Tells the browser of likely future navigations to URLs. The browser can use this information to pre-render content, speeding up subsequent `open()` calls. ### Method ```typescript mayLaunchUrl( mostLikelyUrl: string, otherUrls: Array ): void ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None #### Parameters - **mostLikelyUrl** (string) - Required - The URL the user is most likely to navigate to - **otherUrls** (Array) - Optional - Array of other likely URLs, sorted by decreasing likelihood/priority ### Return Value Returns `void`. This method is synchronous. ### Example ```javascript import { InAppBrowser } from 'react-native-inappbrowser-reborn'; import { useEffect } from 'react'; const ArticleList = () => { useEffect(() => { // Pre-render the first article InAppBrowser.mayLaunchUrl( 'https://blog.example.com/article-1', [ 'https://blog.example.com/article-2', 'https://blog.example.com/article-3' ] ); }, []); return null; }; ``` ### Notes - **Android only** — iOS implementation is a no-op - All previous calls are deprioritized when a new call is made - The browser may ignore additional URLs if it chooses - Use this in `useEffect` hooks before users are likely to tap links, not on every render ### Platform Support - Android: Uses Custom Tabs pre-rendering and pre-loading hints - iOS: No-op ``` -------------------------------- ### Android Manual Registration (settings.gradle) Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/configuration.md Include the react-native-inappbrowser-reborn module in your project's settings.gradle file for manual registration. ```gradle include ':react-native-inappbrowser-reborn' project(':react-native-inappbrowser-reborn').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-inappbrowser-reborn/android') ``` -------------------------------- ### open Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/quick-reference.md Opens a URL in the in-app browser. It can be configured with various options specific to iOS and Android platforms. The method returns a promise that resolves with the browser interaction type. ```APIDOC ## open(url, options?) ### Description Opens a URL in the in-app browser. ### Method `open` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **url** (string) - The URL to open. * **options** (object) - Optional configuration object for the browser. ### Request Example ```javascript const result = await InAppBrowser.open('https://example.com', { dismissButtonStyle: 'cancel', // iOS preferredBarTintColor: '#453AA4', // iOS toolbarColor: '#6200EE', // Android showTitle: true // Android }); ``` ### Response #### Success Response * **result** (object) - An object indicating the interaction type, e.g., `{ type: 'cancel' | 'dismiss' }`. ``` -------------------------------- ### Manage Status Bar Style When Opening Browser Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/configuration.md When opening the browser, you can temporarily change the StatusBar style to match the browser's appearance and restore it when the browser closes. This example uses `StatusBar.pushStackEntry` for React Native >= 0.59. ```javascript import { StatusBar } from 'react-native'; import { InAppBrowser } from 'react-native-inappbrowser-reborn'; const openBrowserWithStatusBar = async (url) => { try { const oldStyle = StatusBar.pushStackEntry({ barStyle: 'dark-content', animated: false }); await InAppBrowser.open(url); StatusBar.popStackEntry(oldStyle); } catch (error) { console.error(error); } }; ``` -------------------------------- ### Warm up Browser (Android) Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/README.md Use the 'warmup' method on Android to pre-load the browser process, potentially speeding up subsequent navigations. ```javascript await InAppBrowser.warmup('https://example.com'); ``` -------------------------------- ### Open URL with Fallback to System Browser Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/README.md Check if the in-app browser is available and use it. If not, fall back to opening the URL in the system's default browser. ```javascript if (await InAppBrowser.isAvailable()) { await InAppBrowser.open(url); } else { Linking.openURL(url); } ``` -------------------------------- ### Error Handling with InAppBrowser.open Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/api-reference/InAppBrowser.md Demonstrates how to use a try-catch block to handle potential errors when opening the InAppBrowser. This is crucial for managing invalid URLs, network failures, or unexpected browser terminations. ```javascript try { const result = await InAppBrowser.open(url, options); console.log('Browser closed:', result.type); } catch (error) { console.error('Failed to open browser:', error.message); } ``` -------------------------------- ### Pre-render URLs with mayLaunchUrl Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/README.md Optimizes performance by pre-rendering URLs that the user is likely to open. This function should not be called on every component render; use `useEffect` to call it once. ```javascript // Do not call this every time the component render useEffect(() => { InAppBrowser.mayLaunchUrl("Url user has high chance to open", ["Other urls that user might open ordered by priority"]); }, []); ``` -------------------------------- ### iOS Session Management Diagram Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/platform-specific.md Illustrates how InAppBrowser.open() and InAppBrowser.openAuth() interact with SFSafariViewController and ASWebAuthenticationSession on iOS, emphasizing isolated sessions and user consent for authentication. ```text ┌─────────────────────┐ │ Your App │ ├─────────────────────┤ │ InAppBrowser.open()│ ───┐ │ │ │ │ InAppBrowser.open │ │ Isolated Session │ Auth() │ │ (no cookie sharing) │ │ │ └─────────────────────┘ │ │ ┌─────────────────┴──────────┐ │ │ ┌────▼─────────┐ ┌────────▼──────┐ │ Safari View │ │ Auth Session │ │ Controller │ │ (iOS 11+) │ └──────────────┘ └───────────────┘ │ │ │ Modal Presentation │ User Consent │ │ ┌────▼─────────────────────────▼──────┐ │ Isolated Browser Instance │ │ (no Cookie Access) │ └──────────────────────────────────────┘ ``` -------------------------------- ### warmup Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/quick-reference.md Warms up the browser process, which can improve the performance of subsequent browser launches. This is an Android-only optimization. ```APIDOC ## warmup() ### Description Warms up browser (Android only). ### Method `warmup` ### Parameters None ### Request Example ```javascript await InAppBrowser.warmup(); ``` ### Response None. ``` -------------------------------- ### Android Manual Registration (build.gradle) Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/configuration.md Add the react-native-inappbrowser-reborn dependency in your app's build.gradle file for manual registration. ```gradle dependencies { implementation project(':react-native-inappbrowser-reborn') } ``` -------------------------------- ### Warmup InAppBrowser Client on Android Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/README.md Optimizes InAppBrowser launch speed on Android by warming up the client. This should be called in the `onStart` method of your `MainActivity`. ```java import com.proyecto26.inappbrowser.RNInAppBrowserModule; public class MainActivity extends ReactActivity { @Override protected void onStart() { super.onStart(); RNInAppBrowserModule.onStart(this); } } ``` -------------------------------- ### Activity Resume Detection Timeline Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/platform-specific.md Outlines the sequence of events from initiating an authentication flow to the app resuming and detecting the redirect URL via Linking.getInitialURL(). This clarifies how backgrounding and foregrounding affect the process. ```text Timeline: 1. App in foreground │ ├─ openAuth() called │ │ │ └─ Browser opens in separate task │ 2. App enters background │ ├─ Browser in foreground (different task) │ ├─ User completes auth │ ├─ Redirect to app's URL scheme │ 3. App brought to foreground (another task) │ ├─ ActivityResumedEvent fires │ ├─ Linking.getInitialURL() gets the redirect URL │ └─ Promise resolves with success result ``` -------------------------------- ### Browser Warmup and URL Pre-rendering with useEffect Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/quick-reference.md Utilizes the `useEffect` hook to perform browser warmup and pre-render URLs when the component mounts, optimizing initial load times. ```javascript useEffect(() => { InAppBrowser.warmup(); InAppBrowser.mayLaunchUrl(url, [url2, url3]); }, []); ``` -------------------------------- ### Custom Tabs Service Connection Diagram Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/platform-specific.md Illustrates the interaction between the app, the Custom Tabs Service, and the Custom Tab View. This visualizes how the app binds to the service to manage the browser instance. ```text ┌─────────────────────┐ │ Your App │ ├─────────────────────┤ │ MainActivity.onStart│ ───┐ │ RNInAppBrowserModule│ │ │ .onStart(this) │ │ Binds service │ │ │ │ InAppBrowser.warmup│ │ │ InAppBrowser.open()│ │ └─────────────────────┘ │ │ ┌─────────────────┘ │ ┌────▼──────────────────────┐ │ Custom Tabs Service │ │ (Chrome Background Service) └────┬──────────────────────┘ │ │ Connected │ ┌────▼──────────────────────┐ │ Custom Tab View │ │ (Chrome Browser Instance) │ │ │ │ ┌───────────────────────┐ │ │ │ Address Bar │ │ │ │ Navigation Buttons │ │ │ │ Web Content │ │ │ │ Custom Menu │ │ │ └───────────────────────┘ │ └───────────────────────────┘ ``` -------------------------------- ### CommonJS (Node.js) Imports Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/api-reference/module-exports.md Shows how to import InAppBrowser using CommonJS syntax, including both named and default import equivalents. ```javascript const { InAppBrowser } = require('react-native-inappbrowser-reborn'); // Or const InAppBrowser = require('react-native-inappbrowser-reborn').default; ``` -------------------------------- ### Android Manual Registration (MainApplication.java) Source: https://github.com/proyecto26/react-native-inappbrowser/blob/develop/_autodocs/configuration.md Manually register the RNInAppBrowserPackage in MainApplication.java for React Native versions below 0.60. ```java import com.proyecto26.inappbrowser.RNInAppBrowserPackage; public class MainApplication extends Application implements ReactApplication { private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { @Override public List getPackages() { return Arrays.asList( new MainReactPackage(), new RNInAppBrowserPackage() ); } }; } ```