Skip to content

Commit 5b8de24

Browse files
committed
feat: implement InAppBrowser class with core functionalities
1 parent 1ef3a36 commit 5b8de24

3 files changed

Lines changed: 74 additions & 70 deletions

File tree

src/InAppBrowserCore.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { NitroModules } from 'react-native-nitro-modules';
2+
import type {
3+
InAppBrowserNitro,
4+
InAppBrowserOptions,
5+
InAppBrowserResult,
6+
InAppBrowserAuthResult,
7+
} from './InAppBrowserNitro.nitro';
8+
9+
const InAppBrowserNitroHybridObject =
10+
NitroModules.createHybridObject<InAppBrowserNitro>('InAppBrowserNitro');
11+
12+
/**
13+
* InAppBrowser - A fast, modern in-app browser for React Native using Nitro modules
14+
*
15+
* Provides access to the system's web browser (Safari on iOS, Chrome Custom Tabs on Android)
16+
* with support for authentication flows, deep linking, and performance optimizations.
17+
*/
18+
export class InAppBrowser {
19+
/**
20+
* Check if the device supports InAppBrowser
21+
* @returns Promise<boolean> - true if supported, false otherwise
22+
*/
23+
static async isAvailable(): Promise<boolean> {
24+
return InAppBrowserNitroHybridObject.isAvailable();
25+
}
26+
27+
/**
28+
* Open a URL in the in-app browser
29+
* @param url - The URL to open
30+
* @param options - Browser configuration options
31+
* @returns Promise<InAppBrowserResult> - Result of the browser operation
32+
*/
33+
static async open(
34+
url: string,
35+
options?: InAppBrowserOptions
36+
): Promise<InAppBrowserResult> {
37+
return InAppBrowserNitroHybridObject.open(url, options);
38+
}
39+
40+
/**
41+
* Open a URL for authentication flow (OAuth, etc.)
42+
* @param url - The URL to open for authentication
43+
* @param redirectUrl - The redirect URL scheme to listen for
44+
* @param options - Browser configuration options
45+
* @returns Promise<InAppBrowserAuthResult> - Result of the authentication
46+
*/
47+
static async openAuth(
48+
url: string,
49+
redirectUrl: string,
50+
options?: InAppBrowserOptions
51+
): Promise<InAppBrowserAuthResult> {
52+
return InAppBrowserNitroHybridObject.openAuth(url, redirectUrl, options);
53+
}
54+
55+
/**
56+
* Close the currently opened in-app browser
57+
* @returns Promise<void>
58+
*/
59+
static async close(): Promise<void> {
60+
return InAppBrowserNitroHybridObject.close();
61+
}
62+
63+
/**
64+
* Close the currently opened authentication session
65+
* @returns Promise<void>
66+
*/
67+
static async closeAuth(): Promise<void> {
68+
return InAppBrowserNitroHybridObject.closeAuth();
69+
}
70+
}

src/hooks/useInAppBrowser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useCallback, useState } from 'react';
2-
import { InAppBrowser } from '../index';
2+
import { InAppBrowser } from '../InAppBrowserCore';
33
import type {
44
InAppBrowserOptions,
55
InAppBrowserResult,

src/index.tsx

Lines changed: 3 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,7 @@
1-
import { NitroModules } from 'react-native-nitro-modules';
2-
import type {
3-
InAppBrowserNitro,
4-
InAppBrowserOptions,
5-
InAppBrowserResult,
6-
InAppBrowserAuthResult,
7-
} from './InAppBrowserNitro.nitro';
8-
9-
const InAppBrowserNitroHybridObject =
10-
NitroModules.createHybridObject<InAppBrowserNitro>('InAppBrowserNitro');
11-
12-
/**
13-
* InAppBrowser - A fast, modern in-app browser for React Native using Nitro modules
14-
*
15-
* Provides access to the system's web browser (Safari on iOS, Chrome Custom Tabs on Android)
16-
* with support for authentication flows, deep linking, and performance optimizations.
17-
*/
18-
export class InAppBrowser {
19-
/**
20-
* Check if the device supports InAppBrowser
21-
* @returns Promise<boolean> - true if supported, false otherwise
22-
*/
23-
static async isAvailable(): Promise<boolean> {
24-
return InAppBrowserNitroHybridObject.isAvailable();
25-
}
26-
27-
/**
28-
* Open a URL in the in-app browser
29-
* @param url - The URL to open
30-
* @param options - Browser configuration options
31-
* @returns Promise<InAppBrowserResult> - Result of the browser operation
32-
*/
33-
static async open(
34-
url: string,
35-
options?: InAppBrowserOptions
36-
): Promise<InAppBrowserResult> {
37-
return InAppBrowserNitroHybridObject.open(url, options);
38-
}
39-
40-
/**
41-
* Open a URL for authentication flow (OAuth, etc.)
42-
* @param url - The URL to open for authentication
43-
* @param redirectUrl - The redirect URL scheme to listen for
44-
* @param options - Browser configuration options
45-
* @returns Promise<InAppBrowserAuthResult> - Result of the authentication
46-
*/
47-
static async openAuth(
48-
url: string,
49-
redirectUrl: string,
50-
options?: InAppBrowserOptions
51-
): Promise<InAppBrowserAuthResult> {
52-
return InAppBrowserNitroHybridObject.openAuth(url, redirectUrl, options);
53-
}
54-
55-
/**
56-
* Close the currently opened in-app browser
57-
* @returns Promise<void>
58-
*/
59-
static async close(): Promise<void> {
60-
return InAppBrowserNitroHybridObject.close();
61-
}
1+
import { InAppBrowser } from './InAppBrowserCore';
622

63-
/**
64-
* Close the currently opened authentication session
65-
* @returns Promise<void>
66-
*/
67-
static async closeAuth(): Promise<void> {
68-
return InAppBrowserNitroHybridObject.closeAuth();
69-
}
70-
}
3+
// Export the main class
4+
export { InAppBrowser } from './InAppBrowserCore';
715

726
// Export types for external use
737
export type {

0 commit comments

Comments
 (0)